Example #1
0
/*
 * Do the dirty work in checking
 */
int
chk(char *file)
{
	int *r, jnum;
	char **u;
	const char *cfhost;
	FILE *cfp;

	/*
	 * Check for valid cf file name (mostly checking current).
	 */
	if (strlen(file) < 7 || file[0] != 'c' || file[1] != 'f')
		return(0);

	jnum = calc_jobnum(file, &cfhost);
	if (all && (from_host == local_host || !strcmp(from_host, cfhost)))
		return(1);

	/*
	 * get the owner's name from the control file.
	 */
	seteuid(euid);
	if ((cfp = fopen(file, "r")) == NULL)
		return(0);
	seteuid(uid);
	while (getline(cfp)) {
		if (line[0] == 'P')
			break;
	}
	(void) fclose(cfp);
	if (line[0] != 'P')
		return(0);

	if (users == 0 && requests == 0)
		return(!strcmp(file, current) && isowner(line+1, file, cfhost));
	/*
	 * Check the request list
	 */
	for (r = requ; r < &requ[requests]; r++)
		if (*r == jnum && isowner(line+1, file, cfhost))
			return(1);
	/*
	 * Check to see if it's in the user list
	 */
	for (u = user; u < &user[users]; u++)
		if (!strcmp(*u, line+1) && isowner(line+1, file, cfhost))
			return(1);
	return(0);
}
Example #2
0
int
inlist(char *uname, char *cfile)
{
	int *r, jnum;
	char **u;
	const char *cfhost;

	if (users == 0 && requests == 0)
		return(1);
	/*
	 * Check to see if it's in the user list
	 */
	for (u = user; u < &user[users]; u++)
		if (!strcmp(*u, uname))
			return(1);
	/*
	 * Check the request list
	 */
	jnum = calc_jobnum(cfile, &cfhost);
	for (r = requ; r < &requ[requests]; r++)
		if (*r == jnum && !strcmp(cfhost, from_host))
			return(1);
	return(0);
}
Example #3
0
void
inform(const struct printer *pp, char *cf)
{
	int copycnt, jnum;
	char	 savedname[MAXPATHLEN+1];
	FILE	*cfp;

	/*
	 * There's a chance the control file has gone away
	 * in the meantime; if this is the case just keep going
	 */
	PRIV_START
	if ((cfp = fopen(cf, "r")) == NULL)
		return;
	PRIV_END

	if (rank < 0)
		rank = 0;
	if (pp->remote || garbage || strcmp(cf, current))
		rank++;

	/*
	 * The cf-file may include commands to print more than one datafile
	 * from the user.  For each datafile, the cf-file contains at least
	 * one line which starts with some format-specifier ('a'-'z'), and
	 * a second line ('N'ame) which indicates the original name the user
	 * specified for that file.  There can be multiple format-spec lines
	 * for a single Name-line, if the user requested multiple copies of
	 * that file.  Standard lpr puts the format-spec line(s) before the
	 * Name-line, while lprNG puts the Name-line before the format-spec
	 * line(s).  This section needs to handle the lines in either order.
	 */
	copycnt = 0;
	file[0] = '\0';
	savedname[0] = '\0';
	jnum = calc_jobnum(cf, NULL);
	while (getline(cfp)) {
		switch (line[0]) {
		case 'P': /* Was this file specified in the user's list? */
			if (!inlist(line+1, cf)) {
				fclose(cfp);
				return;
			}
			if (lflag) {
				printf("\n%s: ", line+1);
				col = strlen(line+1) + 2;
				prank(rank);
				blankfill(JOBCOL);
				printf(" [job %s]\n", cf+3);
			} else {
				col = 0;
				prank(rank);
				blankfill(OWNCOL);
				printf("%-10s %-3d  ", line+1, jnum);
				col += 16;
				first = 1;
			}
			continue;
		default: /* some format specifer and file name? */
			if (line[0] < 'a' || line[0] > 'z')
				break;
			if (copycnt == 0 || strcmp(file, line+1) != 0) {
				strlcpy(file, line + 1, sizeof(file));
			}
			copycnt++;
			/*
			 * deliberately 'continue' to another getline(), so
			 * all format-spec lines for this datafile are read
			 * in and counted before calling show()
			 */
			continue;
		case 'N':
			strlcpy(savedname, line + 1, sizeof(savedname));
			break;
		}
		if ((file[0] != '\0') && (savedname[0] != '\0')) {
			show(savedname, file, copycnt);
			copycnt = 0;
			file[0] = '\0';
			savedname[0] = '\0';
		}
	}
	fclose(cfp);
	/* check for a file which hasn't been shown yet */
	if (file[0] != '\0') {
		if (savedname[0] == '\0') {
			/* a safeguard in case the N-ame line is missing */
			strlcpy(savedname, file, sizeof(savedname));
		}
		show(savedname, file, copycnt);
	}
	if (!lflag) {
		blankfill(SIZCOL);
		printf("%ld bytes\n", totsize);
		totsize = 0;
	}
}