home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / comm / mail / smail / src / rcs / sysdep.c,v < prev    next >
Text File  |  1993-12-21  |  38KB  |  2,153 lines

  1. head    1.19;
  2. access;
  3. symbols
  4.     C_1:1.19;
  5. locks; strict;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.19
  10. date    93.11.14.20.58.52;    author Aussem;    state Exp;
  11. branches;
  12. next    1.18;
  13.  
  14. 1.18
  15. date    93.11.13.21.16.23;    author Aussem;    state Exp;
  16. branches;
  17. next    1.17;
  18.  
  19. 1.17
  20. date    93.11.12.23.05.06;    author Aussem;    state Exp;
  21. branches;
  22. next    1.16;
  23.  
  24. 1.16
  25. date    93.11.09.22.42.58;    author Aussem;    state Exp;
  26. branches;
  27. next    1.15;
  28.  
  29. 1.15
  30. date    93.11.04.22.46.49;    author Aussem;    state Exp;
  31. branches;
  32. next    1.14;
  33.  
  34. 1.14
  35. date    93.11.02.22.43.42;    author Aussem;    state Exp;
  36. branches;
  37. next    1.13;
  38.  
  39. 1.13
  40. date    93.11.02.19.56.34;    author Aussem;    state Exp;
  41. branches;
  42. next    1.12;
  43.  
  44. 1.12
  45. date    93.10.31.21.11.58;    author Aussem;    state Exp;
  46. branches;
  47. next    1.11;
  48.  
  49. 1.11
  50. date    93.10.31.17.50.59;    author Aussem;    state Exp;
  51. branches;
  52. next    1.10;
  53.  
  54. 1.10
  55. date    93.10.24.15.00.22;    author Aussem;    state Exp;
  56. branches;
  57. next    1.9;
  58.  
  59. 1.9
  60. date    93.09.18.20.23.05;    author Aussem;    state Exp;
  61. branches;
  62. next    1.8;
  63.  
  64. 1.8
  65. date    93.09.18.16.47.47;    author Aussem;    state Exp;
  66. branches;
  67. next    1.7;
  68.  
  69. 1.7
  70. date    93.09.16.22.36.48;    author Aussem;    state Exp;
  71. branches;
  72. next    1.6;
  73.  
  74. 1.6
  75. date    93.09.15.22.22.27;    author Aussem;    state Exp;
  76. branches;
  77. next    1.5;
  78.  
  79. 1.5
  80. date    93.09.15.20.17.42;    author Aussem;    state Exp;
  81. branches;
  82. next    1.4;
  83.  
  84. 1.4
  85. date    93.09.11.16.27.44;    author Aussem;    state Exp;
  86. branches;
  87. next    1.3;
  88.  
  89. 1.3
  90. date    93.09.11.01.41.16;    author Aussem;    state Exp;
  91. branches;
  92. next    1.2;
  93.  
  94. 1.2
  95. date    93.09.10.01.53.25;    author Aussem;    state Exp;
  96. branches;
  97. next    1.1;
  98.  
  99. 1.1
  100. date    93.09.08.16.27.13;    author Aussem;    state Exp;
  101. branches;
  102. next    ;
  103.  
  104.  
  105. desc
  106. @system depended routines for AmigaOS
  107. @
  108.  
  109.  
  110. 1.19
  111. log
  112. @commtents insert
  113. @
  114. text
  115. @/*
  116.  * sysdep.c
  117.  *
  118.  * System depend routines
  119.  *
  120.  * This program is free software; you can redistribute it and/or
  121.  * modify it under the terms of the GNU General Public License as
  122.  * published by the Free Software Foundation; either version 2 of
  123.  * the License, or (at your option) any later version.
  124.  *
  125.  * This program is distributed in the hope that it will be useful,
  126.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  127.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  128.  * General Public License for more details.
  129.  *
  130.  * You should have received a copy of the GNU General Public License
  131.  * along with this program; if not, write to the Free Software
  132.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  133.  *
  134.  * $Log: sysdep.c,v $
  135.  * Revision 1.18  1993/11/13  21:16:23  Aussem
  136.  * rename getversion() get_programtype() and store the program
  137.  * type in the global var programtype_string
  138.  *
  139.  * Revision 1.17  1993/11/12  23:05:06  Aussem
  140.  * checkuid() now uses the checkuser file in MUFS version too
  141.  * checkuid does not care about case of the users
  142.  * in checkuser file
  143.  *
  144.  * Revision 1.16  1993/11/09  22:42:58  Aussem
  145.  * Debug msgs unified
  146.  * user access check implemented
  147.  * MUFS routines optimizied
  148.  *
  149.  * Revision 1.15  1993/11/04  22:46:49  Aussem
  150.  * grep_*() deletes now tabs too
  151.  *
  152.  * Revision 1.14  1993/11/02  22:43:42  Aussem
  153.  * extended MUFS routines
  154.  *
  155.  * Revision 1.13  1993/11/02  19:56:34  Aussem
  156.  * MUFS routines added
  157.  *
  158.  * Revision 1.12  1993/10/31  21:11:58  Aussem
  159.  * grep_toline() eliminate now really all not needed spaces
  160.  *
  161.  * Revision 1.11  1993/10/31  17:50:59  Aussem
  162.  * if stdin is empty (e.g nil:) smail does not wait anymore
  163.  *
  164.  * Revision 1.10  1993/10/24  15:00:22  Aussem
  165.  * AXSh Version is now included in this file (no sysdep_axsh.c anymore)
  166.  *
  167.  * Revision 1.9  1993/09/18  20:23:05  Aussem
  168.  * the cc line can now be parsed from cmdline and from file
  169.  *
  170.  * Revision 1.8  1993/09/18  16:47:47  Aussem
  171.  * insert GNU license text in the header
  172.  *
  173.  * Revision 1.7  1993/09/16  22:36:48  Aussem
  174.  * realname elmination in grep_toline() works better now
  175.  *
  176.  * Revision 1.6  1993/09/15  22:22:27  Aussem
  177.  * grep_toline() <addr> are now recognized
  178.  *
  179.  * Revision 1.5  1993/09/15  20:17:42  Aussem
  180.  * gethostname and getdomain first look in uulib:config and then
  181.  * in the enviroment variables
  182.  *
  183.  * Revision 1.4  1993/09/11  16:27:44  Aussem
  184.  * getrealname() now works correctly again
  185.  *
  186.  * Revision 1.3  1993/09/11  01:41:16  Aussem
  187.  * \t will now be noticed as continuation of the To: line
  188.  *
  189.  * Revision 1.2  1993/09/10  01:53:25  Aussem
  190.  * new support for grepping the To: line from mailbody with grep_toline()
  191.  *
  192.  * Revision 1.1  1993/09/08  16:27:13  Aussem
  193.  * Initial revision
  194.  *
  195.  *
  196.  */
  197.  
  198.  
  199. static char     *rcsid="$Id: sysdep.c,v 1.18 1993/11/13 21:16:23 Aussem Exp Aussem $";
  200.  
  201.  
  202. #include <time.h>
  203. #include <stdio.h>
  204. #include <stdlib.h>
  205. #include <stdarg.h>
  206. #include <dos/dostags.h>
  207. #include <proto/dos.h>
  208. #include <pragmas/dos_pragmas.h>
  209. #include <proto/exec.h>
  210. #include <pragmas/exec_pragmas.h>
  211. #include "defs.h"
  212.  
  213.  
  214. #define CTLZ    ('z'&0x1F)
  215.  
  216. extern struct DosLibrary *DOSBase;
  217. extern char passwdfile[]; /* name of the passwd file           */
  218. extern char logfile[];    /* - " -       Dillon styled logfile */
  219. extern int checkuser;     /* user checking on/off              */
  220. extern int debug;         /* debug                             */
  221.  
  222. char checkuserfile[SMLBUF]="uulib:mail/checkuser"; /* name of the checkuser file */
  223. char prgtype_string[]="UNKNOWN"; /* type of program (getty/axsh/mufs) */
  224.  
  225. /* static vars */
  226. static char *ConfBuf = NULL;
  227. static long passwd_pos = 0;
  228.  
  229. /* static prototypes */
  230. static void uncomment(char *);
  231. static char *Breakout(char **pptr);
  232.  
  233. /*
  234.  * Breakout(): extract a field from a passwd entry
  235.  *
  236.  * pptr - pointer to a char array
  237.  *
  238.  * Return:
  239.  * pointer to the passwd field
  240.  *
  241.  */
  242. static
  243. char *
  244. Breakout(pptr)
  245. char **pptr;
  246. {
  247.     char *base;
  248.     char *ptr;
  249.  
  250.     base = *pptr;
  251.     if (base == NULL)
  252.     return("");
  253.     for (ptr = base; *ptr && *ptr != '\n' && *ptr != ','; ++ptr);
  254.     if (*ptr == ',') {
  255.     *pptr = ptr + 1;
  256.     *ptr = 0;
  257.     } else {
  258.     *pptr = NULL;
  259.     *ptr = 0;
  260.     }
  261.     return(base);
  262. }
  263.  
  264. /*
  265.  * kill_external(): global atexit function
  266.  *
  267.  * This function closes the MUFS library and kill all
  268.  * memory allocated for user and group info. For all
  269.  * other program types this function do nothing.
  270.  * This function is add to the atexit function in main.c
  271.  *
  272.  */
  273. void kill_external(void)
  274. {
  275. #ifdef MUFS
  276. void kill_mufs(void);
  277.  
  278. kill_mufs();
  279. #endif
  280. }
  281.  
  282. #ifdef AXSH
  283. /*
  284.  *  passwd routines for the AXSh passwd
  285.  */
  286.  
  287. /* includes for AXSh */
  288. #include "axsh/iomodes.h"
  289. #include "axsh/misc.h"
  290. #include "axsh/users.h"
  291.  
  292. /* static vars for AXSh */
  293. static struct User usr;
  294.  
  295. /*
  296.  *  axsh_getuid(): get the group id from the uid
  297.  *
  298.  * params: uid - userid of the user
  299.  * return: groupid
  300.  *
  301.  */
  302. static UWORD axsh_getgid(UWORD uid)
  303. {
  304. if(uid & UID_DAEMON) return(UID_DAEMON);
  305. if(uid & UID_SYSTEM) return(UID_SYSTEM);
  306. if(uid & UID_WIZARD) return(UID_WIZARD);
  307. if(uid & UID_SUPERUSER) return(UID_SUPERUSER);
  308. if(uid & UID_ASSISTANT) return(UID_ASSISTANT);
  309. if(uid & UID_PRIVILEGED) return(UID_PRIVILEGED);
  310. if(uid & UID_TRUSTED) return(UID_TRUSTED);
  311. if(uid & UID_FRIEND) return(UID_FRIEND);
  312. if(uid & UID_QUALIFIED) return(UID_QUALIFIED);
  313. if(uid & UID_NORMAL) return(UID_NORMAL);
  314. if(uid & UID_GUEST) return(UID_GUEST);
  315. return(UID_VISITOR);
  316. }
  317.  
  318. /*
  319.  * getpwent(): get the next passwd entry from passwd
  320.  *
  321.  * return: NULL for no next entry or error
  322.  *         or a filled passwd structure
  323.  *
  324.  */
  325. struct passwd * getpwent(void)
  326. {
  327.     static char User[32];
  328.     static char Passwd[32];
  329.     static char Dir[128];
  330.     static char Shell[256];
  331.     static char Gecos[256];
  332.     static char Comment[256];
  333.     static struct passwd Pas = { User, Passwd, 0, 0, 0, Comment, Gecos,  Dir, Shell };
  334.  
  335.     if(read_userdata("AXsh:etc/passwd",&usr,passwd_pos++)==-1)
  336.         return(NULL);
  337.  
  338.     strcpy(Pas.pw_name, usr.Loginname);
  339.     strcpy(Pas.pw_passwd, usr.Password);
  340.     Pas.pw_uid = usr.UID;
  341.     Pas.pw_gid = axsh_getgid(Pas.pw_uid);
  342.     strcpy(Pas.pw_gecos,usr.Fullname);     /*  finger info */
  343.     strcpy(Pas.pw_dir,usr.Home);
  344.  
  345.     return(&Pas);
  346. }
  347.  
  348. /*
  349.  * getpwname(): get the passwd entry of a special user from passwd
  350.  *
  351.  * params:  name of the user
  352.  * return: NULL for no next entry or error
  353.  *         or a filled passwd structure
  354.  *
  355.  */
  356. struct passwd *
  357. getpwnam(name)
  358. const char *name;
  359. {
  360.     static char User[32];
  361.     static char Passwd[32];
  362.     static char Dir[128];
  363.     static char Shell[256];
  364.     static char Gecos[256];
  365.     static char Comment[256];
  366.     static struct passwd Pas = { User, Passwd, 0, 0, 0, Comment, Gecos,  Dir, Shell };
  367.  
  368.    if (search_userdata ("AXsh:etc/passwd", &usr, 0,(char *) name) == -1)
  369.         return(NULL);
  370.  
  371.     strcpy(Pas.pw_name, usr.Loginname);
  372.     strcpy(Pas.pw_passwd, usr.Password);
  373.     Pas.pw_uid = usr.UID;
  374.     Pas.pw_gid = axsh_getgid(Pas.pw_uid);
  375.     strcpy(Pas.pw_gecos,usr.Fullname);     /*  finger info */
  376.     strcpy(Pas.pw_dir,usr.Home);
  377.  
  378.     return(&Pas);
  379. }
  380. #endif /* AXSH */
  381.  
  382. #ifdef MUFS
  383. /*
  384.  *  passwd routines for the MUFS passwd
  385.  */
  386.  
  387. /* include files for MUFS */
  388. #include <proto/multiuser.h>
  389. #include <pragmas/multiuser_pragmas.h>
  390. #include <libraries/multiuser.h>
  391.  
  392. /* vars for MUFS */
  393. struct muBase  *muBase=NULL;
  394. struct muUserInfo  *ui=NULL;
  395. struct muGroupInfo *gi=NULL;
  396.  
  397. /* protos for MUFS */
  398. int setup_mufs(void);
  399. void kill_mufs(void);
  400.  
  401. /*
  402.  * getpwname(): get the passwd entry of a special user from passwd
  403.  *
  404.  * params:  name of the user
  405.  * return: NULL for no next entry or error
  406.  *         or a filled passwd structure
  407.  *
  408.  */
  409. struct passwd *
  410. getpwnam(const char *name)
  411. {
  412. static char User[muUSERIDSIZE];
  413. static char Passwd[32];
  414. static char Dir[muHOMEDIRSIZE];
  415. static char Shell[256];
  416. static char Gecos[muUSERNAMESIZE];
  417. static char Comment[256];
  418. static struct passwd Pas = { User, Passwd, 0, 0, 0, Comment, Gecos,  Dir, Shell };
  419.  
  420. if(!setup_mufs())
  421.     return(NULL);
  422.  
  423. strcpy(ui->UserID,name);
  424. if(muGetUserInfo(ui,muKeyType_UserID)==NULL)
  425.     {
  426.     DEBUG("getpwnam: unable to find user '%s' in MUFS passwd\n",name);
  427.     return(NULL);
  428.     }
  429.  
  430.     strcpy(Pas.pw_name, ui->UserID);
  431.     strcpy(Pas.pw_passwd, "unknown");
  432.     Pas.pw_uid = ui->uid;
  433.     Pas.pw_gid = ui->gid;
  434.     strcpy(Pas.pw_gecos,ui->UserName);     /*  finger info */
  435.     strcpy(Pas.pw_dir,ui->HomeDir);
  436.    return(&Pas);
  437. }
  438.  
  439. /*
  440.  * getpwuid(): get the passwd entry of a special user from passwd
  441.  *
  442.  * params: userid of the user
  443.  * return: NULL for no next entry or error
  444.  *         or a filled passwd structure
  445.  *
  446.  */
  447. struct passwd *
  448. getpwuid(int uid)
  449. {
  450. static char User[muUSERIDSIZE];
  451. static char Passwd[32];
  452. static char Dir[muHOMEDIRSIZE];
  453. static char Shell[256];
  454. static char Gecos[muUSERNAMESIZE];
  455. static char Comment[256];
  456. static struct passwd Pas = { User, Passwd, 0, 0, 0, Comment, Gecos,  Dir, Shell };
  457.  
  458. if(!setup_mufs())
  459.     return(NULL);
  460.  
  461. ui->uid=uid;
  462. if(muGetUserInfo(ui,muKeyType_uid)==NULL)
  463.     {
  464.     DEBUG("getpwnam: unable to find UID '%d' in MUFS passwd\n",uid);
  465.     return(NULL);
  466.     }
  467.  
  468.     strcpy(Pas.pw_name, ui->UserID);
  469.     strcpy(Pas.pw_passwd, "unknown");
  470.     Pas.pw_uid = ui->uid;
  471.     Pas.pw_gid = ui->gid;
  472.     strcpy(Pas.pw_gecos,ui->UserName);     /*  finger info */
  473.     strcpy(Pas.pw_dir,ui->HomeDir);
  474.    return(&Pas);
  475. }
  476.  
  477. /*
  478.  * getpwent(): get the next passwd entry from passwd
  479.  *
  480.  * return: NULL for no next entry or error
  481.  *         or a filled passwd structure
  482.  *
  483.  */
  484. struct passwd * getpwent(void)
  485. {
  486. static char User[muUSERIDSIZE];
  487. static char Passwd[32];
  488. static char Dir[muHOMEDIRSIZE];
  489. static char Shell[256];
  490. static char Gecos[muUSERNAMESIZE];
  491. static char Comment[256];
  492. static struct passwd Pas = { User, Passwd, 0, 0, 0, Comment, Gecos,  Dir, Shell };
  493.  
  494. if(!setup_mufs())
  495.     return(NULL);
  496.  
  497. if(muGetUserInfo(ui,passwd_pos++?muKeyType_Next:muKeyType_First)==NULL)
  498.     {
  499.    /* all read */
  500.     return(NULL);
  501.     }
  502.  
  503.     strcpy(Pas.pw_name, ui->UserID);
  504.     strcpy(Pas.pw_passwd, "unknown");
  505.     Pas.pw_uid = ui->uid;
  506.     Pas.pw_gid = ui->gid;
  507.     strcpy(Pas.pw_gecos,ui->UserName);     /*  finger info */
  508.     strcpy(Pas.pw_dir,ui->HomeDir);
  509.    return(&Pas);
  510. }
  511.  
  512.  
  513. /*
  514.  * _getloginname(): get the name of the tasks owner
  515.  *
  516.  * return: the name of the tasks owner
  517.  *
  518.  */
  519. char *_getloginname(void)
  520. {
  521. UWORD  uid;
  522. struct passwd *pwd;
  523.  
  524. if(!setup_mufs())
  525.     return(NULL);
  526.  
  527. uid = muGetTaskOwner(NULL)>>16;
  528. if(!uid)
  529.     return(NULL);
  530.  
  531. pwd=getpwuid(uid);
  532. if(!pwd)
  533.     return(NULL);
  534. return(pwd->pw_name);
  535. }
  536.  
  537. /*
  538.  *  setup_mufs(): setup the MUFS libraries and allocate user/group memory
  539.  *
  540.  *  return: 0 for error
  541.  *          else okay
  542.  *
  543.  */
  544. int setup_mufs(void)
  545. {
  546. if(!muBase)
  547.     {
  548.     muBase=(struct muBase *)OpenLibrary(MULTIUSERNAME,MULTIUSERVERSION);
  549.     if(!muBase)
  550.         {
  551.         DEBUG("setup_mufs: unable to open %s Version >= %d\n",MULTIUSERNAME,MULTIUSERVERSION);
  552.         return(0);
  553.        }
  554.    }
  555.  
  556. if(!ui)
  557.     {
  558.     ui=muAllocUserInfo();
  559.     if(!ui)
  560.         {
  561.         kill_mufs();
  562.         return(NULL);
  563.         }
  564.     }
  565.  
  566. if(!gi)
  567.     {
  568.     gi=muAllocGroupInfo();
  569.     if(!gi)
  570.         {
  571.         kill_mufs();
  572.         return(NULL);
  573.         }
  574.     }
  575.  
  576. return(1);
  577. }
  578.  
  579. /*
  580.  *  kill_mufs(): close the MUFS libraries and deallocate user/group memory
  581.  *
  582.  */
  583. void kill_mufs(void)
  584. {
  585. if(ui)
  586.     {
  587.     muFreeUserInfo(ui);
  588.     ui=NULL;
  589.     }
  590. if(gi)
  591.     {
  592.     muFreeGroupInfo(gi);
  593.     gi=NULL;
  594.     }
  595. if(muBase)
  596.     {
  597.     CloseLibrary((struct Library *)muBase);
  598.     muBase=NULL;
  599.     }
  600. }
  601. #endif /* MUFS */
  602.  
  603. #if !defined(AXSH) && !defined(MUFS)
  604. /*
  605.  *  routines for getty passwd
  606.  */
  607.  
  608. /*
  609.  * getpwent(): get the next passwd entry from passwd
  610.  *
  611.  * return: NULL for no next entry or error
  612.  *         or a filled passwd structure
  613.  *
  614.  */
  615. struct passwd * getpwent(void)
  616. {
  617.     static FILE *fi=NULL;
  618.      char *ptr;
  619.      char *arg;
  620.     char *buf = malloc(256);
  621.     static char User[32];
  622.     static char Passwd[32];
  623.     static char Dir[128];
  624.     static char Shell[256];
  625.     static char Gecos[256];
  626.     static char Comment[256];
  627.     static struct passwd Pas = { User, Passwd, 0, 0, 0, Comment, Gecos,  Dir, Shell };
  628.  
  629.    if(!fi)
  630.        {
  631.         fi = fopen(passwdfile, "r");
  632.         passwd_pos=0;
  633.         }
  634.  
  635.     if (fi == NULL) {
  636.     free(buf);
  637.     return(NULL);
  638.     }
  639.  
  640.    fseek(fi,passwd_pos,0);
  641.    do
  642.    {
  643.    if(fgets(buf, 256, fi)==NULL)
  644.         {
  645.         free(buf);
  646.         fclose(fi);
  647.         passwd_pos=0;
  648.         fi=NULL;
  649.         return(NULL);
  650.        }
  651.    }while(buf[0]=='#');
  652.    passwd_pos=ftell(fi)+1;
  653.    ptr=buf;
  654.     arg = Breakout(&ptr);
  655.     strcpy(Pas.pw_name, arg);
  656.     strcpy(Pas.pw_passwd, Breakout(&ptr));
  657.     Pas.pw_uid = atoi(Breakout(&ptr));
  658.     Pas.pw_gid = atoi(Breakout(&ptr));
  659.     strcpy(Pas.pw_gecos,Breakout(&ptr));     /*  finger info */
  660.     strcpy(Pas.pw_dir, Breakout(&ptr));
  661.     strcpy(Pas.pw_shell, Breakout(&ptr));
  662.  
  663.     {
  664.         short i = strlen(Pas.pw_dir) - 1;
  665.         if (i >= 0 && Pas.pw_dir[i] != ':' && Pas.pw_dir[i] != '/') {
  666.         Pas.pw_dir[++i] = '/';
  667.         Pas.pw_dir[++i] = 0;
  668.         }
  669.     }
  670.  
  671.     {
  672.         char *str;
  673.  
  674.         Pas.pw_shell_arg0 = Pas.pw_shell;
  675.         for (str = Pas.pw_shell; *str && *str != ' ' && *str != 9; ++str);
  676.         if (*str) {
  677.         *str = 0;
  678.         ++str;
  679.         while (*str == ' ' || *str == 9)
  680.             ++str;
  681.         Pas.pw_shell_argn = str;
  682.         } else {
  683.         Pas.pw_shell_argn = str;
  684.         }
  685.     }
  686.     free(buf);
  687.     return(&Pas);
  688. }
  689.  
  690. /*
  691.  * getpwname(): get the passwd entry of a special user from passwd
  692.  *
  693.  * params:  name of the user
  694.  * return: NULL for no next entry or error
  695.  *         or a filled passwd structure
  696.  *
  697.  */
  698. struct passwd *
  699. getpwnam(name)
  700. const char *name;
  701. {
  702.     FILE *fi;
  703.     char *buf = malloc(256);
  704.     static char User[32];
  705.     static char Passwd[32];
  706.     static char Dir[128];
  707.     static char Shell[256];
  708.     static char Gecos[256];
  709.     static char Comment[256];
  710.     static struct passwd Pas = { User, Passwd, 0, 0, 0, Comment, Gecos,  Dir, Shell };
  711.  
  712.     fi = fopen(passwdfile, "r");
  713.  
  714.     if (fi == NULL) {
  715.     free(buf);
  716.    DEBUG("getpwnam: Couldn't open '%s'\n",passwdfile);
  717.     return(NULL);
  718.     }
  719.  
  720.     while (fgets(buf, 256, fi)) {
  721.     char *ptr = buf;
  722.     char *arg;
  723.  
  724.     arg = Breakout(&ptr);
  725.     if (strcmp(name, arg) != 0)
  726.         continue;
  727.     strcpy(Pas.pw_name, arg);
  728.     strcpy(Pas.pw_passwd, Breakout(&ptr));
  729.     Pas.pw_uid = atoi(Breakout(&ptr));
  730.     Pas.pw_gid = atoi(Breakout(&ptr));
  731.     strcpy(Pas.pw_gecos,Breakout(&ptr));     /*  finger info */
  732.     strcpy(Pas.pw_dir, Breakout(&ptr));
  733.     strcpy(Pas.pw_shell, Breakout(&ptr));
  734.  
  735.     {
  736.         short i = strlen(Pas.pw_dir) - 1;
  737.         if (i >= 0 && Pas.pw_dir[i] != ':' && Pas.pw_dir[i] != '/') {
  738.         Pas.pw_dir[++i] = '/';
  739.         Pas.pw_dir[++i] = 0;
  740.         }
  741.     }
  742.  
  743.     {
  744.         char *str;
  745.  
  746.         Pas.pw_shell_arg0 = Pas.pw_shell;
  747.         for (str = Pas.pw_shell; *str && *str != ' ' && *str != 9; ++str);
  748.         if (*str) {
  749.         *str = 0;
  750.         ++str;
  751.         while (*str == ' ' || *str == 9)
  752.             ++str;
  753.         Pas.pw_shell_argn = str;
  754.         } else {
  755.         Pas.pw_shell_argn = str;
  756.         }
  757.     }
  758.     fclose(fi);
  759.     free(buf);
  760.     return(&Pas);
  761.     }
  762.     free(buf);
  763.     fclose(fi);
  764.     DEBUG("getpwnam: Couldn't find '%s' in '%s'\n",name,passwdfile);
  765.     return(NULL);
  766. }
  767. #endif /* !AXSH && !MUFS */
  768.  
  769.  
  770. /*
  771.  * findconfig(): find a config field in uulib:config/s:uuconfig
  772.  *
  773.  * params: field name (case insensitive)
  774.  * return: NULL for error
  775.  *         pointer to char array (you have to free() it)
  776.  */
  777. char *
  778. findconfig(field)
  779. char *field;
  780. {
  781.     char *str;
  782.     short flen = strlen(field);
  783.  
  784.     /*
  785.      *    load config file if not already loaded
  786.      */
  787.  
  788.     if (ConfBuf == NULL) {
  789.     FILE *fi;
  790.     fi = fopen("S:UUConfig", "r");
  791.     if (fi == NULL)
  792.         fi = fopen("UULIB:Config", "r");
  793.     if (fi) {
  794.         long buflen;
  795.         fseek(fi, 0L, 2);
  796.         buflen = ftell(fi);
  797.         fseek(fi, 0L, 0);
  798.         if (buflen > 0 && (ConfBuf = malloc(buflen + 1))) {
  799.         fread(ConfBuf, buflen, 1, fi);
  800.         ConfBuf[buflen] = CTLZ;     /*    can't use \0 */
  801.         for (str = ConfBuf; *str && *str != CTLZ; ++str) {
  802.             char *bup;
  803.             if (*str == '\n') {     /*  make separate strs */
  804.             *str = 0;
  805.                         /*    remove white space at end */
  806.             for (bup = str - 1; bup >= ConfBuf && (*bup == ' ' || *bup == 9); --bup)
  807.                 *bup = 0;
  808.             }
  809.         }
  810.         } else {
  811.         ConfBuf = NULL;
  812.         }
  813.         fclose(fi);
  814.     } else {
  815.         DEBUG("findconfig: Couldn't open S:UUConfig or UULIB:Config\n");
  816.     }
  817.     }
  818.     if (ConfBuf == NULL)
  819.     return(NULL);
  820.  
  821.     /*
  822.      *    Search ConfBuf for Field<space/tab>
  823.      */
  824.  
  825.     for (str = ConfBuf; *str != CTLZ; str += strlen(str) + 1) {
  826.     if (*str == 0 || *str == '#')
  827.         continue;
  828.     if (strnicmp(str, field, flen) == 0 && (str[flen] == ' ' || str[flen] == '\t')) {
  829.         str += flen;
  830.         while (*str == ' ' || *str == 9)
  831.         ++str;
  832.         return(str);
  833.     }
  834.     }
  835.     return(NULL);
  836. }
  837. /*
  838.  * checkuid(): check whether the user is allowed to deliver mails via UUCP
  839.  *
  840.  * params: name of the user
  841.  * return: 0 - okay
  842.  *         else no
  843.  *
  844.  */
  845. int checkuid(char *name)
  846. {
  847.  
  848. /* if we don't check user return allowed */
  849. if(!checkuser)
  850.     return(0);
  851.  
  852. /* MAILERDAEMON ALWAYS have the permission to send */
  853. if(stricmp(name,"MAILER-DAEMON")==0)
  854.     return(0);
  855.  
  856. #ifdef MUFS
  857. {
  858. register int i;
  859.  
  860. ADVISE("checkuid: seaching user '%s' in MUFS passwd\n",name);
  861.  
  862. if(!setup_mufs())
  863.    goto go_on;
  864.  
  865. strcpy(ui->UserID,name);
  866. if(muGetUserInfo(ui,muKeyType_UserID)==NULL)
  867.     {
  868.     DEBUG("checkuid: unable to find Username '%s' in MUFS passwd\n",name);
  869.    goto go_on;
  870.     }
  871.  
  872. strcpy(gi->GroupID,"mail");
  873. if(muGetGroupInfo(gi,muKeyType_GroupID)==NULL)
  874.     {
  875.     DEBUG("checkuid: unable to find group '%s' in MUFS group file\n","mail");
  876.    goto go_on;
  877.     }
  878.  
  879. for(i=0;i<ui->NumSecGroups;i++)
  880.     {
  881.    if(ui->SecGroups[i]==gi->gid)
  882.        return(0);
  883.    }
  884. }
  885. #endif
  886.  
  887. /* sorry for this goto :-) */
  888. go_on:
  889. {
  890. static char *text=NULL;
  891. char puf[SMLBUF]="\n",*found;
  892.  
  893. ADVISE("checkuid: seaching user '%s' in '%s' ",name,checkuserfile);
  894. if(!text)
  895.     {
  896.     FILE *fp=NULL;
  897.     size_t pos;
  898.  
  899.     fp=fopen(checkuserfile,"r");
  900.     if(!fp)
  901.         {
  902.         ADVISE("checkuid: checkuser file open('%s') failed\n",checkuserfile);
  903.         return(-1);
  904.       }
  905.     fseek(fp,0,SEEK_END);
  906.     pos=ftell(fp);
  907.     if(pos<1)
  908.         {
  909.         ADVISE("checkuid: checkuser file is ('%s') empty\n", checkuserfile);
  910.         return(-1);
  911.       }
  912.     fseek(fp,0,SEEK_SET);
  913.     text=malloc(pos*sizeof(char));
  914.     if(!text)
  915.         {
  916.         ADVISE("checkuid: unable to alloc %d bytes\n", pos);
  917.         return(-1);
  918.       }
  919.     fread(text,pos,1,fp);
  920.     fclose(fp);
  921.     /* case insensitiv, please */
  922.     strlwr(text);
  923.     }
  924. strcat(puf,name);
  925. strcat(puf,"\n");
  926. /* case insensitiv for pattern too, please */
  927. strlwr(puf);
  928. if(strstr(text,puf))
  929.     {
  930.     ADVISE("found\n");
  931.     return(0);
  932.     }
  933. /* if the file starts with this user there is no \n at the begin */
  934. strcpy(puf,name);
  935. strcat(puf,"\n");
  936. found=strstr(text,puf);
  937. if(found==text)
  938.     {
  939.     ADVISE("found\n");
  940.     return(0);
  941.     }
  942.  
  943. ADVISE("not found\n");
  944. return(1);
  945. }
  946. }
  947.  
  948. /*
  949.  * set_programtype(): setup the global buffer prgtype_string
  950.  *
  951.  */
  952. void set_programtype(void)
  953. {
  954. #ifdef MUFS
  955. strcpy(prgtype_string,"MUFS");
  956. #endif
  957. #ifdef AXSH
  958. strcpy(prgtype_string,"AXSh");
  959. #endif
  960. #if !defined(MUFS) && !defined(AXSH)
  961. strcpy(prgtype_string,"Getty");
  962. #endif
  963. }
  964.  
  965. /*
  966.  * getuid(): return the userid of the actual login user
  967.  *
  968.  * return: userid
  969.  *
  970.  */
  971. int getuid(void)
  972. {
  973. UBYTE *str;
  974. struct passwd *pwd;
  975.  
  976. str=getloginname();
  977. if(!str)
  978.     return(0);
  979.  
  980. pwd=getpwnam(str);
  981. if(!pwd)
  982.     return(0);
  983. return(pwd->pw_uid);
  984. }
  985.  
  986. /*
  987.  * getgid(): return the user groupid of the actual login user
  988.  *
  989.  * return: usergid
  990.  *
  991.  */
  992. int getgid(void)
  993. {
  994. UBYTE *str;
  995. struct passwd *pwd;
  996.  
  997. str=getloginname();
  998. if(!str)
  999.     return(0);
  1000.  
  1001. pwd=getpwnam(str);
  1002. if(!pwd)
  1003.     return(0);
  1004. return(pwd->pw_gid);
  1005. }
  1006.  
  1007. /*
  1008.  * getpid(): get the actual Process Id
  1009.  *
  1010.  */
  1011. long getpid(void)
  1012. {
  1013. struct Process *proc;
  1014.  
  1015. Forbid();
  1016. proc=(struct Process *)FindTask(NULL);
  1017. Permit();
  1018. if(proc)return(proc->pr_TaskNum);
  1019. return(0);
  1020. }
  1021.  
  1022. /*
  1023.  * getloginname(): return the user name of the actual login user
  1024.  *
  1025.  * return: user name
  1026.  *
  1027.  */
  1028. char *getloginname(void)
  1029. {
  1030. static UBYTE buffer[SMLBUF];
  1031. char *str;
  1032.  
  1033. #ifdef MUFS
  1034. str=_getloginname();
  1035. if(str)
  1036.     {
  1037.     return((char *)str);
  1038.     }
  1039. #endif
  1040.  
  1041. if(GetVar("USER",buffer,128,GVF_LOCAL_ONLY)!=-1)
  1042.     return((char *)buffer);
  1043. str=findconfig("UserName");
  1044. if(str)
  1045.     {
  1046.     strcpy(buffer,str);
  1047.     return((char *)buffer);
  1048.     }
  1049. DEBUG( "getloginname: Couldn't find your login name\n");
  1050. return(NULL);
  1051. }
  1052.  
  1053. /*
  1054.  * uncomment(): removes comments brackets
  1055.  *
  1056.  * params: line to remove brackets
  1057.  *
  1058.  */
  1059. static
  1060. void
  1061. uncomment(char *p)
  1062. {
  1063.     char *b;
  1064.     while((p = index(p, '(')) != NULL) {
  1065.        strcpy(p,p+1);
  1066.        b=p;
  1067.         if((p = index(p, ')')) != NULL) {/* look for close paren */
  1068.             (void) strcpy(p, p+1);
  1069.         } else {
  1070.             *b = '\0';    /* no paren, skip rest of line  */
  1071.             break;
  1072.         }
  1073.     }
  1074. }
  1075.  
  1076. /*
  1077.  * getrealname(): get the real name
  1078.  *
  1079.  * params: user name
  1080.  *
  1081.  */
  1082. char *getrealname(char *user)
  1083. {
  1084. static UBYTE buffer[128];
  1085. struct passwd *pwd;
  1086. char *str;
  1087.  
  1088. if(user)
  1089.     {
  1090.     pwd=getpwnam(user);
  1091.     if(pwd)
  1092.         {
  1093.         str=pwd->pw_gecos;
  1094.         uncomment(str);
  1095.         return((char *)pwd->pw_gecos);
  1096.         }
  1097.     }
  1098.  
  1099. if(GetVar("REALNAME",buffer,128,GVF_LOCAL_ONLY)!=-1)
  1100.     return((char *)buffer);
  1101.  
  1102. str=getloginname();
  1103. if(str)
  1104.     {
  1105.     pwd=getpwnam(str);
  1106.     if(pwd)
  1107.         {
  1108.         str=pwd->pw_gecos;
  1109.         uncomment(str);
  1110.         return((char *)pwd->pw_gecos);
  1111.         }
  1112.    }
  1113.  
  1114. str=findconfig("RealName");
  1115. if(str)
  1116.     {
  1117.     strcpy(buffer,str);
  1118.     return((char *)buffer);
  1119.    }
  1120.  
  1121. DEBUG("getrealname: Couldn't find '%s' realname\n",user);
  1122. return(NULL);
  1123. }
  1124.  
  1125. /*
  1126.  * gethostname(): get the host name
  1127.  *
  1128.  * params: hostname buffer and length
  1129.  *
  1130.  */
  1131. void gethostname(char hostname[],size_t len)
  1132. {
  1133. char *str;
  1134.  
  1135. hostname[0]='\0';
  1136. str=findconfig("NodeName");
  1137. if(str)
  1138.     {
  1139.     strcpy(hostname,str);
  1140.     return;
  1141.     }
  1142. if(GetVar("HOSTNAME",hostname,len,NULL)!=-1)
  1143.     return;
  1144. if(GetVar("HOST",hostname,len,NULL)!=-1)
  1145.     return;
  1146. DEBUG("gethostname: Warning!!! Couldn't find your host name\n");
  1147. }
  1148.  
  1149. /*
  1150.  * getdomainname(): get the domain name
  1151.  *
  1152.  * params: domainname buffer and length
  1153.  *
  1154.  */
  1155. void getdomainname(char name[],size_t len)
  1156. {
  1157. char *str;
  1158.  
  1159. name[0]='\0';
  1160. str=findconfig("DomainName");
  1161. if(str)
  1162.     {
  1163.     strcpy(name,str);
  1164.    return;
  1165.     }
  1166. if(GetVar("DOMAIN",name,len,NULL)!=-1)
  1167.     return;
  1168. DEBUG("getdomainname: Warning!!! Couldn't find your host domain\n");
  1169. }
  1170.  
  1171. /*
  1172.  * getsmarthost(): get the name of the smarthost
  1173.  *
  1174.  * params: smarthostname buffer and length
  1175.  *
  1176.  */
  1177. void getsmarthost(char name[],size_t len)
  1178. {
  1179. char *str;
  1180.  
  1181. name[0]='\0';
  1182. str=findconfig("SMSmarthost");
  1183. if(str)
  1184.     {
  1185.     strcpy(name,str);
  1186.     return;
  1187.     }
  1188. #ifdef SMARTHOST
  1189.     strcpy(name,SMARTHOST);
  1190.     return;
  1191. #endif
  1192. DEBUG("getsmarthost: Couldn't find your smarthost\n");
  1193. }
  1194.  
  1195. /*
  1196.  * get_config(): get a config entry
  1197.  *
  1198.  * params: keyword
  1199.  *         0  - Yes/no
  1200.  *         1  - Number
  1201.  *         2  - string
  1202.  *
  1203.  */
  1204. char *get_config(char entry[],short art)
  1205. {
  1206. char *str;
  1207.  
  1208. str=findconfig(entry);
  1209. switch(art)
  1210. {
  1211.     case 0:
  1212.     if(str && ((stricmp(str,"YES")==0) || (stricmp(str,"TRUE")==0)))
  1213.      return("YES");
  1214.    break;
  1215.     case 1:
  1216.     if(str && atoi(str)!=0)
  1217.      return(str);
  1218.    break;
  1219.     case 2:
  1220.     if(str)
  1221.      return(str);
  1222.    break;
  1223. }
  1224. return(NULL);
  1225. }
  1226.  
  1227. /*
  1228.  * sleep(): wait time secs
  1229.  *
  1230.  */
  1231. void sleep(unsigned long time)
  1232. {
  1233. Delay(50L*time);
  1234. }
  1235.  
  1236. /*
  1237.  * mktemp(): generate temp file name
  1238.  *
  1239.  * params: return buffer for the temp buffer
  1240.  *
  1241.  */
  1242. void mktemp(char pattern[])
  1243. {
  1244. strcpy(pattern,tmpnam(NULL));
  1245. }
  1246.  
  1247. /*
  1248.  * my_system(): a stub routine for system()
  1249.  *
  1250.  * params: command
  1251.  *         stderrr name
  1252.  * return: return code
  1253.  *
  1254.  */
  1255. int my_system(char *cmd,char *errname)
  1256. {
  1257. int rc;
  1258. struct TagItem ti[2];
  1259.  
  1260. ti[0].ti_Tag=NP_StackSize;
  1261. ti[0].ti_Data=80000L;
  1262. ti[1].ti_Tag=TAG_DONE;
  1263.  
  1264. strcat(cmd," >>");
  1265. strcat(cmd,errname);
  1266.  
  1267. rc=SystemTagList(cmd,ti);
  1268. if(rc==0)return(0);
  1269. return(rc);
  1270. }
  1271.  
  1272. /*
  1273.  * writelog(): write a log entry in Dillon uucp style
  1274.  *
  1275.  * params: entries for logfile
  1276.  *
  1277.  */
  1278. void
  1279. writelog (const char *ctl,...)
  1280. {
  1281.   struct tm *tm;
  1282.   time_t time_sec;
  1283.   FILE *fp = NULL;
  1284.   char logbuf[BIGBUF]="";
  1285.   va_list args;
  1286.  
  1287.   va_start (args, ctl);
  1288.  
  1289.   time (&time_sec);
  1290.   tm = localtime (&time_sec);
  1291.  
  1292.   sprintf (logbuf, "(%02d/%02d-%02d:%02d:%02d) %s,-,-", tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SMAIL);
  1293.   vsprintf (logbuf + strlen (logbuf), ctl, args);
  1294.   va_end (args);
  1295.  
  1296.   fp = fopen (logfile, "a");
  1297.   if(!fp)return;
  1298.   fputs(logbuf,fp);
  1299.   fputc('\n',fp);
  1300.   fclose(fp);
  1301. }
  1302.  
  1303. /*
  1304.  * mkfilename(): generate a file name from file and dir path
  1305.  *
  1306.  * params: directory and file part
  1307.  * return: the connectect dir and filepath
  1308.  *
  1309.  */
  1310. char *
  1311. mkfilename(const char *dir,const char *file)
  1312. {
  1313. static char buf[BIGBUF];
  1314.  
  1315. strcpy(buf,dir);
  1316. AddPart(buf,(char *)file,BIGBUF-1);
  1317. return(buf);
  1318. }
  1319.  
  1320. /*
  1321.  * grep_toline(): grep a line start with pattern replace , with spaces
  1322.  *
  1323.  * params: fp - Filepointer
  1324.  *         pattern -  Search pattern
  1325.  *
  1326.  * return: the rest of the line without \n
  1327.  *
  1328.  */
  1329. char *grep_toline(FILE *fp,char *pattern)
  1330. {
  1331. char line[BIGBUF],*back=NULL,*ptr,*end,*start,*addr;
  1332. size_t len;
  1333. size_t pos;
  1334. size_t count;
  1335.  
  1336. if(!fp || !pattern)return(NULL);
  1337.  
  1338. len=strlen(pattern);
  1339. pos=ftell(fp);
  1340.  
  1341. /* test whether the stream is empty (e.g nil:)*/
  1342. fseek(fp,0,SEEK_END);
  1343. if(ftell(fp)==pos)
  1344.     {
  1345.    return(NULL);
  1346.    }
  1347.  
  1348. /* rewind to the begin */
  1349. fseek(fp,pos,SEEK_SET);
  1350.  
  1351. while(fgets(line,BIGBUF,fp)!=NULL)
  1352.     if(strncmp(line,pattern,len)==0)
  1353.         {
  1354.        end=strchr(line,'\n');
  1355.        if(end)
  1356.            *end='\0';
  1357.        back=strdup(&line[len]);
  1358.       /* continuation lines */
  1359.        while(fgets(line,BIGBUF,fp)!=NULL && (line[0]==' ' || line[0]=='\t'))
  1360.            {
  1361.            end=strchr(line,'\n');
  1362.            if(end)
  1363.                *end='\0';
  1364.            strins(line,back);
  1365.            if(back)free(back);
  1366.            back=strdup(line);
  1367.          }
  1368.        /* handle <addr> lines */
  1369.         for(addr=ptr=back,count=0;*ptr!='\0';ptr++)
  1370.         {
  1371.             switch(*ptr)
  1372.                 {
  1373.                 case ',':
  1374.                     addr=ptr+1;
  1375.                     count=0;
  1376.                break;
  1377.                 case '<':
  1378.                     count++;
  1379.                  if(count==1)start=ptr+1;
  1380.                 break;
  1381.                 case '>':
  1382.                     count--;
  1383.                  if(count==0 && addr && start)
  1384.                         {*ptr=' ';strcpy(addr,start);}
  1385.                     ptr=addr;
  1386.                 break;
  1387.              }
  1388.          }
  1389.        /* removes (Realname) */
  1390.         for(ptr=back,count=0;*ptr!='\0';ptr++)
  1391.             switch(*ptr)
  1392.                 {
  1393.                 case ',':
  1394.                     count=0;
  1395.                break;
  1396.                 case '(':
  1397.                     count++;
  1398.                  if(count==1)start=ptr;
  1399.                 break;
  1400.                 case ')':
  1401.                     count--;
  1402.                  if((count==0) && start)
  1403.                      {
  1404.                         strcpy(start,ptr+1);
  1405.                         ptr=start;
  1406.                   }
  1407.                 break;
  1408.              }
  1409.       ptr=back;
  1410.        while(ptr=index(ptr,','))*ptr=' ';
  1411.       ptr=back;
  1412.        while(ptr=index(ptr,'\t'))*ptr=' ';
  1413.        break;
  1414.         }
  1415.         else
  1416.             if(line[0]=='\n')break;
  1417.  
  1418. if(back)
  1419.     {
  1420.     BOOL flag;
  1421.  
  1422.    /* remove all leadings spaces/tabs */
  1423.    for(ptr=back;*ptr!='\0';ptr++)
  1424.        if(*ptr==' ' ||
  1425.           *ptr=='\t')
  1426.       strcpy(ptr,ptr+1);
  1427.  
  1428.     /* kill every i.th spaces i>1 */
  1429.     for(ptr=back,flag=FALSE;*ptr!='\0';ptr++)
  1430.         if(*ptr==' ')
  1431.             {
  1432.             if(!flag)flag=TRUE;
  1433.             else
  1434.                 {
  1435.                 char *old=ptr;
  1436.                 strcpy(ptr,stpblk(old));
  1437.                 }
  1438.          }
  1439.       else
  1440.          flag=FALSE;
  1441.  
  1442.    /* remove all spaces on the end */
  1443.     for(ptr=back+strlen(back)-1;(*ptr==' ' || *ptr=='\t') && (ptr!=back);ptr--);
  1444.    *(ptr+1)='\0';
  1445.    }
  1446.  
  1447. fseek(fp,pos,SEEK_SET);
  1448. return(back);
  1449. }
  1450. @
  1451.  
  1452.  
  1453. 1.18
  1454. log
  1455. @rename getversion() get_programtype() and store the program
  1456. type in the global var programtype_string
  1457. @
  1458. text
  1459. @d21 4
  1460. a83 1
  1461. static char     *rcsid="$Id: sysdep.c,v 1.17 1993/11/12 23:05:06 Aussem Exp Aussem $";
  1462. d85 1
  1463. a85 1
  1464. extern int debug;
  1465. a86 1
  1466. #define CTLZ    ('z'&0x1F)
  1467. a98 4
  1468. #ifdef AXSH
  1469. #include "axsh/iomodes.h"
  1470. #include "axsh/misc.h"
  1471. #include "axsh/users.h"
  1472. d100 1
  1473. a100 2
  1474. static struct User usr;
  1475. #endif
  1476. d103 7
  1477. a109 5
  1478. extern char passwdfile[];
  1479. extern char logfile[];
  1480. extern int checkuser;
  1481. char checkuserfile[SMLBUF]="uulib:mail/checkuser";
  1482. char prgtype_string[]="UNKNOWN";
  1483. d111 1
  1484. d114 2
  1485. a116 1
  1486.  
  1487. d119 9
  1488. d151 7
  1489. a157 1
  1490.  * global atexit function
  1491. d167 10
  1492. a176 4
  1493. int setpassent(int p)
  1494. {
  1495. passwd_pos=p;
  1496. }
  1497. d178 2
  1498. a179 4
  1499. int setpwent(void)
  1500. {
  1501. passwd_pos=0;
  1502. }
  1503. d181 7
  1504. a187 1
  1505. #ifdef AXSH
  1506. d204 7
  1507. d234 8
  1508. d266 1
  1509. a266 1
  1510. #endif
  1511. d268 4
  1512. a271 120
  1513. #if !defined(AXSH) && !defined(MUFS)
  1514. struct passwd * getpwent(void)
  1515. {
  1516.     static FILE *fi=NULL;
  1517.      char *ptr;
  1518.      char *arg;
  1519.     char *buf = malloc(256);
  1520.     static char User[32];
  1521.     static char Passwd[32];
  1522.     static char Dir[128];
  1523.     static char Shell[256];
  1524.     static char Gecos[256];
  1525.     static char Comment[256];
  1526.     static struct passwd Pas = { User, Passwd, 0, 0, 0, Comment, Gecos,  Dir, Shell };
  1527.  
  1528.    if(!fi)
  1529.        {
  1530.         fi = fopen(passwdfile, "r");
  1531.         passwd_pos=0;
  1532.         }
  1533.  
  1534.     if (fi == NULL) {
  1535.     free(buf);
  1536.     return(NULL);
  1537.     }
  1538.  
  1539.    fseek(fi,passwd_pos,0);
  1540.    do
  1541.    {
  1542.    if(fgets(buf, 256, fi)==NULL)
  1543.         {
  1544.         free(buf);
  1545.         fclose(fi);
  1546.         passwd_pos=0;
  1547.         fi=NULL;
  1548.         return(NULL);
  1549.        }
  1550.    }while(buf[0]=='#');
  1551.    passwd_pos=ftell(fi)+1;
  1552.    ptr=buf;
  1553.     arg = Breakout(&ptr);
  1554.     strcpy(Pas.pw_name, arg);
  1555.     strcpy(Pas.pw_passwd, Breakout(&ptr));
  1556.     Pas.pw_uid = atoi(Breakout(&ptr));
  1557.     Pas.pw_gid = atoi(Breakout(&ptr));
  1558.     strcpy(Pas.pw_gecos,Breakout(&ptr));     /*  finger info */
  1559.     strcpy(Pas.pw_dir, Breakout(&ptr));
  1560.     strcpy(Pas.pw_shell, Breakout(&ptr));
  1561.  
  1562.     {
  1563.         short i = strlen(Pas.pw_dir) - 1;
  1564.         if (i >= 0 && Pas.pw_dir[i] != ':' && Pas.pw_dir[i] != '/') {
  1565.         Pas.pw_dir[++i] = '/';
  1566.         Pas.pw_dir[++i] = 0;
  1567.         }
  1568.     }
  1569.  
  1570.     {
  1571.         char *str;
  1572.  
  1573.         Pas.pw_shell_arg0 = Pas.pw_shell;
  1574.         for (str = Pas.pw_shell; *str && *str != ' ' && *str != 9; ++str);
  1575.         if (*str) {
  1576.         *str = 0;
  1577.         ++str;
  1578.         while (*str == ' ' || *str == 9)
  1579.             ++str;
  1580.         Pas.pw_shell_argn = str;
  1581.         } else {
  1582.         Pas.pw_shell_argn = str;
  1583.         }
  1584.     }
  1585.     free(buf);
  1586.     return(&Pas);
  1587. }
  1588.  
  1589. struct passwd *
  1590. getpwnam(name)
  1591. const char *name;
  1592. {
  1593.     FILE *fi;
  1594.     char *buf = malloc(256);
  1595.     static char User[32];
  1596.     static char Passwd[32];
  1597.     static char Dir[128];
  1598.     static char Shell[256];
  1599.     static char Gecos[256];
  1600.     static char Comment[256];
  1601.     static struct passwd Pas = { User, Passwd, 0, 0, 0, Comment, Gecos,  Dir, Shell };
  1602.  
  1603.     fi = fopen(passwdfile, "r");
  1604.  
  1605.     if (fi == NULL) {
  1606.     free(buf);
  1607.    DEBUG("getpwnam: Couldn't open '%s'\n",passwdfile);
  1608.     return(NULL);
  1609.     }
  1610.  
  1611.     while (fgets(buf, 256, fi)) {
  1612.     char *ptr = buf;
  1613.     char *arg;
  1614.  
  1615.     arg = Breakout(&ptr);
  1616.     if (strcmp(name, arg) != 0)
  1617.         continue;
  1618.     strcpy(Pas.pw_name, arg);
  1619.     strcpy(Pas.pw_passwd, Breakout(&ptr));
  1620.     Pas.pw_uid = atoi(Breakout(&ptr));
  1621.     Pas.pw_gid = atoi(Breakout(&ptr));
  1622.     strcpy(Pas.pw_gecos,Breakout(&ptr));     /*  finger info */
  1623.     strcpy(Pas.pw_dir, Breakout(&ptr));
  1624.     strcpy(Pas.pw_shell, Breakout(&ptr));
  1625.  
  1626.     {
  1627.         short i = strlen(Pas.pw_dir) - 1;
  1628.         if (i >= 0 && Pas.pw_dir[i] != ':' && Pas.pw_dir[i] != '/') {
  1629.         Pas.pw_dir[++i] = '/';
  1630.         Pas.pw_dir[++i] = 0;
  1631.         }
  1632.     }
  1633. d273 1
  1634. a273 27
  1635.     {
  1636.         char *str;
  1637.  
  1638.         Pas.pw_shell_arg0 = Pas.pw_shell;
  1639.         for (str = Pas.pw_shell; *str && *str != ' ' && *str != 9; ++str);
  1640.         if (*str) {
  1641.         *str = 0;
  1642.         ++str;
  1643.         while (*str == ' ' || *str == 9)
  1644.             ++str;
  1645.         Pas.pw_shell_argn = str;
  1646.         } else {
  1647.         Pas.pw_shell_argn = str;
  1648.         }
  1649.     }
  1650.     fclose(fi);
  1651.     free(buf);
  1652.     return(&Pas);
  1653.     }
  1654.     free(buf);
  1655.     fclose(fi);
  1656.     DEBUG("getpwnam: Couldn't find '%s' in '%s'\n",name,passwdfile);
  1657.     return(NULL);
  1658. }
  1659. #endif
  1660.  
  1661. #ifdef MUFS
  1662. d278 1
  1663. d283 1
  1664. d287 8
  1665. d325 8
  1666. d363 7
  1667. d399 6
  1668. d423 7
  1669. d465 4
  1670. d489 174
  1671. d723 8
  1672. a730 1
  1673.  
  1674. d834 4
  1675. d851 6
  1676. d872 6
  1677. d893 4
  1678. d908 6
  1679. d916 1
  1680. a916 1
  1681. static UBYTE buffer[128];
  1682. d939 6
  1683. d962 6
  1684. d1011 6
  1685. d1035 6
  1686. d1057 6
  1687. d1081 9
  1688. d1113 4
  1689. d1122 6
  1690. d1133 8
  1691. d1159 4
  1692. a1162 1
  1693.  * write to uuspool:logfile
  1694. d1189 7
  1695. d1206 9
  1696. @
  1697.  
  1698.  
  1699. 1.17
  1700. log
  1701. @checkuid() now uses the checkuser file in MUFS version too
  1702. checkuid does not care about case of the users
  1703. in checkuser file
  1704. @
  1705. text
  1706. @d21 5
  1707. d80 1
  1708. a80 1
  1709. static char     *rcsid="$Id: sysdep.c,v 1.16 1993/11/09 22:42:58 Aussem Exp Aussem $";
  1710. d110 1
  1711. d712 1
  1712. a712 1
  1713. char *getversion(void)
  1714. d715 1
  1715. a715 1
  1716. return("MUFS");
  1717. d718 4
  1718. a721 1
  1719. return("AXSh");
  1720. a722 1
  1721. return("Getty");
  1722. @
  1723.  
  1724.  
  1725. 1.16
  1726. log
  1727. @Debug msgs unified
  1728. user access check implemented
  1729. MUFS routines optimizied
  1730. @
  1731. text
  1732. @d21 5
  1733. d75 1
  1734. a75 1
  1735. static char     *rcsid="$Id: sysdep.c,v 1.15 1993/11/04 22:46:49 Aussem Exp Aussem $";
  1736. d621 1
  1737. a621 1
  1738.     return(-1);
  1739. d627 1
  1740. a627 1
  1741.     return(-1);
  1742. d634 1
  1743. a634 1
  1744.     return(-1);
  1745. d642 2
  1746. a643 1
  1747. return(-1);
  1748. d645 2
  1749. a646 2
  1750. }
  1751. #else
  1752. d679 2
  1753. d684 2
  1754. a703 1
  1755. #endif
  1756. @
  1757.  
  1758.  
  1759. 1.15
  1760. log
  1761. @grep_*() deletes now tabs too
  1762. @
  1763. text
  1764. @d21 3
  1765. d70 1
  1766. a70 1
  1767. static char     *rcsid="$Id: sysdep.c,v 1.14 1993/11/02 22:43:42 Aussem Exp Aussem $";
  1768. d98 3
  1769. d310 1
  1770. a310 1
  1771.    DEBUG("Couldn't open %s\n",passwdfile);
  1772. d358 1
  1773. a358 1
  1774.     DEBUG("Couldn't find %s in %s\n",name,passwdfile);
  1775. d368 3
  1776. a370 2
  1777. struct muBase *muBase=NULL;
  1778. struct muUserInfo *ui=NULL;
  1779. d392 1
  1780. a392 1
  1781.     DEBUG("unable to find Username %s\n",name);
  1782. d422 1
  1783. a422 1
  1784.     DEBUG("unable to find UID %d\n",uid);
  1785. d450 1
  1786. a450 1
  1787.     DEBUG("unable to find get to next user\n");
  1788. a478 2
  1789.  
  1790. DEBUG("login:%s\n",pwd->pw_name);
  1791. d489 1
  1792. a489 1
  1793.         DEBUG("unable to open %s Version >= %d\n",MULTIUSERNAME,MULTIUSERVERSION);
  1794. d503 11
  1795. d520 1
  1796. d522 7
  1797. d530 1
  1798. d532 2
  1799. d575 1
  1800. a575 1
  1801.         DEBUG("Couldn't open S:UUConfig or UULIB:Config\n");
  1802. d598 110
  1803. d770 1
  1804. a770 1
  1805. DEBUG( "Couldn't find your login name\n");
  1806. d830 1
  1807. a830 1
  1808. DEBUG("Couldn't find your realname\n");
  1809. d838 1
  1810. d841 1
  1811. d843 2
  1812. d849 1
  1813. a849 1
  1814. DEBUG("Couldn't find your host name\n");
  1815. d856 1
  1816. d859 1
  1817. d861 2
  1818. d865 1
  1819. d872 1
  1820. d875 1
  1821. d877 2
  1822. d881 1
  1823. d883 1
  1824. d925 1
  1825. a925 1
  1826. ti[0].ti_Data=30000L;
  1827. @
  1828.  
  1829.  
  1830. 1.14
  1831. log
  1832. @extended MUFS routines
  1833. @
  1834. text
  1835. @d21 3
  1836. d67 1
  1837. a67 1
  1838. static char     *rcsid="$Id: sysdep.c,v 1.13 1993/11/02 19:56:34 Aussem Exp Aussem $";
  1839. a850 1
  1840.  
  1841. d915 5
  1842. a919 2
  1843.    /* remove all leadings spaces */
  1844.    back=stpblk(back);
  1845. d926 1
  1846. a926 1
  1847.             else 
  1848. d936 1
  1849. a936 1
  1850.     for(ptr=back+strlen(back)-1;(*ptr==' ') && (ptr!=back);ptr--);
  1851. @
  1852.  
  1853.  
  1854. 1.13
  1855. log
  1856. @MUFS routines added
  1857. @
  1858. text
  1859. @d21 3
  1860. d64 1
  1861. a64 1
  1862. static char     *rcsid="$Id: sysdep.c,v 1.12 1993/10/31 21:11:58 Aussem Exp Aussem $";
  1863. d395 30
  1864. d453 21
  1865. a477 1
  1866.    DEBUG("init base\n");
  1867. a487 1
  1868.    DEBUG("init user\n");
  1869. a499 2
  1870. DEBUG("close\n");
  1871.  
  1872. d570 1
  1873. a570 1
  1874. UBYTE buffer[128];
  1875. d573 2
  1876. a574 1
  1877. if(GetVar("USER",buffer,128,GVF_LOCAL_ONLY)==-1)
  1878. d576 2
  1879. a577 1
  1880. pwd=getpwnam(buffer);
  1881. d585 1
  1882. a585 1
  1883. UBYTE buffer[128];
  1884. d588 2
  1885. a589 1
  1886. if(GetVar("USER",buffer,128,GVF_LOCAL_ONLY)==-1)
  1887. d591 2
  1888. a592 1
  1889. pwd=getpwnam(buffer);
  1890. d614 8
  1891. d671 2
  1892. a672 1
  1893. if(GetVar("USER",buffer,128,GVF_LOCAL_ONLY)!=-1)
  1894. d674 1
  1895. a674 1
  1896.     pwd=getpwnam(buffer);
  1897. @
  1898.  
  1899.  
  1900. 1.12
  1901. log
  1902. @grep_toline() eliminate now really all not needed spaces
  1903. @
  1904. text
  1905. @d21 3
  1906. d61 1
  1907. a61 1
  1908. static char     *rcsid="$Id: sysdep.c,v 1.11 1993/10/31 17:50:59 Aussem Exp Aussem $";
  1909. d91 1
  1910. a93 1
  1911. static void uncomment(char *);
  1912. d117 11
  1913. d202 3
  1914. a204 1
  1915. #else
  1916. d351 106
  1917. a698 4
  1918. }
  1919.  
  1920. void execvp(char *name,char *argv[])
  1921. {
  1922. @
  1923.  
  1924.  
  1925. 1.11
  1926. log
  1927. @if stdin is empty (e.g nil:) smail does not wait anymore
  1928. @
  1929. text
  1930. @d21 3
  1931. d58 1
  1932. a58 1
  1933. static char     *rcsid="$Id: sysdep.c,v 1.10 1993/10/24 15:00:22 Aussem Exp Aussem $";
  1934. d732 3
  1935. d740 5
  1936. a744 1
  1937.             else strcpy(ptr,++ptr);
  1938. d748 4
  1939. @
  1940.  
  1941.  
  1942. 1.10
  1943. log
  1944. @AXSh Version is now included in this file (no sysdep_axsh.c anymore)
  1945. @
  1946. text
  1947. @d21 3
  1948. d55 1
  1949. a55 1
  1950. static char     *rcsid="$Id: sysdep.c,v 1.9 1993/09/18 20:23:05 Aussem Exp Aussem $";
  1951. d646 10
  1952. @
  1953.  
  1954.  
  1955. 1.9
  1956. log
  1957. @the cc line can now be parsed from cmdline and from file
  1958. @
  1959. text
  1960. @d21 3
  1961. d52 1
  1962. a52 1
  1963. static char     *rcsid="$Id: sysdep.c,v 1.8 1993/09/18 16:47:47 Aussem Exp Aussem $";
  1964. d69 8
  1965. d118 65
  1966. d327 1
  1967. @
  1968.  
  1969.  
  1970. 1.8
  1971. log
  1972. @insert GNU license text in the header
  1973. @
  1974. text
  1975. @d21 3
  1976. d49 1
  1977. a49 1
  1978. static char     *rcsid="$Id: sysdep.c,v 1.7 1993/09/16 22:36:48 Aussem Exp Aussem $";
  1979. d555 1
  1980. a555 1
  1981. char *grep_toline(FILE *fp)
  1982. d558 1
  1983. a558 2
  1984. const char to[]="To: ";
  1985. const size_t len=strlen(to);
  1986. d562 1
  1987. a562 1
  1988. if(!fp)return(NULL);
  1989. d564 1
  1990. d566 1
  1991. d568 1
  1992. a568 1
  1993.     if(strncmp(line,to,len)==0)
  1994. @
  1995.  
  1996.  
  1997. 1.7
  1998. log
  1999. @realname elmination in grep_toline() works better now
  2000. @
  2001. text
  2002. @d2 1
  2003. a2 1
  2004.  *  sysdep.c
  2005. d4 1
  2006. a4 1
  2007.  *  System depend routines
  2008. d6 14
  2009. d21 3
  2010. d46 1
  2011. a46 1
  2012. static char     *rcsid="$Id: sysdep.c,v 1.6 1993/09/15 22:22:27 Aussem Exp Aussem $";
  2013. @
  2014.  
  2015.  
  2016. 1.6
  2017. log
  2018. @grep_toline() <addr> are now recognized
  2019. @
  2020. text
  2021. @d7 3
  2022. d29 1
  2023. a29 1
  2024. static char     *rcsid="$Id: sysdep.c,v 1.5 1993/09/15 20:17:42 Aussem Exp Aussem $";
  2025. d585 20
  2026. d609 1
  2027. a609 13
  2028.  
  2029.        end=back;
  2030.        while(ptr=index(end,'('))
  2031.             {
  2032.          end=index(ptr,')');
  2033.          if(end)
  2034.              {
  2035.              memmove(ptr,end+1,end+1-ptr);
  2036.             }
  2037.          else
  2038.                break;
  2039.            }
  2040.            break;
  2041. @
  2042.  
  2043.  
  2044. 1.5
  2045. log
  2046. @gethostname and getdomain first look in uulib:config and then
  2047. in the enviroment variables
  2048. @
  2049. text
  2050. @d7 4
  2051. d26 1
  2052. a26 1
  2053. static char     *rcsid="$Id: sysdep.c,v 1.4 1993/09/11 16:27:44 Aussem Exp Aussem $";
  2054. d534 1
  2055. a534 1
  2056. char line[BIGBUF],*back=NULL,*ptr,*end;
  2057. d538 1
  2058. d561 21
  2059. d606 2
  2060. d614 1
  2061. a614 1
  2062.       else   
  2063. @
  2064.  
  2065.  
  2066. 1.4
  2067. log
  2068. @getrealname() now works correctly again
  2069. @
  2070. text
  2071. @d7 3
  2072. d22 1
  2073. a22 1
  2074. static char     *rcsid="$Id: sysdep.c,v 1.3 1993/09/11 01:41:16 Aussem Exp Aussem $";
  2075. d403 3
  2076. d410 1
  2077. a410 5
  2078. str=findconfig("NodeName");
  2079. if(str)
  2080.     strcpy(hostname,str);
  2081. else
  2082.     DEBUG("Couldn't find your host name\n");
  2083. a416 2
  2084. if(GetVar("DOMAIN",name,len,NULL)!=-1)
  2085.     return;
  2086. d420 2
  2087. @
  2088.  
  2089.  
  2090. 1.3
  2091. log
  2092. @\t will now be noticed as continuation of the To: line
  2093. @
  2094. text
  2095. @d7 3
  2096. d19 1
  2097. a19 1
  2098. static char     *rcsid="$Id: sysdep.c,v 1.2 1993/09/10 01:53:25 Aussem Exp Aussem $";
  2099. d40 1
  2100. d43 1
  2101. d67 10
  2102. d92 1
  2103. d94 2
  2104. d102 1
  2105. d109 1
  2106. d114 1
  2107. a114 1
  2108.  
  2109. d337 17
  2110. a358 1
  2111. void strip_comments(char *);
  2112. d365 2
  2113. a366 1
  2114.         strip_comments(pwd->pw_gecos);
  2115. d379 2
  2116. a380 1
  2117.         strip_comments(pwd->pw_gecos);
  2118. @
  2119.  
  2120.  
  2121. 1.2
  2122. log
  2123. @new support for grepping the To: line from mailbody with grep_toline()
  2124. @
  2125. text
  2126. @d7 3
  2127. d16 1
  2128. a16 1
  2129. static char     *rcsid="$Id: sysdep.c,v 1.1 1993/09/08 16:27:13 Aussem Exp Aussem $";
  2130. d506 2
  2131. a507 1
  2132.        while(fgets(line,BIGBUF,fp)!=NULL && line[0]==' ')
  2133. d516 5
  2134. a520 1
  2135.        while(ptr=index(back,','))*ptr=' ';
  2136. @
  2137.  
  2138.  
  2139. 1.1
  2140. log
  2141. @Initial revision
  2142. @
  2143. text
  2144. @d6 3
  2145. a8 1
  2146.  * $Log$
  2147. d10 1
  2148. d13 1
  2149. a13 1
  2150. static char     *rcsid="$Id$";
  2151. d483 61
  2152. @
  2153.