xref: /illumos-gate/usr/src/cmd/bnu/grades.c (revision d67944fb)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*d67944fbSScott Rotondo  * Common Development and Distribution License (the "License").
6*d67944fbSScott Rotondo  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
227c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate /*
25*d67944fbSScott Rotondo  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
26*d67944fbSScott Rotondo  * Use is subject to license terms.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include "uucp.h"
307c478bd9Sstevel@tonic-gate #include <grp.h>
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #define G_EXT	0
337c478bd9Sstevel@tonic-gate #define	G_INT	1
347c478bd9Sstevel@tonic-gate #define	G_RES	2
357c478bd9Sstevel@tonic-gate #define	G_ACT	3
367c478bd9Sstevel@tonic-gate #define	G_IDF	4
377c478bd9Sstevel@tonic-gate #define	G_MAX	512	/* max number of fields in the Grades file line */
387c478bd9Sstevel@tonic-gate #define	SMBUF	128
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #define	TYPE	0
417c478bd9Sstevel@tonic-gate #define FILE1	1
427c478bd9Sstevel@tonic-gate #define	FILE2	2
437c478bd9Sstevel@tonic-gate #define	USER	3
447c478bd9Sstevel@tonic-gate #define	OPTS	4
457c478bd9Sstevel@tonic-gate #define	FILE3	5
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate extern int rdfulline(), jsize(), gdirf(), gnamef();
487c478bd9Sstevel@tonic-gate extern void wfcommit();
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate static void	mailAdmin();		/* Send mail to administrator. */
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate  * chkgrp - checks to see the group has permission
547c478bd9Sstevel@tonic-gate  *		to use a service grade queue.
557c478bd9Sstevel@tonic-gate  *
567c478bd9Sstevel@tonic-gate  * returns
577c478bd9Sstevel@tonic-gate  *
587c478bd9Sstevel@tonic-gate  *	SUCCESS - if the group has permissions
597c478bd9Sstevel@tonic-gate  *	FAIL - if group does not
607c478bd9Sstevel@tonic-gate  *
617c478bd9Sstevel@tonic-gate  */
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate static int
chkgrp(carray,na)647c478bd9Sstevel@tonic-gate chkgrp(carray,na)
657c478bd9Sstevel@tonic-gate char **carray;
667c478bd9Sstevel@tonic-gate int na;
677c478bd9Sstevel@tonic-gate {
687c478bd9Sstevel@tonic-gate 	struct group *grp;
697c478bd9Sstevel@tonic-gate 	int i;
707c478bd9Sstevel@tonic-gate 	gid_t gid;
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 	gid = getgid();
737c478bd9Sstevel@tonic-gate 	grp = getgrgid(gid);
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate 	for (i = G_IDF; i < na; i++)
767c478bd9Sstevel@tonic-gate 			if (EQUALS(carray[i], grp->gr_name))
777c478bd9Sstevel@tonic-gate 				return(SUCCESS);
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 	return(FAIL);
807c478bd9Sstevel@tonic-gate }
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /*
837c478bd9Sstevel@tonic-gate  * chkusr - checks the permission fields of the Grades file
847c478bd9Sstevel@tonic-gate  *	    to determine if the user can queue to a particular service grade.
857c478bd9Sstevel@tonic-gate  *
867c478bd9Sstevel@tonic-gate  * returns
877c478bd9Sstevel@tonic-gate  *
887c478bd9Sstevel@tonic-gate  *	SUCCESS - if the user can queue to the service grade.
897c478bd9Sstevel@tonic-gate  *	FAIL - if the user can not queue to this service grade.
907c478bd9Sstevel@tonic-gate  *
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate static int
chkusr(carray,na)947c478bd9Sstevel@tonic-gate chkusr(carray, na)
957c478bd9Sstevel@tonic-gate char **carray;
967c478bd9Sstevel@tonic-gate int na;
977c478bd9Sstevel@tonic-gate {
987c478bd9Sstevel@tonic-gate 	int i;
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	/*
1017c478bd9Sstevel@tonic-gate 	 * start at the point where the users are supposed to be in the
1027c478bd9Sstevel@tonic-gate 	 * Grades file. Loop thru until the end of the user list is
1037c478bd9Sstevel@tonic-gate 	 * found or the user name is found. If the user name is found then
1047c478bd9Sstevel@tonic-gate 	 * return TRUE. If the end of the list is found, return FAIL.
1057c478bd9Sstevel@tonic-gate 	 */
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 	DEBUG(9, "User (%s)\n", User);
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 	/* check for any user and return if so */
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 	if (EQUALS(carray[G_IDF], "Any"))
1127c478bd9Sstevel@tonic-gate 		return(SUCCESS);
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 	DEBUG(9, "Members of administrator defined service grade (%s)\n", carray[G_EXT]);
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	for (i = G_IDF; i < na; i++) {
1177c478bd9Sstevel@tonic-gate 		DEBUG(9, "%s\n", carray[i]);
1187c478bd9Sstevel@tonic-gate 		if (EQUALS(User, carray[i]))
1197c478bd9Sstevel@tonic-gate 			return(SUCCESS);
1207c478bd9Sstevel@tonic-gate 	}
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 	return(FAIL);
1237c478bd9Sstevel@tonic-gate }
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate /*
1267c478bd9Sstevel@tonic-gate  *	fgrade - finds the appropiate queue to queue a job into
1277c478bd9Sstevel@tonic-gate  *
1287c478bd9Sstevel@tonic-gate  *	returns
1297c478bd9Sstevel@tonic-gate  *		SUCCESS	-> found a queue
1307c478bd9Sstevel@tonic-gate  *		FAIL	-> can't find a queue
1317c478bd9Sstevel@tonic-gate  */
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate int
fgrade(scfile)1347c478bd9Sstevel@tonic-gate fgrade(scfile)
1357c478bd9Sstevel@tonic-gate struct cs_struct *scfile;
1367c478bd9Sstevel@tonic-gate {
1377c478bd9Sstevel@tonic-gate 	char fdgrade();
1387c478bd9Sstevel@tonic-gate 	FILE *cfd;
1397c478bd9Sstevel@tonic-gate 	char line[BUFSIZ];
1407c478bd9Sstevel@tonic-gate 	char *carray[G_MAX];
1417c478bd9Sstevel@tonic-gate 	long climit;
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 	/* Check for the default service grade first */
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 	if (strcmp(scfile->sgrade, "default") == 0) {
1467c478bd9Sstevel@tonic-gate 		scfile->grade = fdgrade();
1477c478bd9Sstevel@tonic-gate 		return(SUCCESS);
1487c478bd9Sstevel@tonic-gate 	}
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 	/* open grades file to begin a linear for the grade requested */
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 	cfd = fopen(GRADES, "r");
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	/* loop until the file is empty or we find the grade we want */
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 	while (rdfulline(cfd, line, BUFSIZ) != 0) {
1577c478bd9Sstevel@tonic-gate 		(void) getargs(line, carray, G_MAX);
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 		/* check to see if this is the grade we want */
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 		if (!EQUALS(scfile->sgrade, carray[G_EXT]))
1627c478bd9Sstevel@tonic-gate 			continue;
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 		if (jsize(scfile, carray[G_RES], &climit) != FAIL) {
1657c478bd9Sstevel@tonic-gate 			(void) fclose(cfd);
1667c478bd9Sstevel@tonic-gate 			scfile->grade = *carray[G_INT];
1677c478bd9Sstevel@tonic-gate 			return(SUCCESS);
1687c478bd9Sstevel@tonic-gate 		}
1697c478bd9Sstevel@tonic-gate 	}
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 	(void) fclose(cfd);
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("Job size (%ld bytes)"
1747c478bd9Sstevel@tonic-gate 	    " exceeds maximum number of bytes (%ld bytes)"
1757c478bd9Sstevel@tonic-gate 	    " allowed into this service grade (%s).\n"
1767c478bd9Sstevel@tonic-gate 	    "Job queued to default grade.\n"),
1777c478bd9Sstevel@tonic-gate 	    scfile->jsize, climit, scfile->sgrade);
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 	scfile->grade = fdgrade();
1807c478bd9Sstevel@tonic-gate 	return(SUCCESS);
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate /*
1847c478bd9Sstevel@tonic-gate  *	fdgrade - finds the default queue for this system
1857c478bd9Sstevel@tonic-gate  *
1867c478bd9Sstevel@tonic-gate  *	returns
1877c478bd9Sstevel@tonic-gate  *		a one char name for the default queue
1887c478bd9Sstevel@tonic-gate  *
1897c478bd9Sstevel@tonic-gate  */
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate char
fdgrade()1927c478bd9Sstevel@tonic-gate fdgrade()
1937c478bd9Sstevel@tonic-gate {
1947c478bd9Sstevel@tonic-gate 	FILE *cfd;
1957c478bd9Sstevel@tonic-gate 	char line[BUFSIZ];
1967c478bd9Sstevel@tonic-gate 	char *carray[G_MAX];
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 	/* Check for the default grade first */
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 		cfd = fopen(GRADES, "r");
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 		/* loop until the end of the file is read */
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate 		for (; rdfulline(cfd, line, BUFSIZ) != 0;) {
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 			/* parse the fields of this line */
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 			(void) getargs(line, carray, G_MAX);
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 			/* check to see if the administrator has defined
2117c478bd9Sstevel@tonic-gate 			 * a default grade for the machine.
2127c478bd9Sstevel@tonic-gate 			 */
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate 			if (strcmp(carray[G_EXT], "default") != 0)
2157c478bd9Sstevel@tonic-gate 				continue;
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate 			/* default must be defined in the file
2187c478bd9Sstevel@tonic-gate 			 *  close the file, get the queue name, and return.
2197c478bd9Sstevel@tonic-gate 			 */
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 			(void) fclose(cfd);
2227c478bd9Sstevel@tonic-gate 			return(*carray[G_INT]);
2237c478bd9Sstevel@tonic-gate 		}
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 		/* no default defined in this file. close file.
2267c478bd9Sstevel@tonic-gate 		 * get our default queue and return.
2277c478bd9Sstevel@tonic-gate 		 */
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 		(void) fclose(cfd);
2307c478bd9Sstevel@tonic-gate 		return(D_QUEUE);
2317c478bd9Sstevel@tonic-gate }
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate /*
2347c478bd9Sstevel@tonic-gate  * job_size - determines the size of a job
2357c478bd9Sstevel@tonic-gate  *
2367c478bd9Sstevel@tonic-gate  * returns
2377c478bd9Sstevel@tonic-gate  *
2387c478bd9Sstevel@tonic-gate  *	SUCCESS - if the size of the job can be determined
2397c478bd9Sstevel@tonic-gate  *	FAIL	- otherwise
2407c478bd9Sstevel@tonic-gate  */
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate int
job_size(scfile)2437c478bd9Sstevel@tonic-gate job_size(scfile)
2447c478bd9Sstevel@tonic-gate struct cs_struct *scfile;
2457c478bd9Sstevel@tonic-gate {
2467c478bd9Sstevel@tonic-gate 	extern int Dfileused;
2477c478bd9Sstevel@tonic-gate 	struct stat s;
2487c478bd9Sstevel@tonic-gate 	FILE *fp;
2497c478bd9Sstevel@tonic-gate 	char line[BUFSIZ];
2507c478bd9Sstevel@tonic-gate 	char *carray[G_MAX];
2517c478bd9Sstevel@tonic-gate 	int na;
2527c478bd9Sstevel@tonic-gate 	int nodfile = FALSE;
2537c478bd9Sstevel@tonic-gate 	int ret;
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 	scfile->jsize = 0;
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 	fp = fopen(scfile->file, "r");
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	if (fp == NULL) {
2607c478bd9Sstevel@tonic-gate 		toCorrupt(scfile->file);
2617c478bd9Sstevel@tonic-gate 		errent(Ct_OPEN, scfile->file, errno, __FILE__,  __LINE__);
2627c478bd9Sstevel@tonic-gate 	}
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 	while (fgets(line, BUFSIZ, fp) != NULL) {
2657c478bd9Sstevel@tonic-gate 		na = getargs(line, carray, G_MAX);
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 		if (na < 6) {
2687c478bd9Sstevel@tonic-gate 			(void) fclose(fp);
2697c478bd9Sstevel@tonic-gate 			toCorrupt(scfile->file);
2707c478bd9Sstevel@tonic-gate 			errent("BAD NUMBER OF ARGUMENTS", scfile->file, 0,
2717c478bd9Sstevel@tonic-gate 				__FILE__, __LINE__);
2727c478bd9Sstevel@tonic-gate 		}
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 		/* if the type of a transfer is not a push
2757c478bd9Sstevel@tonic-gate 		 * then don't try to determine the size of
2767c478bd9Sstevel@tonic-gate 		 * the data file, because you can't.
2777c478bd9Sstevel@tonic-gate 		 */
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 		if (*carray[TYPE] == 'R')
2807c478bd9Sstevel@tonic-gate 			continue;
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 		/* find the data dile that is to be transferred */
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 		if ((ret = stat(carray[FILE3], &s)) != 0) {
2857c478bd9Sstevel@tonic-gate 			if (errno == ENOENT) {
2867c478bd9Sstevel@tonic-gate 				nodfile = TRUE;
2877c478bd9Sstevel@tonic-gate 				ret = stat(carray[FILE1], &s);
2887c478bd9Sstevel@tonic-gate 			}
2897c478bd9Sstevel@tonic-gate 		}
2907c478bd9Sstevel@tonic-gate 		else
2917c478bd9Sstevel@tonic-gate 			Dfileused = TRUE;
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate 		/*
2947c478bd9Sstevel@tonic-gate 		 * check to see if the return code from stat was 0
2957c478bd9Sstevel@tonic-gate 		 * if return code was not 0, write message to error
2967c478bd9Sstevel@tonic-gate 		 * log and quit. Otherwise, add size of file to job
2977c478bd9Sstevel@tonic-gate 		 * size and continue looping.
2987c478bd9Sstevel@tonic-gate 		 */
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 		if (ret != 0) {
3017c478bd9Sstevel@tonic-gate 			(void) fclose(fp);
3027c478bd9Sstevel@tonic-gate 			errent(Ct_STAT, nodfile ?
3037c478bd9Sstevel@tonic-gate 				carray[FILE1] : carray[FILE3], errno,
3047c478bd9Sstevel@tonic-gate 				__FILE__, __LINE__);
3057c478bd9Sstevel@tonic-gate 		}
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 		nodfile = FALSE;
3087c478bd9Sstevel@tonic-gate 		scfile->jsize += s.st_size;
3097c478bd9Sstevel@tonic-gate 	}
3107c478bd9Sstevel@tonic-gate 	(void) fclose(fp);
3117c478bd9Sstevel@tonic-gate 	return(SUCCESS);
3127c478bd9Sstevel@tonic-gate }
3137c478bd9Sstevel@tonic-gate 
314*d67944fbSScott Rotondo static void lcase();
315*d67944fbSScott Rotondo 
3167c478bd9Sstevel@tonic-gate /*
3177c478bd9Sstevel@tonic-gate  * jsize - determines whether if a job is small enough to
3187c478bd9Sstevel@tonic-gate  * 	   be placed in the appropiate queue.
3197c478bd9Sstevel@tonic-gate  *
3207c478bd9Sstevel@tonic-gate  * returns
3217c478bd9Sstevel@tonic-gate  *
3227c478bd9Sstevel@tonic-gate  *	SUCCESS - if the size of the job is less than or
3237c478bd9Sstevel@tonic-gate  *		  equal to the number of bytes in the restriction
3247c478bd9Sstevel@tonic-gate  *		  of the GRADES file.
3257c478bd9Sstevel@tonic-gate  *
3267c478bd9Sstevel@tonic-gate  *	FAIL	- otherwise
3277c478bd9Sstevel@tonic-gate  */
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate int
jsize(scfile,climit,nlimit)3307c478bd9Sstevel@tonic-gate jsize(scfile, climit, nlimit)
3317c478bd9Sstevel@tonic-gate struct cs_struct *scfile;
3327c478bd9Sstevel@tonic-gate char *climit;
3337c478bd9Sstevel@tonic-gate long *nlimit;
3347c478bd9Sstevel@tonic-gate {
3357c478bd9Sstevel@tonic-gate #define ONE_K (1024)
3367c478bd9Sstevel@tonic-gate #define ONE_MEG ((1024)*(1024))
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 	char rest[SMBUF];
3397c478bd9Sstevel@tonic-gate 	char msg[BUFSIZ], *p;
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 	if (EQUALS(climit, "Any"))
3427c478bd9Sstevel@tonic-gate 		return(SUCCESS);
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate 	lcase(climit, rest, SMBUF);
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate 	if (!(p = strchr(rest, 'k')) && (!(p = strchr(rest, 'm')))) {
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate 		for(p = climit; *p; ++p) {
3497c478bd9Sstevel@tonic-gate 			if (isdigit(*p))
3507c478bd9Sstevel@tonic-gate 				continue;
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 			/* corrupt restriction field in the Grades file.
3537c478bd9Sstevel@tonic-gate 			 * report it to the uucp administrator.
3547c478bd9Sstevel@tonic-gate 			 */
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate 			snprintf(msg, sizeof (msg),
3577c478bd9Sstevel@tonic-gate 			    gettext("Error encountered in the"
3587c478bd9Sstevel@tonic-gate 			    " restrictions field of the Grades file."
3597c478bd9Sstevel@tonic-gate 			    "  Field contents (%s)."), climit);
3607c478bd9Sstevel@tonic-gate 			mailAdmin(msg);
3617c478bd9Sstevel@tonic-gate 			return(SUCCESS);
3627c478bd9Sstevel@tonic-gate 		}
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate 		*nlimit = atol(climit);
3657c478bd9Sstevel@tonic-gate 	}
3667c478bd9Sstevel@tonic-gate 	else if (*p == 'k') {
3677c478bd9Sstevel@tonic-gate 		*p = '\0';
3687c478bd9Sstevel@tonic-gate 		*nlimit = (long) (atof(rest) * ONE_K);
3697c478bd9Sstevel@tonic-gate 	}
3707c478bd9Sstevel@tonic-gate 	else {
3717c478bd9Sstevel@tonic-gate 		*p = '\0';
3727c478bd9Sstevel@tonic-gate 		*nlimit = (long) (atof(rest) * ONE_MEG);
3737c478bd9Sstevel@tonic-gate 	}
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate 	if (scfile->jsize <= *nlimit)
3767c478bd9Sstevel@tonic-gate 		return(SUCCESS);
3777c478bd9Sstevel@tonic-gate 	else
3787c478bd9Sstevel@tonic-gate 		return(FAIL);
3797c478bd9Sstevel@tonic-gate }
3807c478bd9Sstevel@tonic-gate 
3817c478bd9Sstevel@tonic-gate static void
lcase(s,t,lim)3827c478bd9Sstevel@tonic-gate lcase(s, t, lim)
3837c478bd9Sstevel@tonic-gate char s[], t[];
3847c478bd9Sstevel@tonic-gate int lim;
3857c478bd9Sstevel@tonic-gate {
3867c478bd9Sstevel@tonic-gate 	char *p;
3877c478bd9Sstevel@tonic-gate 	int i;
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate 	p = s;
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate 	for (i = 0; i < lim-1 && *p; i++)
3937c478bd9Sstevel@tonic-gate 		if (isupper(*p))
3947c478bd9Sstevel@tonic-gate 			t[i] = tolower(*p++);
3957c478bd9Sstevel@tonic-gate 		else
3967c478bd9Sstevel@tonic-gate 			t[i] = *p++;
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate 	t[i] = '\0';
3997c478bd9Sstevel@tonic-gate 	return;
4007c478bd9Sstevel@tonic-gate }
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate /*
4037c478bd9Sstevel@tonic-gate  * mailAdmin - mail a message to the uucp administrator.
4047c478bd9Sstevel@tonic-gate  *
4057c478bd9Sstevel@tonic-gate  * returns:
4067c478bd9Sstevel@tonic-gate  *
4077c478bd9Sstevel@tonic-gate  *	nothing
4087c478bd9Sstevel@tonic-gate  */
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate static void
mailAdmin(msg)4117c478bd9Sstevel@tonic-gate mailAdmin (msg)
4127c478bd9Sstevel@tonic-gate 
4137c478bd9Sstevel@tonic-gate char *	msg;
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate {
4167c478bd9Sstevel@tonic-gate 	char	cmd[BUFSIZ];		/* Place to build mail command. */
4177c478bd9Sstevel@tonic-gate 	FILE *	mail;			/* Channel to write mail on. */
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate 	(void) sprintf(cmd, "%s %s %s", PATH, MAIL, "uucp");
4207c478bd9Sstevel@tonic-gate 	if ((mail = popen(cmd, "w")) != (FILE *) NULL)
4217c478bd9Sstevel@tonic-gate 	{
4227c478bd9Sstevel@tonic-gate 		(void) fprintf(mail, "To: uucp\nSubject: %s\n\n%s\n",
4237c478bd9Sstevel@tonic-gate 		    gettext("Grades file problem"), msg);
4247c478bd9Sstevel@tonic-gate 		(void) pclose(mail);
4257c478bd9Sstevel@tonic-gate 	}
4267c478bd9Sstevel@tonic-gate 
4277c478bd9Sstevel@tonic-gate 	/*
4287c478bd9Sstevel@tonic-gate 	 * Ignore popen failure.  There is not much that we can do if
4297c478bd9Sstevel@tonic-gate 	 * it fails, since we are already trying to notify the administrator
4307c478bd9Sstevel@tonic-gate 	 * of a problem.
4317c478bd9Sstevel@tonic-gate 	 */
4327c478bd9Sstevel@tonic-gate 	return;
4337c478bd9Sstevel@tonic-gate }
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate /*
4367c478bd9Sstevel@tonic-gate  * putdfiles - moves any and all of the D. to the spool directory for
4377c478bd9Sstevel@tonic-gate  * 	       a C. file.
4387c478bd9Sstevel@tonic-gate  *
4397c478bd9Sstevel@tonic-gate  * returns
4407c478bd9Sstevel@tonic-gate  *
4417c478bd9Sstevel@tonic-gate  *	nothing
4427c478bd9Sstevel@tonic-gate  */
4437c478bd9Sstevel@tonic-gate 
4447c478bd9Sstevel@tonic-gate void
putdfiles(scfile)4457c478bd9Sstevel@tonic-gate putdfiles(scfile)
4467c478bd9Sstevel@tonic-gate struct cs_struct scfile;
4477c478bd9Sstevel@tonic-gate {
4487c478bd9Sstevel@tonic-gate 	FILE *fp;
4497c478bd9Sstevel@tonic-gate 	char line[BUFSIZ];
4507c478bd9Sstevel@tonic-gate 	char *carray[G_MAX];
4517c478bd9Sstevel@tonic-gate 	int na;
4527c478bd9Sstevel@tonic-gate 	struct stat s;
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate 	fp = fopen(scfile.file, "r");
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate 	if (fp == NULL) {
4577c478bd9Sstevel@tonic-gate 		toCorrupt(scfile.file);
4587c478bd9Sstevel@tonic-gate 		errent(Ct_OPEN, scfile.file, errno, __FILE__, __LINE__);
4597c478bd9Sstevel@tonic-gate 	}
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate 	while (fgets(line, BUFSIZ, fp) != NULL) {
4627c478bd9Sstevel@tonic-gate 
4637c478bd9Sstevel@tonic-gate 		na = getargs(line, carray, G_MAX);
4647c478bd9Sstevel@tonic-gate 		if (na < 6) {
4657c478bd9Sstevel@tonic-gate 			(void) fclose(fp);
4667c478bd9Sstevel@tonic-gate 			toCorrupt(scfile.file);
4677c478bd9Sstevel@tonic-gate 			errent("BAD NUMBER OF ARGUMENTS", scfile.file, 0,
4687c478bd9Sstevel@tonic-gate 				__FILE__, __LINE__);
4697c478bd9Sstevel@tonic-gate 		}
4707c478bd9Sstevel@tonic-gate 
4717c478bd9Sstevel@tonic-gate 		if (*carray[TYPE] == 'R')
4727c478bd9Sstevel@tonic-gate 			continue;
4737c478bd9Sstevel@tonic-gate 
4747c478bd9Sstevel@tonic-gate 	    	/* move D. file to the spool area */
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate 		if (stat(carray[FILE3], &s) != -1)
4777c478bd9Sstevel@tonic-gate 			wfcommit(carray[FILE3], carray[FILE3], scfile.sys);
4787c478bd9Sstevel@tonic-gate 	}
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate 	(void) fclose(fp);
4817c478bd9Sstevel@tonic-gate 	return;
4827c478bd9Sstevel@tonic-gate }
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate /*
4857c478bd9Sstevel@tonic-gate  * reads a line from a file and takes care of comment lines
4867c478bd9Sstevel@tonic-gate  * and continuations (\) in last column.
4877c478bd9Sstevel@tonic-gate  *
4887c478bd9Sstevel@tonic-gate  * return:
4897c478bd9Sstevel@tonic-gate  *	the number of chars that are placed in line.
4907c478bd9Sstevel@tonic-gate  */
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate int
rdfulline(fd,line,lim)4937c478bd9Sstevel@tonic-gate rdfulline(fd, line, lim)
4947c478bd9Sstevel@tonic-gate FILE *fd;
4957c478bd9Sstevel@tonic-gate char *line;
4967c478bd9Sstevel@tonic-gate int lim;
4977c478bd9Sstevel@tonic-gate {
4987c478bd9Sstevel@tonic-gate 	register char *p, *c;
4997c478bd9Sstevel@tonic-gate 	char buf[BUFSIZ];
5007c478bd9Sstevel@tonic-gate 	size_t blr, btox;
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate 	p = line;
5037c478bd9Sstevel@tonic-gate 	for (;fgets(buf, BUFSIZ, fd) != NULL;) {
5047c478bd9Sstevel@tonic-gate 		/* check to see if it is a comment */
5057c478bd9Sstevel@tonic-gate 
5067c478bd9Sstevel@tonic-gate 		if (buf[0] == '#')
5077c478bd9Sstevel@tonic-gate 			continue;
5087c478bd9Sstevel@tonic-gate 
5097c478bd9Sstevel@tonic-gate 		/* remove trailing white space */
5107c478bd9Sstevel@tonic-gate 		c = &buf[strlen(buf)-1];
5117c478bd9Sstevel@tonic-gate 		while (c>=buf && (*c == '\n' || *c == '\t' || *c == ' ') )
5127c478bd9Sstevel@tonic-gate 			*c-- = NULLCHAR;
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate 		if (buf[0] == '\n' || buf[0] == NULLCHAR)
5157c478bd9Sstevel@tonic-gate 			continue;
5167c478bd9Sstevel@tonic-gate 
5177c478bd9Sstevel@tonic-gate 		blr = lim - 1 - (p - line);
5187c478bd9Sstevel@tonic-gate 		btox = blr < strlen(buf) ? blr : strlen(buf);
5197c478bd9Sstevel@tonic-gate 
5207c478bd9Sstevel@tonic-gate 		if (btox <= 0)
5217c478bd9Sstevel@tonic-gate 			break;
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate 		(void) strncpy(p, buf, btox);
5247c478bd9Sstevel@tonic-gate 		p += btox - 1;
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate 		if ( *(p-1) == '\\')
5277c478bd9Sstevel@tonic-gate 			p--;
5287c478bd9Sstevel@tonic-gate 		else
5297c478bd9Sstevel@tonic-gate 			break;
5307c478bd9Sstevel@tonic-gate 	}
5317c478bd9Sstevel@tonic-gate 
5327c478bd9Sstevel@tonic-gate 	*++p = '\0';
5337c478bd9Sstevel@tonic-gate 	return(p-line-1);
5347c478bd9Sstevel@tonic-gate }
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate /*	upermit - checks to determine if the user has permissions
5377c478bd9Sstevel@tonic-gate  *	to use administrator defined service grade.
5387c478bd9Sstevel@tonic-gate  *
5397c478bd9Sstevel@tonic-gate  *	returns
5407c478bd9Sstevel@tonic-gate  *		SUCCESS -> if the user can queue to this service grade.
5417c478bd9Sstevel@tonic-gate  *		FAIL -> if the user cannot queue to this service grade.
5427c478bd9Sstevel@tonic-gate  */
5437c478bd9Sstevel@tonic-gate 
5447c478bd9Sstevel@tonic-gate int
upermit(carray,na)5457c478bd9Sstevel@tonic-gate upermit(carray, na)
5467c478bd9Sstevel@tonic-gate char **carray;
5477c478bd9Sstevel@tonic-gate int na;
5487c478bd9Sstevel@tonic-gate {
5497c478bd9Sstevel@tonic-gate #define G_USR "user"
5507c478bd9Sstevel@tonic-gate #define G_NUSR "non-user"
5517c478bd9Sstevel@tonic-gate #define G_GRP "group"
5527c478bd9Sstevel@tonic-gate #define G_NGRP "non-group"
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate 	char actn[SMBUF];
5557c478bd9Sstevel@tonic-gate 	char ufld[SMBUF];
5567c478bd9Sstevel@tonic-gate 	char msg[BUFSIZ];
5577c478bd9Sstevel@tonic-gate 
5587c478bd9Sstevel@tonic-gate 	(void) strcpy(actn, carray[G_ACT]);
5597c478bd9Sstevel@tonic-gate 
5607c478bd9Sstevel@tonic-gate 	lcase(actn, ufld, SMBUF);
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate 	if (EQUALS(ufld, G_USR))
5637c478bd9Sstevel@tonic-gate 		return(chkusr(carray,na));
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate 	if (EQUALS(ufld, G_NUSR))
5667c478bd9Sstevel@tonic-gate 		return((chkusr(carray, na) != SUCCESS) ? SUCCESS : FAIL);
5677c478bd9Sstevel@tonic-gate 
5687c478bd9Sstevel@tonic-gate 	if (EQUALS(ufld, G_GRP))
5697c478bd9Sstevel@tonic-gate 		return(chkgrp(carray, na));
5707c478bd9Sstevel@tonic-gate 
5717c478bd9Sstevel@tonic-gate 	if (EQUALS(ufld, G_NGRP))
5727c478bd9Sstevel@tonic-gate 		return((chkgrp(carray, na) != SUCCESS) ? SUCCESS : FAIL);
5737c478bd9Sstevel@tonic-gate 
5747c478bd9Sstevel@tonic-gate 	(void) snprintf(msg, sizeof (msg),
5757c478bd9Sstevel@tonic-gate 	    gettext("Error encountered in action field of"
5767c478bd9Sstevel@tonic-gate 	    " the Grades file. Field contents (%s)."), carray[G_ACT]);
5777c478bd9Sstevel@tonic-gate 	mailAdmin(msg);
5787c478bd9Sstevel@tonic-gate 	return(FAIL);
5797c478bd9Sstevel@tonic-gate }
5807c478bd9Sstevel@tonic-gate 
5817c478bd9Sstevel@tonic-gate /*
5827c478bd9Sstevel@tonic-gate  *	vergrd - verify if the grade name is a valid administrator
5837c478bd9Sstevel@tonic-gate  *		 defined service grade name and if the user has the
5847c478bd9Sstevel@tonic-gate  *		 appropiate permission to use this grade.
5857c478bd9Sstevel@tonic-gate  *
5867c478bd9Sstevel@tonic-gate  *	returns
5877c478bd9Sstevel@tonic-gate  *		SUCCESS	-> grade is valid and user is
5887c478bd9Sstevel@tonic-gate  *			   permitted to use this grade.
5897c478bd9Sstevel@tonic-gate  *		FAIL	-> otherwise
5907c478bd9Sstevel@tonic-gate  *
5917c478bd9Sstevel@tonic-gate  */
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate int
vergrd(grade)5947c478bd9Sstevel@tonic-gate vergrd(grade)
5957c478bd9Sstevel@tonic-gate char *grade;
5967c478bd9Sstevel@tonic-gate {
5977c478bd9Sstevel@tonic-gate 	FILE *cfd;
5987c478bd9Sstevel@tonic-gate 	char line[BUFSIZ];
5997c478bd9Sstevel@tonic-gate 	char *carray[G_MAX];
6007c478bd9Sstevel@tonic-gate 	int na;
6017c478bd9Sstevel@tonic-gate 
6027c478bd9Sstevel@tonic-gate 	/* Check for the default grade first */
6037c478bd9Sstevel@tonic-gate 
6047c478bd9Sstevel@tonic-gate 	if (EQUALS(grade, "default"))
6057c478bd9Sstevel@tonic-gate 		return(SUCCESS);
6067c478bd9Sstevel@tonic-gate 
6077c478bd9Sstevel@tonic-gate 	/* open grades file to begin a linear for the grade requested */
6087c478bd9Sstevel@tonic-gate 
6097c478bd9Sstevel@tonic-gate 	cfd = fopen(GRADES, "r");
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate 	/* loop until the file is empty or we find the grade we want */
6127c478bd9Sstevel@tonic-gate 
6137c478bd9Sstevel@tonic-gate 	while (rdfulline(cfd, line, BUFSIZ) != 0) {
6147c478bd9Sstevel@tonic-gate 		na = getargs(line, carray, G_MAX);
6157c478bd9Sstevel@tonic-gate 
6167c478bd9Sstevel@tonic-gate 		/* check to see if this is the grade we want */
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate 		if (!EQUALS(grade, carray[G_EXT]))
6197c478bd9Sstevel@tonic-gate 			continue;
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate 		/* check for the permission on this grade */
6227c478bd9Sstevel@tonic-gate 
6237c478bd9Sstevel@tonic-gate 		if (upermit(carray, na) != FAIL) {
6247c478bd9Sstevel@tonic-gate 			(void) fclose(cfd);
6257c478bd9Sstevel@tonic-gate 			return(SUCCESS);
6267c478bd9Sstevel@tonic-gate 		}
6277c478bd9Sstevel@tonic-gate 		else {
6287c478bd9Sstevel@tonic-gate 			(void) fclose(cfd);
6297c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, gettext("User does not have"
6307c478bd9Sstevel@tonic-gate 			    " permission to use this service grade (%s).\n"
6317c478bd9Sstevel@tonic-gate 			    "Job has not been queued.\n"
6327c478bd9Sstevel@tonic-gate 			    "Use (uuglist) to find which service grades"
6337c478bd9Sstevel@tonic-gate 			    " you can queue to.\n"), grade);
6347c478bd9Sstevel@tonic-gate 			return(FAIL);
6357c478bd9Sstevel@tonic-gate 		}
6367c478bd9Sstevel@tonic-gate 	}
6377c478bd9Sstevel@tonic-gate 
6387c478bd9Sstevel@tonic-gate 	(void) fclose(cfd);
6397c478bd9Sstevel@tonic-gate 
6407c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext(
6417c478bd9Sstevel@tonic-gate 	    "Service grade (%s) does not exist on this machine."
6427c478bd9Sstevel@tonic-gate 	    "  Job not queued.\n"
6437c478bd9Sstevel@tonic-gate 	    "Use (uuglist) to find which service grades are available on"
6447c478bd9Sstevel@tonic-gate 	    " this machine.\n"), grade);
6457c478bd9Sstevel@tonic-gate 	return(FAIL);
6467c478bd9Sstevel@tonic-gate }
6477c478bd9Sstevel@tonic-gate 
6487c478bd9Sstevel@tonic-gate /*
6497c478bd9Sstevel@tonic-gate  * wfremove - removes a C. file from the Workspace directory and all of its
6507c478bd9Sstevel@tonic-gate  * D. files.
6517c478bd9Sstevel@tonic-gate  */
6527c478bd9Sstevel@tonic-gate 
6537c478bd9Sstevel@tonic-gate void
wfremove(file)6547c478bd9Sstevel@tonic-gate wfremove(file)
6557c478bd9Sstevel@tonic-gate char *file;
6567c478bd9Sstevel@tonic-gate {
6577c478bd9Sstevel@tonic-gate 	FILE *fp;
6587c478bd9Sstevel@tonic-gate 	char line[BUFSIZ];
6597c478bd9Sstevel@tonic-gate 	char *carray[G_MAX];
6607c478bd9Sstevel@tonic-gate 	int na;
6617c478bd9Sstevel@tonic-gate 	struct stat s;
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate 	fp = fopen(file, "r");
6647c478bd9Sstevel@tonic-gate 
6657c478bd9Sstevel@tonic-gate 	if (fp == NULL) {
6667c478bd9Sstevel@tonic-gate 		toCorrupt(file);
6677c478bd9Sstevel@tonic-gate 		errent(Ct_OPEN, file, errno, __FILE__, __LINE__);
6687c478bd9Sstevel@tonic-gate 	}
6697c478bd9Sstevel@tonic-gate 
6707c478bd9Sstevel@tonic-gate 	while (fgets(line, BUFSIZ, fp) != NULL) {
6717c478bd9Sstevel@tonic-gate 		na = getargs(line, carray, G_MAX);
6727c478bd9Sstevel@tonic-gate 
6737c478bd9Sstevel@tonic-gate 		if (na < 6) {
6747c478bd9Sstevel@tonic-gate 			(void) fclose(fp);
6757c478bd9Sstevel@tonic-gate 			toCorrupt(file);
6767c478bd9Sstevel@tonic-gate 			errent("BAD NUMBER OF ARGUMENTS", file, 0,
6777c478bd9Sstevel@tonic-gate 				__FILE__, __LINE__);
6787c478bd9Sstevel@tonic-gate 		}
6797c478bd9Sstevel@tonic-gate 
6807c478bd9Sstevel@tonic-gate 		if (*carray[TYPE] == 'R')
6817c478bd9Sstevel@tonic-gate 			continue;
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate 	    	/* remove D. file */
6847c478bd9Sstevel@tonic-gate 
6857c478bd9Sstevel@tonic-gate 	    	DEBUG(4, "Removing data file (%s)\n", carray[FILE3]);
6867c478bd9Sstevel@tonic-gate 
6877c478bd9Sstevel@tonic-gate 		if ((stat(carray[FILE3], &s) != -1) && (unlink(carray[FILE3]) != 0)) {
6887c478bd9Sstevel@tonic-gate 			(void) fclose(fp);
6897c478bd9Sstevel@tonic-gate 			toCorrupt(file);
6907c478bd9Sstevel@tonic-gate 			toCorrupt(carray[FILE3]);
6917c478bd9Sstevel@tonic-gate 			errent(Ct_UNLINK, carray[FILE3], errno, __FILE__,
6927c478bd9Sstevel@tonic-gate 				__LINE__);
6937c478bd9Sstevel@tonic-gate 		}
6947c478bd9Sstevel@tonic-gate 	}
6957c478bd9Sstevel@tonic-gate 
6967c478bd9Sstevel@tonic-gate 	(void) fclose(fp);
6977c478bd9Sstevel@tonic-gate 
6987c478bd9Sstevel@tonic-gate 	DEBUG(4, "Removing work file (%s)\n", file);
6997c478bd9Sstevel@tonic-gate 
7007c478bd9Sstevel@tonic-gate 	if (unlink(file) != 0) {
7017c478bd9Sstevel@tonic-gate 		toCorrupt(file);
7027c478bd9Sstevel@tonic-gate 		errent(Ct_UNLINK, file, errno, __FILE__, __LINE__);
7037c478bd9Sstevel@tonic-gate 	}
7047c478bd9Sstevel@tonic-gate 	return;
7057c478bd9Sstevel@tonic-gate }
7067c478bd9Sstevel@tonic-gate 
7077c478bd9Sstevel@tonic-gate /*
7087c478bd9Sstevel@tonic-gate  * findgrade - finds the highest priority job grade that is not locked
7097c478bd9Sstevel@tonic-gate  * and that has jobs.
7107c478bd9Sstevel@tonic-gate  *
7117c478bd9Sstevel@tonic-gate  * job grade name is null, if no job grade is found.
7127c478bd9Sstevel@tonic-gate  */
7137c478bd9Sstevel@tonic-gate 
7147c478bd9Sstevel@tonic-gate void
findgrade(dir,jobgrade)7157c478bd9Sstevel@tonic-gate findgrade(dir, jobgrade)
7167c478bd9Sstevel@tonic-gate char *dir, *jobgrade;
7177c478bd9Sstevel@tonic-gate {
7187c478bd9Sstevel@tonic-gate 	char prevgrade[MAXBASENAME+1], curgrade[MAXBASENAME+1],
7197c478bd9Sstevel@tonic-gate 	     gradedir[MAXBASENAME+1];
7207c478bd9Sstevel@tonic-gate 	char lockname[MAXFULLNAME];
7217c478bd9Sstevel@tonic-gate 	char Cfile[MAXBASENAME+1];
7227c478bd9Sstevel@tonic-gate 	DIR *p, *q;
7237c478bd9Sstevel@tonic-gate 
7247c478bd9Sstevel@tonic-gate 	*prevgrade = NULLCHAR;
7257c478bd9Sstevel@tonic-gate 	p = opendir(dir);
7267c478bd9Sstevel@tonic-gate 	ASSERT(p != NULL, Ct_OPEN, dir, errno);
7277c478bd9Sstevel@tonic-gate 
7287c478bd9Sstevel@tonic-gate 	while (gdirf(p, gradedir, dir) == TRUE) {
7297c478bd9Sstevel@tonic-gate 		(void) sprintf(lockname, "%s.%.*s.%s", LOCKPRE, SYSNSIZE,
7307c478bd9Sstevel@tonic-gate 		    Rmtname, gradedir);
7317c478bd9Sstevel@tonic-gate 		if (cklock(lockname) == FAIL)
7327c478bd9Sstevel@tonic-gate 			continue;
7337c478bd9Sstevel@tonic-gate 		q = opendir(gradedir);
7347c478bd9Sstevel@tonic-gate 		ASSERT(q != NULL, Ct_OPEN, gradedir, errno);
7357c478bd9Sstevel@tonic-gate 		while (gnamef(q, Cfile) == TRUE) {
7367c478bd9Sstevel@tonic-gate 			if (Cfile[0] == CMDPRE) {
7377c478bd9Sstevel@tonic-gate 				if (*prevgrade == NULLCHAR) {
7387c478bd9Sstevel@tonic-gate 					(void) strcpy(prevgrade, gradedir);
7397c478bd9Sstevel@tonic-gate 					break;
7407c478bd9Sstevel@tonic-gate 				}
7417c478bd9Sstevel@tonic-gate 				(void) strcpy(curgrade, gradedir);
7427c478bd9Sstevel@tonic-gate 				if (strcmp(curgrade, prevgrade) < 0)
7437c478bd9Sstevel@tonic-gate 					(void) strcpy(prevgrade, curgrade);
7447c478bd9Sstevel@tonic-gate 			}
7457c478bd9Sstevel@tonic-gate 		}
7467c478bd9Sstevel@tonic-gate 		closedir(q);
7477c478bd9Sstevel@tonic-gate 	}
7487c478bd9Sstevel@tonic-gate 	closedir(p);
7497c478bd9Sstevel@tonic-gate 	(void) strncpy(jobgrade, prevgrade, MAXBASENAME);
7507c478bd9Sstevel@tonic-gate 	jobgrade[MAXBASENAME] = NULLCHAR;
7517c478bd9Sstevel@tonic-gate 	return;
7527c478bd9Sstevel@tonic-gate }
753