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 >
Wrap
Text File
|
1993-12-21
|
38KB
|
2,153 lines
head 1.19;
access;
symbols
C_1:1.19;
locks; strict;
comment @ * @;
1.19
date 93.11.14.20.58.52; author Aussem; state Exp;
branches;
next 1.18;
1.18
date 93.11.13.21.16.23; author Aussem; state Exp;
branches;
next 1.17;
1.17
date 93.11.12.23.05.06; author Aussem; state Exp;
branches;
next 1.16;
1.16
date 93.11.09.22.42.58; author Aussem; state Exp;
branches;
next 1.15;
1.15
date 93.11.04.22.46.49; author Aussem; state Exp;
branches;
next 1.14;
1.14
date 93.11.02.22.43.42; author Aussem; state Exp;
branches;
next 1.13;
1.13
date 93.11.02.19.56.34; author Aussem; state Exp;
branches;
next 1.12;
1.12
date 93.10.31.21.11.58; author Aussem; state Exp;
branches;
next 1.11;
1.11
date 93.10.31.17.50.59; author Aussem; state Exp;
branches;
next 1.10;
1.10
date 93.10.24.15.00.22; author Aussem; state Exp;
branches;
next 1.9;
1.9
date 93.09.18.20.23.05; author Aussem; state Exp;
branches;
next 1.8;
1.8
date 93.09.18.16.47.47; author Aussem; state Exp;
branches;
next 1.7;
1.7
date 93.09.16.22.36.48; author Aussem; state Exp;
branches;
next 1.6;
1.6
date 93.09.15.22.22.27; author Aussem; state Exp;
branches;
next 1.5;
1.5
date 93.09.15.20.17.42; author Aussem; state Exp;
branches;
next 1.4;
1.4
date 93.09.11.16.27.44; author Aussem; state Exp;
branches;
next 1.3;
1.3
date 93.09.11.01.41.16; author Aussem; state Exp;
branches;
next 1.2;
1.2
date 93.09.10.01.53.25; author Aussem; state Exp;
branches;
next 1.1;
1.1
date 93.09.08.16.27.13; author Aussem; state Exp;
branches;
next ;
desc
@system depended routines for AmigaOS
@
1.19
log
@commtents insert
@
text
@/*
* sysdep.c
*
* System depend routines
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: sysdep.c,v $
* Revision 1.18 1993/11/13 21:16:23 Aussem
* rename getversion() get_programtype() and store the program
* type in the global var programtype_string
*
* Revision 1.17 1993/11/12 23:05:06 Aussem
* checkuid() now uses the checkuser file in MUFS version too
* checkuid does not care about case of the users
* in checkuser file
*
* Revision 1.16 1993/11/09 22:42:58 Aussem
* Debug msgs unified
* user access check implemented
* MUFS routines optimizied
*
* Revision 1.15 1993/11/04 22:46:49 Aussem
* grep_*() deletes now tabs too
*
* Revision 1.14 1993/11/02 22:43:42 Aussem
* extended MUFS routines
*
* Revision 1.13 1993/11/02 19:56:34 Aussem
* MUFS routines added
*
* Revision 1.12 1993/10/31 21:11:58 Aussem
* grep_toline() eliminate now really all not needed spaces
*
* Revision 1.11 1993/10/31 17:50:59 Aussem
* if stdin is empty (e.g nil:) smail does not wait anymore
*
* Revision 1.10 1993/10/24 15:00:22 Aussem
* AXSh Version is now included in this file (no sysdep_axsh.c anymore)
*
* Revision 1.9 1993/09/18 20:23:05 Aussem
* the cc line can now be parsed from cmdline and from file
*
* Revision 1.8 1993/09/18 16:47:47 Aussem
* insert GNU license text in the header
*
* Revision 1.7 1993/09/16 22:36:48 Aussem
* realname elmination in grep_toline() works better now
*
* Revision 1.6 1993/09/15 22:22:27 Aussem
* grep_toline() <addr> are now recognized
*
* Revision 1.5 1993/09/15 20:17:42 Aussem
* gethostname and getdomain first look in uulib:config and then
* in the enviroment variables
*
* Revision 1.4 1993/09/11 16:27:44 Aussem
* getrealname() now works correctly again
*
* Revision 1.3 1993/09/11 01:41:16 Aussem
* \t will now be noticed as continuation of the To: line
*
* Revision 1.2 1993/09/10 01:53:25 Aussem
* new support for grepping the To: line from mailbody with grep_toline()
*
* Revision 1.1 1993/09/08 16:27:13 Aussem
* Initial revision
*
*
*/
static char *rcsid="$Id: sysdep.c,v 1.18 1993/11/13 21:16:23 Aussem Exp Aussem $";
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <dos/dostags.h>
#include <proto/dos.h>
#include <pragmas/dos_pragmas.h>
#include <proto/exec.h>
#include <pragmas/exec_pragmas.h>
#include "defs.h"
#define CTLZ ('z'&0x1F)
extern struct DosLibrary *DOSBase;
extern char passwdfile[]; /* name of the passwd file */
extern char logfile[]; /* - " - Dillon styled logfile */
extern int checkuser; /* user checking on/off */
extern int debug; /* debug */
char checkuserfile[SMLBUF]="uulib:mail/checkuser"; /* name of the checkuser file */
char prgtype_string[]="UNKNOWN"; /* type of program (getty/axsh/mufs) */
/* static vars */
static char *ConfBuf = NULL;
static long passwd_pos = 0;
/* static prototypes */
static void uncomment(char *);
static char *Breakout(char **pptr);
/*
* Breakout(): extract a field from a passwd entry
*
* pptr - pointer to a char array
*
* Return:
* pointer to the passwd field
*
*/
static
char *
Breakout(pptr)
char **pptr;
{
char *base;
char *ptr;
base = *pptr;
if (base == NULL)
return("");
for (ptr = base; *ptr && *ptr != '\n' && *ptr != ','; ++ptr);
if (*ptr == ',') {
*pptr = ptr + 1;
*ptr = 0;
} else {
*pptr = NULL;
*ptr = 0;
}
return(base);
}
/*
* kill_external(): global atexit function
*
* This function closes the MUFS library and kill all
* memory allocated for user and group info. For all
* other program types this function do nothing.
* This function is add to the atexit function in main.c
*
*/
void kill_external(void)
{
#ifdef MUFS
void kill_mufs(void);
kill_mufs();
#endif
}
#ifdef AXSH
/*
* passwd routines for the AXSh passwd
*/
/* includes for AXSh */
#include "axsh/iomodes.h"
#include "axsh/misc.h"
#include "axsh/users.h"
/* static vars for AXSh */
static struct User usr;
/*
* axsh_getuid(): get the group id from the uid
*
* params: uid - userid of the user
* return: groupid
*
*/
static UWORD axsh_getgid(UWORD uid)
{
if(uid & UID_DAEMON) return(UID_DAEMON);
if(uid & UID_SYSTEM) return(UID_SYSTEM);
if(uid & UID_WIZARD) return(UID_WIZARD);
if(uid & UID_SUPERUSER) return(UID_SUPERUSER);
if(uid & UID_ASSISTANT) return(UID_ASSISTANT);
if(uid & UID_PRIVILEGED) return(UID_PRIVILEGED);
if(uid & UID_TRUSTED) return(UID_TRUSTED);
if(uid & UID_FRIEND) return(UID_FRIEND);
if(uid & UID_QUALIFIED) return(UID_QUALIFIED);
if(uid & UID_NORMAL) return(UID_NORMAL);
if(uid & UID_GUEST) return(UID_GUEST);
return(UID_VISITOR);
}
/*
* getpwent(): get the next passwd entry from passwd
*
* return: NULL for no next entry or error
* or a filled passwd structure
*
*/
struct passwd * getpwent(void)
{
static char User[32];
static char Passwd[32];
static char Dir[128];
static char Shell[256];
static char Gecos[256];
static char Comment[256];
static struct passwd Pas = { User, Passwd, 0, 0, 0, Comment, Gecos, Dir, Shell };
if(read_userdata("AXsh:etc/passwd",&usr,passwd_pos++)==-1)
return(NULL);
strcpy(Pas.pw_name, usr.Loginname);
strcpy(Pas.pw_passwd, usr.Password);
Pas.pw_uid = usr.UID;
Pas.pw_gid = axsh_getgid(Pas.pw_uid);
strcpy(Pas.pw_gecos,usr.Fullname); /* finger info */
strcpy(Pas.pw_dir,usr.Home);
return(&Pas);
}
/*
* getpwname(): get the passwd entry of a special user from passwd
*
* params: name of the user
* return: NULL for no next entry or error
* or a filled passwd structure
*
*/
struct passwd *
getpwnam(name)
const char *name;
{
static char User[32];
static char Passwd[32];
static char Dir[128];
static char Shell[256];
static char Gecos[256];
static char Comment[256];
static struct passwd Pas = { User, Passwd, 0, 0, 0, Comment, Gecos, Dir, Shell };
if (search_userdata ("AXsh:etc/passwd", &usr, 0,(char *) name) == -1)
return(NULL);
strcpy(Pas.pw_name, usr.Loginname);
strcpy(Pas.pw_passwd, usr.Password);
Pas.pw_uid = usr.UID;
Pas.pw_gid = axsh_getgid(Pas.pw_uid);
strcpy(Pas.pw_gecos,usr.Fullname); /* finger info */
strcpy(Pas.pw_dir,usr.Home);
return(&Pas);
}
#endif /* AXSH */
#ifdef MUFS
/*
* passwd routines for the MUFS passwd
*/
/* include files for MUFS */
#include <proto/multiuser.h>
#include <pragmas/multiuser_pragmas.h>
#include <libraries/multiuser.h>
/* vars for MUFS */
struct muBase *muBase=NULL;
struct muUserInfo *ui=NULL;
struct muGroupInfo *gi=NULL;
/* protos for MUFS */
int setup_mufs(void);
void kill_mufs(void);
/*
* getpwname(): get the passwd entry of a special user from passwd
*
* params: name of the user
* return: NULL for no next entry or error
* or a filled passwd structure
*
*/
struct passwd *
getpwnam(const char *name)
{
static char User[muUSERIDSIZE];
static char Passwd[32];
static char Dir[muHOMEDIRSIZE];
static char Shell[256];
static char Gecos[muUSERNAMESIZE];
static char Comment[256];
static struct passwd Pas = { User, Passwd, 0, 0, 0, Comment, Gecos, Dir, Shell };
if(!setup_mufs())
return(NULL);
strcpy(ui->UserID,name);
if(muGetUserInfo(ui,muKeyType_UserID)==NULL)
{
DEBUG("getpwnam: unable to find user '%s' in MUFS passwd\n",name);
return(NULL);
}
strcpy(Pas.pw_name, ui->UserID);
strcpy(Pas.pw_passwd, "unknown");
Pas.pw_uid = ui->uid;
Pas.pw_gid = ui->gid;
strcpy(Pas.pw_gecos,ui->UserName); /* finger info */
strcpy(Pas.pw_dir,ui->HomeDir);
return(&Pas);
}
/*
* getpwuid(): get the passwd entry of a special user from passwd
*
* params: userid of the user
* return: NULL for no next entry or error
* or a filled passwd structure
*
*/
struct passwd *
getpwuid(int uid)
{
static char User[muUSERIDSIZE];
static char Passwd[32];
static char Dir[muHOMEDIRSIZE];
static char Shell[256];
static char Gecos[muUSERNAMESIZE];
static char Comment[256];
static struct passwd Pas = { User, Passwd, 0, 0, 0, Comment, Gecos, Dir, Shell };
if(!setup_mufs())
return(NULL);
ui->uid=uid;
if(muGetUserInfo(ui,muKeyType_uid)==NULL)
{
DEBUG("getpwnam: unable to find UID '%d' in MUFS passwd\n",uid);
return(NULL);
}
strcpy(Pas.pw_name, ui->UserID);
strcpy(Pas.pw_passwd, "unknown");
Pas.pw_uid = ui->uid;
Pas.pw_gid = ui->gid;
strcpy(Pas.pw_gecos,ui->UserName); /* finger info */
strcpy(Pas.pw_dir,ui->HomeDir);
return(&Pas);
}
/*
* getpwent(): get the next passwd entry from passwd
*
* return: NULL for no next entry or error
* or a filled passwd structure
*
*/
struct passwd * getpwent(void)
{
static char User[muUSERIDSIZE];
static char Passwd[32];
static char Dir[muHOMEDIRSIZE];
static char Shell[256];
static char Gecos[muUSERNAMESIZE];
static char Comment[256];
static struct passwd Pas = { User, Passwd, 0, 0, 0, Comment, Gecos, Dir, Shell };
if(!setup_mufs())
return(NULL);
if(muGetUserInfo(ui,passwd_pos++?muKeyType_Next:muKeyType_First)==NULL)
{
/* all read */
return(NULL);
}
strcpy(Pas.pw_name, ui->UserID);
strcpy(Pas.pw_passwd, "unknown");
Pas.pw_uid = ui->uid;
Pas.pw_gid = ui->gid;
strcpy(Pas.pw_gecos,ui->UserName); /* finger info */
strcpy(Pas.pw_dir,ui->HomeDir);
return(&Pas);
}
/*
* _getloginname(): get the name of the tasks owner
*
* return: the name of the tasks owner
*
*/
char *_getloginname(void)
{
UWORD uid;
struct passwd *pwd;
if(!setup_mufs())
return(NULL);
uid = muGetTaskOwner(NULL)>>16;
if(!uid)
return(NULL);
pwd=getpwuid(uid);
if(!pwd)
return(NULL);
return(pwd->pw_name);
}
/*
* setup_mufs(): setup the MUFS libraries and allocate user/group memory
*
* return: 0 for error
* else okay
*
*/
int setup_mufs(void)
{
if(!muBase)
{
muBase=(struct muBase *)OpenLibrary(MULTIUSERNAME,MULTIUSERVERSION);
if(!muBase)
{
DEBUG("setup_mufs: unable to open %s Version >= %d\n",MULTIUSERNAME,MULTIUSERVERSION);
return(0);
}
}
if(!ui)
{
ui=muAllocUserInfo();
if(!ui)
{
kill_mufs();
return(NULL);
}
}
if(!gi)
{
gi=muAllocGroupInfo();
if(!gi)
{
kill_mufs();
return(NULL);
}
}
return(1);
}
/*
* kill_mufs(): close the MUFS libraries and deallocate user/group memory
*
*/
void kill_mufs(void)
{
if(ui)
{
muFreeUserInfo(ui);
ui=NULL;
}
if(gi)
{
muFreeGroupInfo(gi);
gi=NULL;
}
if(muBase)
{
CloseLibrary((struct Library *)muBase);
muBase=NULL;
}
}
#endif /* MUFS */
#if !defined(AXSH) && !defined(MUFS)
/*
* routines for getty passwd
*/
/*
* getpwent(): get the next passwd entry from passwd
*
* return: NULL for no next entry or error
* or a filled passwd structure
*
*/
struct passwd * getpwent(void)
{
static FILE *fi=NULL;
char *ptr;
char *arg;
char *buf = malloc(256);
static char User[32];
static char Passwd[32];
static char Dir[128];
static char Shell[256];
static char Gecos[256];
static char Comment[256];
static struct passwd Pas = { User, Passwd, 0, 0, 0, Comment, Gecos, Dir, Shell };
if(!fi)
{
fi = fopen(passwdfile, "r");
passwd_pos=0;
}
if (fi == NULL) {
free(buf);
return(NULL);
}
fseek(fi,passwd_pos,0);
do
{
if(fgets(buf, 256, fi)==NULL)
{
free(buf);
fclose(fi);
passwd_pos=0;
fi=NULL;
return(NULL);
}
}while(buf[0]=='#');
passwd_pos=ftell(fi)+1;
ptr=buf;
arg = Breakout(&ptr);
strcpy(Pas.pw_name, arg);
strcpy(Pas.pw_passwd, Breakout(&ptr));
Pas.pw_uid = atoi(Breakout(&ptr));
Pas.pw_gid = atoi(Breakout(&ptr));
strcpy(Pas.pw_gecos,Breakout(&ptr)); /* finger info */
strcpy(Pas.pw_dir, Breakout(&ptr));
strcpy(Pas.pw_shell, Breakout(&ptr));
{
short i = strlen(Pas.pw_dir) - 1;
if (i >= 0 && Pas.pw_dir[i] != ':' && Pas.pw_dir[i] != '/') {
Pas.pw_dir[++i] = '/';
Pas.pw_dir[++i] = 0;
}
}
{
char *str;
Pas.pw_shell_arg0 = Pas.pw_shell;
for (str = Pas.pw_shell; *str && *str != ' ' && *str != 9; ++str);
if (*str) {
*str = 0;
++str;
while (*str == ' ' || *str == 9)
++str;
Pas.pw_shell_argn = str;
} else {
Pas.pw_shell_argn = str;
}
}
free(buf);
return(&Pas);
}
/*
* getpwname(): get the passwd entry of a special user from passwd
*
* params: name of the user
* return: NULL for no next entry or error
* or a filled passwd structure
*
*/
struct passwd *
getpwnam(name)
const char *name;
{
FILE *fi;
char *buf = malloc(256);
static char User[32];
static char Passwd[32];
static char Dir[128];
static char Shell[256];
static char Gecos[256];
static char Comment[256];
static struct passwd Pas = { User, Passwd, 0, 0, 0, Comment, Gecos, Dir, Shell };
fi = fopen(passwdfile, "r");
if (fi == NULL) {
free(buf);
DEBUG("getpwnam: Couldn't open '%s'\n",passwdfile);
return(NULL);
}
while (fgets(buf, 256, fi)) {
char *ptr = buf;
char *arg;
arg = Breakout(&ptr);
if (strcmp(name, arg) != 0)
continue;
strcpy(Pas.pw_name, arg);
strcpy(Pas.pw_passwd, Breakout(&ptr));
Pas.pw_uid = atoi(Breakout(&ptr));
Pas.pw_gid = atoi(Breakout(&ptr));
strcpy(Pas.pw_gecos,Breakout(&ptr)); /* finger info */
strcpy(Pas.pw_dir, Breakout(&ptr));
strcpy(Pas.pw_shell, Breakout(&ptr));
{
short i = strlen(Pas.pw_dir) - 1;
if (i >= 0 && Pas.pw_dir[i] != ':' && Pas.pw_dir[i] != '/') {
Pas.pw_dir[++i] = '/';
Pas.pw_dir[++i] = 0;
}
}
{
char *str;
Pas.pw_shell_arg0 = Pas.pw_shell;
for (str = Pas.pw_shell; *str && *str != ' ' && *str != 9; ++str);
if (*str) {
*str = 0;
++str;
while (*str == ' ' || *str == 9)
++str;
Pas.pw_shell_argn = str;
} else {
Pas.pw_shell_argn = str;
}
}
fclose(fi);
free(buf);
return(&Pas);
}
free(buf);
fclose(fi);
DEBUG("getpwnam: Couldn't find '%s' in '%s'\n",name,passwdfile);
return(NULL);
}
#endif /* !AXSH && !MUFS */
/*
* findconfig(): find a config field in uulib:config/s:uuconfig
*
* params: field name (case insensitive)
* return: NULL for error
* pointer to char array (you have to free() it)
*/
char *
findconfig(field)
char *field;
{
char *str;
short flen = strlen(field);
/*
* load config file if not already loaded
*/
if (ConfBuf == NULL) {
FILE *fi;
fi = fopen("S:UUConfig", "r");
if (fi == NULL)
fi = fopen("UULIB:Config", "r");
if (fi) {
long buflen;
fseek(fi, 0L, 2);
buflen = ftell(fi);
fseek(fi, 0L, 0);
if (buflen > 0 && (ConfBuf = malloc(buflen + 1))) {
fread(ConfBuf, buflen, 1, fi);
ConfBuf[buflen] = CTLZ; /* can't use \0 */
for (str = ConfBuf; *str && *str != CTLZ; ++str) {
char *bup;
if (*str == '\n') { /* make separate strs */
*str = 0;
/* remove white space at end */
for (bup = str - 1; bup >= ConfBuf && (*bup == ' ' || *bup == 9); --bup)
*bup = 0;
}
}
} else {
ConfBuf = NULL;
}
fclose(fi);
} else {
DEBUG("findconfig: Couldn't open S:UUConfig or UULIB:Config\n");
}
}
if (ConfBuf == NULL)
return(NULL);
/*
* Search ConfBuf for Field<space/tab>
*/
for (str = ConfBuf; *str != CTLZ; str += strlen(str) + 1) {
if (*str == 0 || *str == '#')
continue;
if (strnicmp(str, field, flen) == 0 && (str[flen] == ' ' || str[flen] == '\t')) {
str += flen;
while (*str == ' ' || *str == 9)
++str;
return(str);
}
}
return(NULL);
}
/*
* checkuid(): check whether the user is allowed to deliver mails via UUCP
*
* params: name of the user
* return: 0 - okay
* else no
*
*/
int checkuid(char *name)
{
/* if we don't check user return allowed */
if(!checkuser)
return(0);
/* MAILERDAEMON ALWAYS have the permission to send */
if(stricmp(name,"MAILER-DAEMON")==0)
return(0);
#ifdef MUFS
{
register int i;
ADVISE("checkuid: seaching user '%s' in MUFS passwd\n",name);
if(!setup_mufs())
goto go_on;
strcpy(ui->UserID,name);
if(muGetUserInfo(ui,muKeyType_UserID)==NULL)
{
DEBUG("checkuid: unable to find Username '%s' in MUFS passwd\n",name);
goto go_on;
}
strcpy(gi->GroupID,"mail");
if(muGetGroupInfo(gi,muKeyType_GroupID)==NULL)
{
DEBUG("checkuid: unable to find group '%s' in MUFS group file\n","mail");
goto go_on;
}
for(i=0;i<ui->NumSecGroups;i++)
{
if(ui->SecGroups[i]==gi->gid)
return(0);
}
}
#endif
/* sorry for this goto :-) */
go_on:
{
static char *text=NULL;
char puf[SMLBUF]="\n",*found;
ADVISE("checkuid: seaching user '%s' in '%s' ",name,checkuserfile);
if(!text)
{
FILE *fp=NULL;
size_t pos;
fp=fopen(checkuserfile,"r");
if(!fp)
{
ADVISE("checkuid: checkuser file open('%s') failed\n",checkuserfile);
return(-1);
}
fseek(fp,0,SEEK_END);
pos=ftell(fp);
if(pos<1)
{
ADVISE("checkuid: checkuser file is ('%s') empty\n", checkuserfile);
return(-1);
}
fseek(fp,0,SEEK_SET);
text=malloc(pos*sizeof(char));
if(!text)
{
ADVISE("checkuid: unable to alloc %d bytes\n", pos);
return(-1);
}
fread(text,pos,1,fp);
fclose(fp);
/* case insensitiv, please */
strlwr(text);
}
strcat(puf,name);
strcat(puf,"\n");
/* case insensitiv for pattern too, please */
strlwr(puf);
if(strstr(text,puf))
{
ADVISE("found\n");
return(0);
}
/* if the file starts with this user there is no \n at the begin */
strcpy(puf,name);
strcat(puf,"\n");
found=strstr(text,puf);
if(found==text)
{
ADVISE("found\n");
return(0);
}
ADVISE("not found\n");
return(1);
}
}
/*
* set_programtype(): setup the global buffer prgtype_string
*
*/
void set_programtype(void)
{
#ifdef MUFS
strcpy(prgtype_string,"MUFS");
#endif
#ifdef AXSH
strcpy(prgtype_string,"AXSh");
#endif
#if !defined(MUFS) && !defined(AXSH)
strcpy(prgtype_string,"Getty");
#endif
}
/*
* getuid(): return the userid of the actual login user
*
* return: userid
*
*/
int getuid(void)
{
UBYTE *str;
struct passwd *pwd;
str=getloginname();
if(!str)
return(0);
pwd=getpwnam(str);
if(!pwd)
return(0);
return(pwd->pw_uid);
}
/*
* getgid(): return the user groupid of the actual login user
*
* return: usergid
*
*/
int getgid(void)
{
UBYTE *str;
struct passwd *pwd;
str=getloginname();
if(!str)
return(0);
pwd=getpwnam(str);
if(!pwd)
return(0);
return(pwd->pw_gid);
}
/*
* getpid(): get the actual Process Id
*
*/
long getpid(void)
{
struct Process *proc;
Forbid();
proc=(struct Process *)FindTask(NULL);
Permit();
if(proc)return(proc->pr_TaskNum);
return(0);
}
/*
* getloginname(): return the user name of the actual login user
*
* return: user name
*
*/
char *getloginname(void)
{
static UBYTE buffer[SMLBUF];
char *str;
#ifdef MUFS
str=_getloginname();
if(str)
{
return((char *)str);
}
#endif
if(GetVar("USER",buffer,128,GVF_LOCAL_ONLY)!=-1)
return((char *)buffer);
str=findconfig("UserName");
if(str)
{
strcpy(buffer,str);
return((char *)buffer);
}
DEBUG( "getloginname: Couldn't find your login name\n");
return(NULL);
}
/*
* uncomment(): removes comments brackets
*
* params: line to remove brackets
*
*/
static
void
uncomment(char *p)
{
char *b;
while((p = index(p, '(')) != NULL) {
strcpy(p,p+1);
b=p;
if((p = index(p, ')')) != NULL) {/* look for close paren */
(void) strcpy(p, p+1);
} else {
*b = '\0'; /* no paren, skip rest of line */
break;
}
}
}
/*
* getrealname(): get the real name
*
* params: user name
*
*/
char *getrealname(char *user)
{
static UBYTE buffer[128];
struct passwd *pwd;
char *str;
if(user)
{
pwd=getpwnam(user);
if(pwd)
{
str=pwd->pw_gecos;
uncomment(str);
return((char *)pwd->pw_gecos);
}
}
if(GetVar("REALNAME",buffer,128,GVF_LOCAL_ONLY)!=-1)
return((char *)buffer);
str=getloginname();
if(str)
{
pwd=getpwnam(str);
if(pwd)
{
str=pwd->pw_gecos;
uncomment(str);
return((char *)pwd->pw_gecos);
}
}
str=findconfig("RealName");
if(str)
{
strcpy(buffer,str);
return((char *)buffer);
}
DEBUG("getrealname: Couldn't find '%s' realname\n",user);
return(NULL);
}
/*
* gethostname(): get the host name
*
* params: hostname buffer and length
*
*/
void gethostname(char hostname[],size_t len)
{
char *str;
hostname[0]='\0';
str=findconfig("NodeName");
if(str)
{
strcpy(hostname,str);
return;
}
if(GetVar("HOSTNAME",hostname,len,NULL)!=-1)
return;
if(GetVar("HOST",hostname,len,NULL)!=-1)
return;
DEBUG("gethostname: Warning!!! Couldn't find your host name\n");
}
/*
* getdomainname(): get the domain name
*
* params: domainname buffer and length
*
*/
void getdomainname(char name[],size_t len)
{
char *str;
name[0]='\0';
str=findconfig("DomainName");
if(str)
{
strcpy(name,str);
return;
}
if(GetVar("DOMAIN",name,len,NULL)!=-1)
return;
DEBUG("getdomainname: Warning!!! Couldn't find your host domain\n");
}
/*
* getsmarthost(): get the name of the smarthost
*
* params: smarthostname buffer and length
*
*/
void getsmarthost(char name[],size_t len)
{
char *str;
name[0]='\0';
str=findconfig("SMSmarthost");
if(str)
{
strcpy(name,str);
return;
}
#ifdef SMARTHOST
strcpy(name,SMARTHOST);
return;
#endif
DEBUG("getsmarthost: Couldn't find your smarthost\n");
}
/*
* get_config(): get a config entry
*
* params: keyword
* 0 - Yes/no
* 1 - Number
* 2 - string
*
*/
char *get_config(char entry[],short art)
{
char *str;
str=findconfig(entry);
switch(art)
{
case 0:
if(str && ((stricmp(str,"YES")==0) || (stricmp(str,"TRUE")==0)))
return("YES");
break;
case 1:
if(str && atoi(str)!=0)
return(str);
break;
case 2:
if(str)
return(str);
break;
}
return(NULL);
}
/*
* sleep(): wait time secs
*
*/
void sleep(unsigned long time)
{
Delay(50L*time);
}
/*
* mktemp(): generate temp file name
*
* params: return buffer for the temp buffer
*
*/
void mktemp(char pattern[])
{
strcpy(pattern,tmpnam(NULL));
}
/*
* my_system(): a stub routine for system()
*
* params: command
* stderrr name
* return: return code
*
*/
int my_system(char *cmd,char *errname)
{
int rc;
struct TagItem ti[2];
ti[0].ti_Tag=NP_StackSize;
ti[0].ti_Data=80000L;
ti[1].ti_Tag=TAG_DONE;
strcat(cmd," >>");
strcat(cmd,errname);
rc=SystemTagList(cmd,ti);
if(rc==0)return(0);
return(rc);
}
/*
* writelog(): write a log entry in Dillon uucp style
*
* params: entries for logfile
*
*/
void
writelog (const char *ctl,...)
{
struct tm *tm;
time_t time_sec;
FILE *fp = NULL;
char logbuf[BIGBUF]="";
va_list args;
va_start (args, ctl);
time (&time_sec);
tm = localtime (&time_sec);
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);
vsprintf (logbuf + strlen (logbuf), ctl, args);
va_end (args);
fp = fopen (logfile, "a");
if(!fp)return;
fputs(logbuf,fp);
fputc('\n',fp);
fclose(fp);
}
/*
* mkfilename(): generate a file name from file and dir path
*
* params: directory and file part
* return: the connectect dir and filepath
*
*/
char *
mkfilename(const char *dir,const char *file)
{
static char buf[BIGBUF];
strcpy(buf,dir);
AddPart(buf,(char *)file,BIGBUF-1);
return(buf);
}
/*
* grep_toline(): grep a line start with pattern replace , with spaces
*
* params: fp - Filepointer
* pattern - Search pattern
*
* return: the rest of the line without \n
*
*/
char *grep_toline(FILE *fp,char *pattern)
{
char line[BIGBUF],*back=NULL,*ptr,*end,*start,*addr;
size_t len;
size_t pos;
size_t count;
if(!fp || !pattern)return(NULL);
len=strlen(pattern);
pos=ftell(fp);
/* test whether the stream is empty (e.g nil:)*/
fseek(fp,0,SEEK_END);
if(ftell(fp)==pos)
{
return(NULL);
}
/* rewind to the begin */
fseek(fp,pos,SEEK_SET);
while(fgets(line,BIGBUF,fp)!=NULL)
if(strncmp(line,pattern,len)==0)
{
end=strchr(line,'\n');
if(end)
*end='\0';
back=strdup(&line[len]);
/* continuation lines */
while(fgets(line,BIGBUF,fp)!=NULL && (line[0]==' ' || line[0]=='\t'))
{
end=strchr(line,'\n');
if(end)
*end='\0';
strins(line,back);
if(back)free(back);
back=strdup(line);
}
/* handle <addr> lines */
for(addr=ptr=back,count=0;*ptr!='\0';ptr++)
{
switch(*ptr)
{
case ',':
addr=ptr+1;
count=0;
break;
case '<':
count++;
if(count==1)start=ptr+1;
break;
case '>':
count--;
if(count==0 && addr && start)
{*ptr=' ';strcpy(addr,start);}
ptr=addr;
break;
}
}
/* removes (Realname) */
for(ptr=back,count=0;*ptr!='\0';ptr++)
switch(*ptr)
{
case ',':
count=0;
break;
case '(':
count++;
if(count==1)start=ptr;
break;
case ')':
count--;
if((count==0) && start)
{
strcpy(start,ptr+1);
ptr=start;
}
break;
}
ptr=back;
while(ptr=index(ptr,','))*ptr=' ';
ptr=back;
while(ptr=index(ptr,'\t'))*ptr=' ';
break;
}
else
if(line[0]=='\n')break;
if(back)
{
BOOL flag;
/* remove all leadings spaces/tabs */
for(ptr=back;*ptr!='\0';ptr++)
if(*ptr==' ' ||
*ptr=='\t')
strcpy(ptr,ptr+1);
/* kill every i.th spaces i>1 */
for(ptr=back,flag=FALSE;*ptr!='\0';ptr++)
if(*ptr==' ')
{
if(!flag)flag=TRUE;
else
{
char *old=ptr;
strcpy(ptr,stpblk(old));
}
}
else
flag=FALSE;
/* remove all spaces on the end */
for(ptr=back+strlen(back)-1;(*ptr==' ' || *ptr=='\t') && (ptr!=back);ptr--);
*(ptr+1)='\0';
}
fseek(fp,pos,SEEK_SET);
return(back);
}
@
1.18
log
@rename getversion() get_programtype() and store the program
type in the global var programtype_string
@
text
@d21 4
a83 1
static char *rcsid="$Id: sysdep.c,v 1.17 1993/11/12 23:05:06 Aussem Exp Aussem $";
d85 1
a85 1
extern int debug;
a86 1
#define CTLZ ('z'&0x1F)
a98 4
#ifdef AXSH
#include "axsh/iomodes.h"
#include "axsh/misc.h"
#include "axsh/users.h"
d100 1
a100 2
static struct User usr;
#endif
d103 7
a109 5
extern char passwdfile[];
extern char logfile[];
extern int checkuser;
char checkuserfile[SMLBUF]="uulib:mail/checkuser";
char prgtype_string[]="UNKNOWN";
d111 1
d114 2
a116 1
d119 9
d151 7
a157 1
* global atexit function
d167 10
a176 4
int setpassent(int p)
{
passwd_pos=p;
}
d178 2
a179 4
int setpwent(void)
{
passwd_pos=0;
}
d181 7
a187 1
#ifdef AXSH
d204 7
d234 8
d266 1
a266 1
#endif
d268 4
a271 120
#if !defined(AXSH) && !defined(MUFS)
struct passwd * getpwent(void)
{
static FILE *fi=NULL;
char *ptr;
char *arg;
char *buf = malloc(256);
static char User[32];
static char Passwd[32];
static char Dir[128];
static char Shell[256];
static char Gecos[256];
static char Comment[256];
static struct passwd Pas = { User, Passwd, 0, 0, 0, Comment, Gecos, Dir, Shell };
if(!fi)
{
fi = fopen(passwdfile, "r");
passwd_pos=0;
}
if (fi == NULL) {
free(buf);
return(NULL);
}
fseek(fi,passwd_pos,0);
do
{
if(fgets(buf, 256, fi)==NULL)
{
free(buf);
fclose(fi);
passwd_pos=0;
fi=NULL;
return(NULL);
}
}while(buf[0]=='#');
passwd_pos=ftell(fi)+1;
ptr=buf;
arg = Breakout(&ptr);
strcpy(Pas.pw_name, arg);
strcpy(Pas.pw_passwd, Breakout(&ptr));
Pas.pw_uid = atoi(Breakout(&ptr));
Pas.pw_gid = atoi(Breakout(&ptr));
strcpy(Pas.pw_gecos,Breakout(&ptr)); /* finger info */
strcpy(Pas.pw_dir, Breakout(&ptr));
strcpy(Pas.pw_shell, Breakout(&ptr));
{
short i = strlen(Pas.pw_dir) - 1;
if (i >= 0 && Pas.pw_dir[i] != ':' && Pas.pw_dir[i] != '/') {
Pas.pw_dir[++i] = '/';
Pas.pw_dir[++i] = 0;
}
}
{
char *str;
Pas.pw_shell_arg0 = Pas.pw_shell;
for (str = Pas.pw_shell; *str && *str != ' ' && *str != 9; ++str);
if (*str) {
*str = 0;
++str;
while (*str == ' ' || *str == 9)
++str;
Pas.pw_shell_argn = str;
} else {
Pas.pw_shell_argn = str;
}
}
free(buf);
return(&Pas);
}
struct passwd *
getpwnam(name)
const char *name;
{
FILE *fi;
char *buf = malloc(256);
static char User[32];
static char Passwd[32];
static char Dir[128];
static char Shell[256];
static char Gecos[256];
static char Comment[256];
static struct passwd Pas = { User, Passwd, 0, 0, 0, Comment, Gecos, Dir, Shell };
fi = fopen(passwdfile, "r");
if (fi == NULL) {
free(buf);
DEBUG("getpwnam: Couldn't open '%s'\n",passwdfile);
return(NULL);
}
while (fgets(buf, 256, fi)) {
char *ptr = buf;
char *arg;
arg = Breakout(&ptr);
if (strcmp(name, arg) != 0)
continue;
strcpy(Pas.pw_name, arg);
strcpy(Pas.pw_passwd, Breakout(&ptr));
Pas.pw_uid = atoi(Breakout(&ptr));
Pas.pw_gid = atoi(Breakout(&ptr));
strcpy(Pas.pw_gecos,Breakout(&ptr)); /* finger info */
strcpy(Pas.pw_dir, Breakout(&ptr));
strcpy(Pas.pw_shell, Breakout(&ptr));
{
short i = strlen(Pas.pw_dir) - 1;
if (i >= 0 && Pas.pw_dir[i] != ':' && Pas.pw_dir[i] != '/') {
Pas.pw_dir[++i] = '/';
Pas.pw_dir[++i] = 0;
}
}
d273 1
a273 27
{
char *str;
Pas.pw_shell_arg0 = Pas.pw_shell;
for (str = Pas.pw_shell; *str && *str != ' ' && *str != 9; ++str);
if (*str) {
*str = 0;
++str;
while (*str == ' ' || *str == 9)
++str;
Pas.pw_shell_argn = str;
} else {
Pas.pw_shell_argn = str;
}
}
fclose(fi);
free(buf);
return(&Pas);
}
free(buf);
fclose(fi);
DEBUG("getpwnam: Couldn't find '%s' in '%s'\n",name,passwdfile);
return(NULL);
}
#endif
#ifdef MUFS
d278 1
d283 1
d287 8
d325 8
d363 7
d399 6
d423 7
d465 4
d489 174
d723 8
a730 1
d834 4
d851 6
d872 6
d893 4
d908 6
d916 1
a916 1
static UBYTE buffer[128];
d939 6
d962 6
d1011 6
d1035 6
d1057 6
d1081 9
d1113 4
d1122 6
d1133 8
d1159 4
a1162 1
* write to uuspool:logfile
d1189 7
d1206 9
@
1.17
log
@checkuid() now uses the checkuser file in MUFS version too
checkuid does not care about case of the users
in checkuser file
@
text
@d21 5
d80 1
a80 1
static char *rcsid="$Id: sysdep.c,v 1.16 1993/11/09 22:42:58 Aussem Exp Aussem $";
d110 1
d712 1
a712 1
char *getversion(void)
d715 1
a715 1
return("MUFS");
d718 4
a721 1
return("AXSh");
a722 1
return("Getty");
@
1.16
log
@Debug msgs unified
user access check implemented
MUFS routines optimizied
@
text
@d21 5
d75 1
a75 1
static char *rcsid="$Id: sysdep.c,v 1.15 1993/11/04 22:46:49 Aussem Exp Aussem $";
d621 1
a621 1
return(-1);
d627 1
a627 1
return(-1);
d634 1
a634 1
return(-1);
d642 2
a643 1
return(-1);
d645 2
a646 2
}
#else
d679 2
d684 2
a703 1
#endif
@
1.15
log
@grep_*() deletes now tabs too
@
text
@d21 3
d70 1
a70 1
static char *rcsid="$Id: sysdep.c,v 1.14 1993/11/02 22:43:42 Aussem Exp Aussem $";
d98 3
d310 1
a310 1
DEBUG("Couldn't open %s\n",passwdfile);
d358 1
a358 1
DEBUG("Couldn't find %s in %s\n",name,passwdfile);
d368 3
a370 2
struct muBase *muBase=NULL;
struct muUserInfo *ui=NULL;
d392 1
a392 1
DEBUG("unable to find Username %s\n",name);
d422 1
a422 1
DEBUG("unable to find UID %d\n",uid);
d450 1
a450 1
DEBUG("unable to find get to next user\n");
a478 2
DEBUG("login:%s\n",pwd->pw_name);
d489 1
a489 1
DEBUG("unable to open %s Version >= %d\n",MULTIUSERNAME,MULTIUSERVERSION);
d503 11
d520 1
d522 7
d530 1
d532 2
d575 1
a575 1
DEBUG("Couldn't open S:UUConfig or UULIB:Config\n");
d598 110
d770 1
a770 1
DEBUG( "Couldn't find your login name\n");
d830 1
a830 1
DEBUG("Couldn't find your realname\n");
d838 1
d841 1
d843 2
d849 1
a849 1
DEBUG("Couldn't find your host name\n");
d856 1
d859 1
d861 2
d865 1
d872 1
d875 1
d877 2
d881 1
d883 1
d925 1
a925 1
ti[0].ti_Data=30000L;
@
1.14
log
@extended MUFS routines
@
text
@d21 3
d67 1
a67 1
static char *rcsid="$Id: sysdep.c,v 1.13 1993/11/02 19:56:34 Aussem Exp Aussem $";
a850 1
d915 5
a919 2
/* remove all leadings spaces */
back=stpblk(back);
d926 1
a926 1
else
d936 1
a936 1
for(ptr=back+strlen(back)-1;(*ptr==' ') && (ptr!=back);ptr--);
@
1.13
log
@MUFS routines added
@
text
@d21 3
d64 1
a64 1
static char *rcsid="$Id: sysdep.c,v 1.12 1993/10/31 21:11:58 Aussem Exp Aussem $";
d395 30
d453 21
a477 1
DEBUG("init base\n");
a487 1
DEBUG("init user\n");
a499 2
DEBUG("close\n");
d570 1
a570 1
UBYTE buffer[128];
d573 2
a574 1
if(GetVar("USER",buffer,128,GVF_LOCAL_ONLY)==-1)
d576 2
a577 1
pwd=getpwnam(buffer);
d585 1
a585 1
UBYTE buffer[128];
d588 2
a589 1
if(GetVar("USER",buffer,128,GVF_LOCAL_ONLY)==-1)
d591 2
a592 1
pwd=getpwnam(buffer);
d614 8
d671 2
a672 1
if(GetVar("USER",buffer,128,GVF_LOCAL_ONLY)!=-1)
d674 1
a674 1
pwd=getpwnam(buffer);
@
1.12
log
@grep_toline() eliminate now really all not needed spaces
@
text
@d21 3
d61 1
a61 1
static char *rcsid="$Id: sysdep.c,v 1.11 1993/10/31 17:50:59 Aussem Exp Aussem $";
d91 1
a93 1
static void uncomment(char *);
d117 11
d202 3
a204 1
#else
d351 106
a698 4
}
void execvp(char *name,char *argv[])
{
@
1.11
log
@if stdin is empty (e.g nil:) smail does not wait anymore
@
text
@d21 3
d58 1
a58 1
static char *rcsid="$Id: sysdep.c,v 1.10 1993/10/24 15:00:22 Aussem Exp Aussem $";
d732 3
d740 5
a744 1
else strcpy(ptr,++ptr);
d748 4
@
1.10
log
@AXSh Version is now included in this file (no sysdep_axsh.c anymore)
@
text
@d21 3
d55 1
a55 1
static char *rcsid="$Id: sysdep.c,v 1.9 1993/09/18 20:23:05 Aussem Exp Aussem $";
d646 10
@
1.9
log
@the cc line can now be parsed from cmdline and from file
@
text
@d21 3
d52 1
a52 1
static char *rcsid="$Id: sysdep.c,v 1.8 1993/09/18 16:47:47 Aussem Exp Aussem $";
d69 8
d118 65
d327 1
@
1.8
log
@insert GNU license text in the header
@
text
@d21 3
d49 1
a49 1
static char *rcsid="$Id: sysdep.c,v 1.7 1993/09/16 22:36:48 Aussem Exp Aussem $";
d555 1
a555 1
char *grep_toline(FILE *fp)
d558 1
a558 2
const char to[]="To: ";
const size_t len=strlen(to);
d562 1
a562 1
if(!fp)return(NULL);
d564 1
d566 1
d568 1
a568 1
if(strncmp(line,to,len)==0)
@
1.7
log
@realname elmination in grep_toline() works better now
@
text
@d2 1
a2 1
* sysdep.c
d4 1
a4 1
* System depend routines
d6 14
d21 3
d46 1
a46 1
static char *rcsid="$Id: sysdep.c,v 1.6 1993/09/15 22:22:27 Aussem Exp Aussem $";
@
1.6
log
@grep_toline() <addr> are now recognized
@
text
@d7 3
d29 1
a29 1
static char *rcsid="$Id: sysdep.c,v 1.5 1993/09/15 20:17:42 Aussem Exp Aussem $";
d585 20
d609 1
a609 13
end=back;
while(ptr=index(end,'('))
{
end=index(ptr,')');
if(end)
{
memmove(ptr,end+1,end+1-ptr);
}
else
break;
}
break;
@
1.5
log
@gethostname and getdomain first look in uulib:config and then
in the enviroment variables
@
text
@d7 4
d26 1
a26 1
static char *rcsid="$Id: sysdep.c,v 1.4 1993/09/11 16:27:44 Aussem Exp Aussem $";
d534 1
a534 1
char line[BIGBUF],*back=NULL,*ptr,*end;
d538 1
d561 21
d606 2
d614 1
a614 1
else
@
1.4
log
@getrealname() now works correctly again
@
text
@d7 3
d22 1
a22 1
static char *rcsid="$Id: sysdep.c,v 1.3 1993/09/11 01:41:16 Aussem Exp Aussem $";
d403 3
d410 1
a410 5
str=findconfig("NodeName");
if(str)
strcpy(hostname,str);
else
DEBUG("Couldn't find your host name\n");
a416 2
if(GetVar("DOMAIN",name,len,NULL)!=-1)
return;
d420 2
@
1.3
log
@\t will now be noticed as continuation of the To: line
@
text
@d7 3
d19 1
a19 1
static char *rcsid="$Id: sysdep.c,v 1.2 1993/09/10 01:53:25 Aussem Exp Aussem $";
d40 1
d43 1
d67 10
d92 1
d94 2
d102 1
d109 1
d114 1
a114 1
d337 17
a358 1
void strip_comments(char *);
d365 2
a366 1
strip_comments(pwd->pw_gecos);
d379 2
a380 1
strip_comments(pwd->pw_gecos);
@
1.2
log
@new support for grepping the To: line from mailbody with grep_toline()
@
text
@d7 3
d16 1
a16 1
static char *rcsid="$Id: sysdep.c,v 1.1 1993/09/08 16:27:13 Aussem Exp Aussem $";
d506 2
a507 1
while(fgets(line,BIGBUF,fp)!=NULL && line[0]==' ')
d516 5
a520 1
while(ptr=index(back,','))*ptr=' ';
@
1.1
log
@Initial revision
@
text
@d6 3
a8 1
* $Log$
d10 1
d13 1
a13 1
static char *rcsid="$Id$";
d483 61
@