static char sccsid
[] = "@(#)chkpth.c 5.5 (Berkeley) %G%";
struct userpath
*Uhead
= NULL
;
struct userpath
*Mchdef
= NULL
, *Logdef
= NULL
;
* this routine will check the path table for the
* machine or log name (non-null parameter) to see if the
* input path (path) starts with an acceptable prefix.
chkpth(logname
, mchname
, path
)
char *path
, *logname
, *mchname
;
register struct userpath
*u
;
/* Allow only rooted pathnames. Security wish. rti!trt */
DEBUG(4, "filename doesn't begin with /\n", CNULL
);
syslog(LOG_ERR
, "USERFILE empty!");
for (u
= Uhead
; u
!= NULL
; ) {
if (*logname
!= '\0' && strcmp(logname
, u
->us_lname
) == SAME
)
if (*mchname
!= '\0' && strncmp(mchname
, u
->us_mname
, MAXBASENAME
) == SAME
)
/* check for /../ in path name */
for (s
= path
; *s
!= '\0'; s
++) {
DEBUG(4, "filename has /../ in it\n", CNULL
);
/* Check for access permission */
for (p
= u
->us_path
; *p
!= NULL
; p
++)
DEBUG(4, "filename not in list\n", CNULL
);
/* path name not valid */
* rdpth - this routine will read the USERFILE and
* construct the userpath structure pointed to by (u);
char buf
[100 + 1], *pbuf
[50 + 1];
register struct userpath
*u
;
if ((uf
= fopen(USERFILE
, "r")) == NULL
) {
while (cfgets(buf
, sizeof(buf
), uf
) != NULL
) {
u
= (struct userpath
*)malloc(sizeof (struct userpath
));
DEBUG (1, "*** Userpath malloc failed\n", 0);
if ((pc
= calloc((unsigned)strlen(buf
) + 1, sizeof (char)))
/* can not allocate space */
DEBUG (1, "Userpath calloc 1 failed\n", 0);
nargs
= getargs(pc
, pbuf
, 50);
pc
= index(u
->us_lname
, ',');
pc
= u
->us_lname
+ strlen(u
->us_lname
);
if (strlen(u
->us_mname
) > MAXBASENAME
)
u
->us_mname
[MAXBASENAME
] = '\0';
if (*u
->us_lname
== '\0' && Logdef
== NULL
)
if (*u
->us_mname
== '\0' && Mchdef
== NULL
)
if (strcmp(pbuf
[1], "c") == SAME
) {
cp
= (char **)calloc((unsigned)(nargs
-i
+1), sizeof(char *));
/* can not allocate space */
DEBUG (1, "Userpath calloc 2 failed!\n", 0);
* callback(name) check for callback
register struct userpath
*u
;
syslog(LOG_ERR
, "USERFILE empty!");
for (u
= Uhead
; u
!= NULL
; ) {
if (strcmp(u
->us_lname
, name
) == SAME
)
* chkperm(file, mopt) check write permission of file
* char *mopt; none NULL - create directories
* if mopt != NULL and permissions are ok,
* a side effect of this routine is to make
* directories up to the last part of the
* filename (if they do not exist).
if (stat(subfile(file
), &s
) == 0) {
if ((s
.st_mode
& ANYWRITE
) == 0) {
DEBUG(4,"file is not writable: mode %o\n", s
.st_mode
);
if ((ret
= stat(subfile(dir
), &s
)) == -1 && mopt
== NULL
) {
DEBUG(4, "can't stat directory %s\n", subfile(dir
));
if ((s
.st_mode
& ANYWRITE
) == 0)
* Check for sufficient privilege to request debugging.
if (access(SYSFILE
, 04) < 0) {
fprintf(stderr
, "Sorry, you must be able to read L.sys for debugging\n");
exit(1); /* Just in case */