4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
21 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
22 /* All Rights Reserved */
25 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
37 #define G_MAX 512 /* max number of fields in the Grades file line */
47 extern int rdfulline(), jsize(), gdirf(), gnamef();
48 extern void wfcommit();
50 static void mailAdmin(); /* Send mail to administrator. */
53 * chkgrp - checks to see the group has permission
54 * to use a service grade queue.
58 * SUCCESS - if the group has permissions
59 * FAIL - if group does not
75 for (i
= G_IDF
; i
< na
; i
++)
76 if (EQUALS(carray
[i
], grp
->gr_name
))
83 * chkusr - checks the permission fields of the Grades file
84 * to determine if the user can queue to a particular service grade.
88 * SUCCESS - if the user can queue to the service grade.
89 * FAIL - if the user can not queue to this service grade.
101 * start at the point where the users are supposed to be in the
102 * Grades file. Loop thru until the end of the user list is
103 * found or the user name is found. If the user name is found then
104 * return TRUE. If the end of the list is found, return FAIL.
107 DEBUG(9, "User (%s)\n", User
);
109 /* check for any user and return if so */
111 if (EQUALS(carray
[G_IDF
], "Any"))
114 DEBUG(9, "Members of administrator defined service grade (%s)\n", carray
[G_EXT
]);
116 for (i
= G_IDF
; i
< na
; i
++) {
117 DEBUG(9, "%s\n", carray
[i
]);
118 if (EQUALS(User
, carray
[i
]))
126 * fgrade - finds the appropiate queue to queue a job into
129 * SUCCESS -> found a queue
130 * FAIL -> can't find a queue
135 struct cs_struct
*scfile
;
143 /* Check for the default service grade first */
145 if (strcmp(scfile
->sgrade
, "default") == 0) {
146 scfile
->grade
= fdgrade();
150 /* open grades file to begin a linear for the grade requested */
152 cfd
= fopen(GRADES
, "r");
154 /* loop until the file is empty or we find the grade we want */
156 while (rdfulline(cfd
, line
, BUFSIZ
) != 0) {
157 (void) getargs(line
, carray
, G_MAX
);
159 /* check to see if this is the grade we want */
161 if (!EQUALS(scfile
->sgrade
, carray
[G_EXT
]))
164 if (jsize(scfile
, carray
[G_RES
], &climit
) != FAIL
) {
166 scfile
->grade
= *carray
[G_INT
];
173 (void) fprintf(stderr
, gettext("Job size (%ld bytes)"
174 " exceeds maximum number of bytes (%ld bytes)"
175 " allowed into this service grade (%s).\n"
176 "Job queued to default grade.\n"),
177 scfile
->jsize
, climit
, scfile
->sgrade
);
179 scfile
->grade
= fdgrade();
184 * fdgrade - finds the default queue for this system
187 * a one char name for the default queue
198 /* Check for the default grade first */
200 cfd
= fopen(GRADES
, "r");
202 /* loop until the end of the file is read */
204 for (; rdfulline(cfd
, line
, BUFSIZ
) != 0;) {
206 /* parse the fields of this line */
208 (void) getargs(line
, carray
, G_MAX
);
210 /* check to see if the administrator has defined
211 * a default grade for the machine.
214 if (strcmp(carray
[G_EXT
], "default") != 0)
217 /* default must be defined in the file
218 * close the file, get the queue name, and return.
222 return(*carray
[G_INT
]);
225 /* no default defined in this file. close file.
226 * get our default queue and return.
234 * job_size - determines the size of a job
238 * SUCCESS - if the size of the job can be determined
244 struct cs_struct
*scfile
;
246 extern int Dfileused
;
257 fp
= fopen(scfile
->file
, "r");
260 toCorrupt(scfile
->file
);
261 errent(Ct_OPEN
, scfile
->file
, errno
, __FILE__
, __LINE__
);
264 while (fgets(line
, BUFSIZ
, fp
) != NULL
) {
265 na
= getargs(line
, carray
, G_MAX
);
269 toCorrupt(scfile
->file
);
270 errent("BAD NUMBER OF ARGUMENTS", scfile
->file
, 0,
274 /* if the type of a transfer is not a push
275 * then don't try to determine the size of
276 * the data file, because you can't.
279 if (*carray
[TYPE
] == 'R')
282 /* find the data dile that is to be transferred */
284 if ((ret
= stat(carray
[FILE3
], &s
)) != 0) {
285 if (errno
== ENOENT
) {
287 ret
= stat(carray
[FILE1
], &s
);
294 * check to see if the return code from stat was 0
295 * if return code was not 0, write message to error
296 * log and quit. Otherwise, add size of file to job
297 * size and continue looping.
302 errent(Ct_STAT
, nodfile
?
303 carray
[FILE1
] : carray
[FILE3
], errno
,
308 scfile
->jsize
+= s
.st_size
;
317 * jsize - determines whether if a job is small enough to
318 * be placed in the appropiate queue.
322 * SUCCESS - if the size of the job is less than or
323 * equal to the number of bytes in the restriction
324 * of the GRADES file.
330 jsize(scfile
, climit
, nlimit
)
331 struct cs_struct
*scfile
;
336 #define ONE_MEG ((1024)*(1024))
339 char msg
[BUFSIZ
], *p
;
341 if (EQUALS(climit
, "Any"))
344 lcase(climit
, rest
, SMBUF
);
346 if (!(p
= strchr(rest
, 'k')) && (!(p
= strchr(rest
, 'm')))) {
348 for(p
= climit
; *p
; ++p
) {
352 /* corrupt restriction field in the Grades file.
353 * report it to the uucp administrator.
356 snprintf(msg
, sizeof (msg
),
357 gettext("Error encountered in the"
358 " restrictions field of the Grades file."
359 " Field contents (%s)."), climit
);
364 *nlimit
= atol(climit
);
366 else if (*p
== 'k') {
368 *nlimit
= (long) (atof(rest
) * ONE_K
);
372 *nlimit
= (long) (atof(rest
) * ONE_MEG
);
375 if (scfile
->jsize
<= *nlimit
)
392 for (i
= 0; i
< lim
-1 && *p
; i
++)
394 t
[i
] = tolower(*p
++);
403 * mailAdmin - mail a message to the uucp administrator.
416 char cmd
[BUFSIZ
]; /* Place to build mail command. */
417 FILE * mail
; /* Channel to write mail on. */
419 (void) sprintf(cmd
, "%s %s %s", PATH
, MAIL
, "uucp");
420 if ((mail
= popen(cmd
, "w")) != (FILE *) NULL
)
422 (void) fprintf(mail
, "To: uucp\nSubject: %s\n\n%s\n",
423 gettext("Grades file problem"), msg
);
428 * Ignore popen failure. There is not much that we can do if
429 * it fails, since we are already trying to notify the administrator
436 * putdfiles - moves any and all of the D. to the spool directory for
446 struct cs_struct scfile
;
454 fp
= fopen(scfile
.file
, "r");
457 toCorrupt(scfile
.file
);
458 errent(Ct_OPEN
, scfile
.file
, errno
, __FILE__
, __LINE__
);
461 while (fgets(line
, BUFSIZ
, fp
) != NULL
) {
463 na
= getargs(line
, carray
, G_MAX
);
466 toCorrupt(scfile
.file
);
467 errent("BAD NUMBER OF ARGUMENTS", scfile
.file
, 0,
471 if (*carray
[TYPE
] == 'R')
474 /* move D. file to the spool area */
476 if (stat(carray
[FILE3
], &s
) != -1)
477 wfcommit(carray
[FILE3
], carray
[FILE3
], scfile
.sys
);
485 * reads a line from a file and takes care of comment lines
486 * and continuations (\) in last column.
489 * the number of chars that are placed in line.
493 rdfulline(fd
, line
, lim
)
498 register char *p
, *c
;
503 for (;fgets(buf
, BUFSIZ
, fd
) != NULL
;) {
504 /* check to see if it is a comment */
509 /* remove trailing white space */
510 c
= &buf
[strlen(buf
)-1];
511 while (c
>=buf
&& (*c
== '\n' || *c
== '\t' || *c
== ' ') )
514 if (buf
[0] == '\n' || buf
[0] == NULLCHAR
)
517 blr
= lim
- 1 - (p
- line
);
518 btox
= blr
< strlen(buf
) ? blr
: strlen(buf
);
523 (void) strncpy(p
, buf
, btox
);
536 /* upermit - checks to determine if the user has permissions
537 * to use administrator defined service grade.
540 * SUCCESS -> if the user can queue to this service grade.
541 * FAIL -> if the user cannot queue to this service grade.
550 #define G_NUSR "non-user"
551 #define G_GRP "group"
552 #define G_NGRP "non-group"
558 (void) strcpy(actn
, carray
[G_ACT
]);
560 lcase(actn
, ufld
, SMBUF
);
562 if (EQUALS(ufld
, G_USR
))
563 return(chkusr(carray
,na
));
565 if (EQUALS(ufld
, G_NUSR
))
566 return((chkusr(carray
, na
) != SUCCESS
) ? SUCCESS
: FAIL
);
568 if (EQUALS(ufld
, G_GRP
))
569 return(chkgrp(carray
, na
));
571 if (EQUALS(ufld
, G_NGRP
))
572 return((chkgrp(carray
, na
) != SUCCESS
) ? SUCCESS
: FAIL
);
574 (void) snprintf(msg
, sizeof (msg
),
575 gettext("Error encountered in action field of"
576 " the Grades file. Field contents (%s)."), carray
[G_ACT
]);
582 * vergrd - verify if the grade name is a valid administrator
583 * defined service grade name and if the user has the
584 * appropiate permission to use this grade.
587 * SUCCESS -> grade is valid and user is
588 * permitted to use this grade.
602 /* Check for the default grade first */
604 if (EQUALS(grade
, "default"))
607 /* open grades file to begin a linear for the grade requested */
609 cfd
= fopen(GRADES
, "r");
611 /* loop until the file is empty or we find the grade we want */
613 while (rdfulline(cfd
, line
, BUFSIZ
) != 0) {
614 na
= getargs(line
, carray
, G_MAX
);
616 /* check to see if this is the grade we want */
618 if (!EQUALS(grade
, carray
[G_EXT
]))
621 /* check for the permission on this grade */
623 if (upermit(carray
, na
) != FAIL
) {
629 (void) fprintf(stderr
, gettext("User does not have"
630 " permission to use this service grade (%s).\n"
631 "Job has not been queued.\n"
632 "Use (uuglist) to find which service grades"
633 " you can queue to.\n"), grade
);
640 (void) fprintf(stderr
, gettext(
641 "Service grade (%s) does not exist on this machine."
643 "Use (uuglist) to find which service grades are available on"
644 " this machine.\n"), grade
);
649 * wfremove - removes a C. file from the Workspace directory and all of its
663 fp
= fopen(file
, "r");
667 errent(Ct_OPEN
, file
, errno
, __FILE__
, __LINE__
);
670 while (fgets(line
, BUFSIZ
, fp
) != NULL
) {
671 na
= getargs(line
, carray
, G_MAX
);
676 errent("BAD NUMBER OF ARGUMENTS", file
, 0,
680 if (*carray
[TYPE
] == 'R')
685 DEBUG(4, "Removing data file (%s)\n", carray
[FILE3
]);
687 if ((stat(carray
[FILE3
], &s
) != -1) && (unlink(carray
[FILE3
]) != 0)) {
690 toCorrupt(carray
[FILE3
]);
691 errent(Ct_UNLINK
, carray
[FILE3
], errno
, __FILE__
,
698 DEBUG(4, "Removing work file (%s)\n", file
);
700 if (unlink(file
) != 0) {
702 errent(Ct_UNLINK
, file
, errno
, __FILE__
, __LINE__
);
708 * findgrade - finds the highest priority job grade that is not locked
711 * job grade name is null, if no job grade is found.
715 findgrade(dir
, jobgrade
)
716 char *dir
, *jobgrade
;
718 char prevgrade
[MAXBASENAME
+1], curgrade
[MAXBASENAME
+1],
719 gradedir
[MAXBASENAME
+1];
720 char lockname
[MAXFULLNAME
];
721 char Cfile
[MAXBASENAME
+1];
724 *prevgrade
= NULLCHAR
;
726 ASSERT(p
!= NULL
, Ct_OPEN
, dir
, errno
);
728 while (gdirf(p
, gradedir
, dir
) == TRUE
) {
729 (void) sprintf(lockname
, "%s.%.*s.%s", LOCKPRE
, SYSNSIZE
,
731 if (cklock(lockname
) == FAIL
)
733 q
= opendir(gradedir
);
734 ASSERT(q
!= NULL
, Ct_OPEN
, gradedir
, errno
);
735 while (gnamef(q
, Cfile
) == TRUE
) {
736 if (Cfile
[0] == CMDPRE
) {
737 if (*prevgrade
== NULLCHAR
) {
738 (void) strcpy(prevgrade
, gradedir
);
741 (void) strcpy(curgrade
, gradedir
);
742 if (strcmp(curgrade
, prevgrade
) < 0)
743 (void) strcpy(prevgrade
, curgrade
);
749 (void) strncpy(jobgrade
, prevgrade
, MAXBASENAME
);
750 jobgrade
[MAXBASENAME
] = NULLCHAR
;