/* access.c */ /* * System Access Utilities */ #include #include #include "access.h" #include "usrblk.h" #include "tsxutl.h" #include "rtfile.h" extern struct userblock user; /* username / password block */ static int ac_dnest = SUBDNEST; /* maximum nesting of subdirectories */ static int ac_dbase = SUBDBASE; /* first 'ld' unit */ static int ac_dlevl = 0; /* subdirectory level */ static char ac_dev[6] = { 'd', 'k', ':', 0, 0, 0 }; static char phydev[6] = { 'd', 'k', ':', 0, 0, 0 }; static char ac_nam[8][8]; static char ac_ext[8][4]; static char ac_fil[16]; static char ac_slash = '\\'; static char userpaths[13][106]; /* space for fully expanded user */ /* directory / file specifications */ int ac_priv; /* current priveleges */ /* * faccess */ int faccess(pst,rights) char *pst; int rights; { return(access(pst,rights,0)); } /* * daccess */ int daccess(pst,rights) char *pst; int rights; { return(access(pst,rights,1)); } /* * access * * If the password requirement is set then set the path * and verify that the directory / file may be accessed as * defined in the users userblock structure. */ int access(pst,rights,df) char *pst; int rights,df; { char path[200]; /* * Clear Privileges */ ac_priv = 0; /* * Check for password bypass (implies full access) */ if(!pswdreqd) { ac_priv = ALL_PRIV; return(1); } /* * Get the current path and parse it */ getpath(path); if(ac_lgcdsk(path,1)) return(0); /* * Now parse the incoming specification */ if(ac_lgcdsk(pst,df)) return(0); /* * Get the full path with file */ ac_path(path); /* * Check User directories */ if(chkpath(path,rights)) { return(1); } else { sprintf(errstr, "Insufficient privilege for requested operation"); return(0); } } /* * chkpath * * Compare the path to each of the userblock directory * entries beginning with the access directories and * ending with the default directory. * * If an entry matches the path then the entries access rights * are compared to the requested operation returning a (1) * if the operation is permitted or a (0) if not. * * If no matching entries are found and the DIRUNRESTRICTED flag * is set then the operation is permitted otherwise the operation * is not permitted. */ static int chkpath(path,rights) char *path; int rights; { int i; /* * Check Directory entries */ for(i=0; i= ac_dnest) { sprintf(errstr, /* */ "Subdirectory nesting may not exceed %d", ac_dnest); /* */ return(1); } /* * Generate a complete file spec * from the two filespec strings. */ sprintf(tm2,"%s.dsk", ac_dev); rtparse(rtfile(tm1,tm2)); /* * Update directory tree */ sprintf(ac_dev,"ld%1d:", ac_dlevl+ac_dbase); strcpy(ac_nam[ac_dlevl],rtname()); strcpy(ac_ext[ac_dlevl],rtext()); /* * Update subdirectory level */ ac_dlevl += 1; } /* * Assume the trailing non bracketed * string is a file name */ strncpy(ac_fil,s,16); ac_fil[15] = '\0'; return(0); } /* * Test the Device Specification and Set the Default Directory */ static int ac_tstdev(st) register char *st; { char t[6]; register char *q; register int i; for(i=0,q=t; *st && i<4; i++,q++,st++) *q = tolower(*st); *q = '\0'; q = strchr(t,':'); if(q==NULL || q==t || (q-t)>3) { return(1); } *(++q) = '\0'; sprintf(ac_dev,"%s",t); sprintf(phydev,"%s",t); return(0); } /* * Expand full path with extensions */ static char *ac_path(st) char *st; { char s[12]; int i; sprintf(st,"%s", phydev); for(i=0; i