home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
TELECOM
/
stg_v4.lzh
/
pm_util.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-11
|
2KB
|
161 lines
/*
* postman utility functions
*
* _pm_addr(s) - split address into component parts
* _pm_test(s) - test validity of address (does user/service/system exist?)
*/
#include "stglib.h"
#include "pm_util.h"
#include "pwd.h"
/* calling process must define hostname */
extern char hostname[];
/* fields used for _pm_addr() */
char A_care[PM_CARE_LEN];
char A_user[PM_NAME_LEN];
char A_host[PM_NAME_LEN];
/* create temporary name from time/pid combination (8 chars of a-z,a-z/0-9) */
_pm_temp(s)
char *s;
{
long lTime;
int i,d,p;
sleep(1);
time(&lTime);
#define AZ(x) (x>=10?x-10+'a':x+'0')
/* first six chars from lTime */
i=6;
s+=6;
while (i--)
{
d=lTime%36;
lTime/=36;
*--s=AZ(d);
}
s+=6;
/* next two chars from pid */
p=getpid();
p%=1296;
d=p/36;
*s++=AZ(d);
d=p%36;
*s++=AZ(d);
*s=0;
return(0);
}
/* split given address into fields from form 'care%user@host' */
_pm_addr(s)
char *s;
{
char *pCare,*pUser,*pHost;
int n;
pCare=pUser=s;
pHost=0;
while (*s && *s>' ')
{
if (*s=='%')
pUser=s;
if (*s=='@')
pHost=s;
s++;
}
n=pUser-pCare;
if (!n)
*A_care=0;
else
{
if (n>=PM_CARE_LEN)
return(ERR);
strncpy(A_care,pCare,n);
A_care[n]=0;
pUser++;
}
if (!pHost)
{
n=s-pUser;
if (n>=PM_NAME_LEN)
return(ERR);
strncpy(A_user,pUser,n);
A_user[n]=0;
*A_host=0;
}
else
{
n=pHost-pUser;
if (n>=PM_NAME_LEN)
return(ERR);
strncpy(A_user,pUser,n);
A_user[n]=0;
pHost++;
n=s-pHost;
if (n>=PM_NAME_LEN)
return(ERR);
strncpy(A_host,pHost,n);
A_host[n]=0;
}
return(0);
}
_pm_test(s)
char *s;
{
struct passwd *pw;
struct service *sv;
int uid;
if (_pm_addr(s)==ERR)
return(PM_BADFMT);
if (!*hostname && *A_host)
return(PM_NONODE);
if (*A_host)
{
/* not checking node yet */
/* return(PM_NONODE);*/
return(0);
}
pw=getpwnam(A_user);
if (!pw)
return(PM_NOUSER);
/* don't check for existance of user's dir for service */
if (*pw->pw_shell=='!')
return(0);
if (!pw->pw_dir || *pw->pw_dir!='/')
return(PM_NOMAIL);
uid=getuid();
setuid(0);
#ifdef _OS9
if (access(pw->pw_dir,O_DIR|O_RDWR)==ERR)
#else
if (access(pw->pw_dir,R_OK)==ERR)
#endif
{
setuid(uid);
return(PM_NOMAIL);
}
setuid(uid);
return(0);
}