SCCS-vsn: usr.sbin/lpr/lpr/lpr.c 4.9
char lpr_id[] = "~|^`lpr.c:\t4.2\t1 May 1981\n";
char lpr_id[] = "~|^`lpr.c:\t4.2\t1 May 1981\n";
-/* lpr.c 4.9 83/03/01 */
+/* lpr.c 4.9 83/03/07 */
/*
* lpr -- off line print
*
/*
* lpr -- off line print
*
char *malloc();
char *getenv();
char *rindex();
char *malloc();
char *getenv();
char *rindex();
/*ARGSUSED*/
main(argc, argv)
/*ARGSUSED*/
main(argc, argv)
extern struct passwd *getpwuid(), *getpwnam();
struct passwd *pw;
extern char *itoa();
extern struct passwd *getpwuid(), *getpwnam();
struct passwd *pw;
extern char *itoa();
+ register char *arg, *cp;
int i, f, out();
char *printer = NULL;
struct stat stb;
int i, f, out();
char *printer = NULL;
struct stat stb;
indent = arg[2] ? atoi(&arg[2]) : 8;
break;
indent = arg[2] ? atoi(&arg[2]) : 8;
break;
- default: /* n copies ? */
- if (isdigit(arg[1]))
- ncopies = atoi(&arg[1]);
+ case '#': /* n copies */
+ if (isdigit(arg[2]))
+ ncopies = atoi(&arg[2]);
}
}
if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
printer = DEFLP;
if (!chkprinter(printer)) {
}
}
if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
printer = DEFLP;
if (!chkprinter(printer)) {
- printf("%s: unknown printer\n", name, printer);
+ printf("%s: unknown printer %s\n", name, printer);
if (hdr) {
if (jobname == NULL) {
if (argc == 1)
if (hdr) {
if (jobname == NULL) {
if (argc == 1)
- jobname = &cfname[inchar-2];
else
jobname = argv[1];
}
else
jobname = argv[1];
}
for (i = 0; i < 4; i++)
if (fonts[i] != NULL)
card('1'+i, fonts[i]);
for (i = 0; i < 4; i++)
if (fonts[i] != NULL)
card('1'+i, fonts[i]);
- else if ((format == 'f' || format == 'l' || format == 'p') && width)
card('W', width);
if (argc == 1)
copy(0, " ");
else while (--argc) {
card('W', width);
if (argc == 1)
copy(0, " ");
else while (--argc) {
- if ((i = test(arg = *++argv)) < 0)
+ if ((f = test(arg = *++argv)) < 0)
continue; /* file unreasonable */
continue; /* file unreasonable */
- if (i && lflag && linked(arg)) {
+ if ((f & 1) && (cp = linked(arg)) != NULL) {
if (format == 'p')
card('T', title ? title : arg);
for (i = 0; i < ncopies; i++)
card(format, &dfname[inchar-2]);
card('U', &dfname[inchar-2]);
if (format == 'p')
card('T', title ? title : arg);
for (i = 0; i < ncopies; i++)
card(format, &dfname[inchar-2]);
card('U', &dfname[inchar-2]);
+ if (f & 2)
+ card('U', cp);
card('N', arg);
dfname[inchar]++;
nact++;
} else {
card('N', arg);
dfname[inchar]++;
nact++;
} else {
- if ((f = open(arg, 0)) < 0) {
+ if ((i = open(arg, 0)) < 0) {
printf("%s: cannot open %s\n", name, arg);
continue;
}
printf("%s: cannot open %s\n", name, arg);
continue;
}
- copy(f, arg);
- (void) close(f);
- }
- if (rflag) {
- register char *cp;
-
- if ((cp = rindex(arg, '/')) == NULL)
- f = access(".", 2);
- else {
- *cp = '\0';
- f = access(arg, 2);
- *cp = '/';
- }
- if (f || unlink(arg))
+ copy(i, arg);
+ (void) close(i);
+ if ((f & 2) && unlink(arg))
printf("%s: cannot remove %s\n", name, arg);
}
}
printf("%s: cannot remove %s\n", name, arg);
}
}
printf("jobs queued, but line printer is down.\n");
exit(0);
}
printf("jobs queued, but line printer is down.\n");
exit(0);
}
- execl(DN, arg = rindex(DN, "/") ? arg+1 : DN, printer, 0);
+ execl(DN, (arg = rindex(DN, '/')) ? arg+1 : DN, printer, 0);
printf("jobs queued, but cannot start daemon.\n");
exit(0);
}
printf("jobs queued, but cannot start daemon.\n");
exit(0);
}
- * Try and link the file to dfname. Return true if successful.
+ * Try and link the file to dfname. Return a pointer to the full
+ * path name if successful.
linked(file)
register char *file;
{
register char *cp;
char buf[BUFSIZ];
linked(file)
register char *file;
{
register char *cp;
char buf[BUFSIZ];
- if (link(file, dfname) == 0)
- return(1);
if (*file != '/') {
if (getwd(buf) == NULL)
if (*file != '/') {
if (getwd(buf) == NULL)
while (file[0] == '.') {
switch (file[1]) {
case '/':
while (file[0] == '.') {
switch (file[1]) {
case '/':
strcat(buf, file);
file = buf;
}
strcat(buf, file);
file = buf;
}
- return(symlink(file, dfname) == 0);
+ return(symlink(file, dfname) ? NULL : file);
printf("%s: cannot create %s\n", name, n);
out();
}
printf("%s: cannot create %s\n", name, n);
out();
}
if (chown(n, userid, -1) < 0) {
if (chown(n, userid, -1) < 0) {
+#else
+ if (chown(n, userid, getegid()) < 0) {
+#endif
unlink(n);
printf("%s: cannot chown %s\n", name, n);
out();
unlink(n);
printf("%s: cannot chown %s\n", name, n);
out();
/*
* Test to see if this is a printable file.
/*
* Test to see if this is a printable file.
- * Return -1 if it is not, 1 if it's publically readable, else 0
+ * Return -1 if it is not, 1 if we should try to link and or in 2 if
+ * we should remove it after printing.
*/
test(file)
char *file;
{
struct exec execb;
struct stat statb;
*/
test(file)
char *file;
{
struct exec execb;
struct stat statb;
+ register int fd;
+ register char *cp;
if (access(file, 4) < 0) {
printf("%s: cannot access %s\n", name, file);
if (access(file, 4) < 0) {
printf("%s: cannot access %s\n", name, file);
goto error1;
}
(void) close(fd);
goto error1;
}
(void) close(fd);
- if (rflag) { /* check to make sure user can delete this file */
- register char *cp = rindex(file, '/');
-
- if (cp == NULL)
- fd = access(".", 2);
- else {
+ fd = 0;
+ if (lflag && (statb.st_mode & 04))
+ fd |= 1;
+ if (rflag) {
+ if ((cp = rindex(file, '/')) == NULL) {
+ if (access(".", 2) == 0)
+ fd |= 2;
+ } else {
+ if (access(file, 2) == 0)
+ fd |= 2;
- if (fd < 0) {
- printf("%s: cannot remove %s\n", name, file);
- return(-1);
- }
- if (statb.st_mode & 04)
- return(1);
- return(0);
error1:
printf(" and is unprintable\n");
error1:
printf(" and is unprintable\n");