summaryrefslogtreecommitdiff
path: root/usr.sbin/rpc.pcnfsd
diff options
context:
space:
mode:
authorEric Jackson <ericj@cvs.openbsd.org>2001-08-19 19:16:13 +0000
committerEric Jackson <ericj@cvs.openbsd.org>2001-08-19 19:16:13 +0000
commit38da0b74b703fb2b4d2d60fcc80f0f9fdddf709c (patch)
tree464c247a7d04118b121c559ee8fe614ddedf1bca /usr.sbin/rpc.pcnfsd
parente74e0c407458e60632d7cd8932ba6aa0d3d0ffa4 (diff)
first pass at some cleanup here
- use standard functions,, dont roll our own (strdup, strcasecmp, etc) - style(9) - share common headers.. more readable. doesnt address some of the other problems (cacheing), yet
Diffstat (limited to 'usr.sbin/rpc.pcnfsd')
-rw-r--r--usr.sbin/rpc.pcnfsd/Makefile4
-rw-r--r--usr.sbin/rpc.pcnfsd/README1
-rw-r--r--usr.sbin/rpc.pcnfsd/common.h184
-rw-r--r--usr.sbin/rpc.pcnfsd/paths.h28
-rw-r--r--usr.sbin/rpc.pcnfsd/pcnfsd.81
-rw-r--r--usr.sbin/rpc.pcnfsd/pcnfsd.x1
-rw-r--r--usr.sbin/rpc.pcnfsd/pcnfsd_cache.c65
-rw-r--r--usr.sbin/rpc.pcnfsd/pcnfsd_misc.c426
-rw-r--r--usr.sbin/rpc.pcnfsd/pcnfsd_print.c838
-rw-r--r--usr.sbin/rpc.pcnfsd/pcnfsd_test.c2
-rw-r--r--usr.sbin/rpc.pcnfsd/pcnfsd_v1.c150
-rw-r--r--usr.sbin/rpc.pcnfsd/pcnfsd_v2.c416
12 files changed, 463 insertions, 1653 deletions
diff --git a/usr.sbin/rpc.pcnfsd/Makefile b/usr.sbin/rpc.pcnfsd/Makefile
index 07bc6b23ca6..55ace922bc9 100644
--- a/usr.sbin/rpc.pcnfsd/Makefile
+++ b/usr.sbin/rpc.pcnfsd/Makefile
@@ -1,11 +1,11 @@
-# $OpenBSD: Makefile,v 1.7 2000/09/03 18:41:22 espie Exp $
+# $OpenBSD: Makefile,v 1.8 2001/08/19 19:16:12 ericj Exp $
.include <bsd.own.mk>
PROG= rpc.pcnfsd
MAN= pcnfsd.8
MLINKS= pcnfsd.8 rpc.pcnfsd.8
-CFLAGS += -DUSER_CACHE -DWTMP -I${.OBJDIR}
+CFLAGS += -I${.OBJDIR}
.if (${YP:L} == "yes")
CFLAGS+=-DUSE_YP
diff --git a/usr.sbin/rpc.pcnfsd/README b/usr.sbin/rpc.pcnfsd/README
index 2053b7c654e..4cc12498b53 100644
--- a/usr.sbin/rpc.pcnfsd/README
+++ b/usr.sbin/rpc.pcnfsd/README
@@ -1,3 +1,4 @@
+# $OpenBSD: README,v 1.2 2001/08/19 19:16:12 ericj Exp $
# $NetBSD: README,v 1.2 1995/07/25 22:20:22 gwr Exp $
diff --git a/usr.sbin/rpc.pcnfsd/common.h b/usr.sbin/rpc.pcnfsd/common.h
deleted file mode 100644
index 8312749b038..00000000000
--- a/usr.sbin/rpc.pcnfsd/common.h
+++ /dev/null
@@ -1,184 +0,0 @@
-/* $NetBSD: common.h,v 1.2 1995/07/25 22:20:26 gwr Exp $ */
-
-/* RE_SID: @(%)/usr/dosnfs/shades_SCCS/unix/pcnfsd/v2/src/SCCS/s.common.h 1.3 91/12/17 14:32:05 SMI */
-/*
-**=====================================================================
-** Copyright (c) 1986,1987,1988,1989,1990,1991 by Sun Microsystems, Inc.
-**
-** D I S C L A I M E R S E C T I O N , E T C .
-**
-** pcnfsd is copyrighted software, but is freely licensed. This
-** means that you are free to redistribute it, modify it, ship it
-** in binary with your system, whatever, provided:
-**
-** - you leave the Sun copyright notice in the source code
-** - you make clear what changes you have introduced and do
-** not represent them as being supported by Sun.
-**
-** If you make changes to this software, we ask that you do so in
-** a way which allows you to build either the "standard" version or
-** your custom version from a single source file. Test it, lint
-** it (it won't lint 100%, very little does, and there are bugs in
-** some versions of lint :-), and send it back to Sun via email
-** so that we can roll it into the source base and redistribute
-** it. We'll try to make sure your contributions are acknowledged
-** in the source, but after all these years it's getting hard to
-** remember who did what.
-**
-** The main contributors have been (in no special order):
-**
-** Glen Eustace <G.Eustace@massey.ac.nz>
-** user name caching for b-i-g password files
-** Paul Emerson <paul@sdgsun.uucp>
-** cleaning up Interactive 386/ix handling, fixing the lp
-** interface, and generally tidying up the sources
-** Keith Ericson <keithe@sail.labs.tek.com>
-** more 386/ix fixes
-** Jeff Stearns <jeff@tc.fluke.com>
-** setuid/setgid for lpr
-** Peter Van Campen <petervc@sci.kun.nl>
-** fixing setuid/gid stuff, syslog
-** Ted Nolan <ted@usasoc.soc.mil>
-** /usr/adm/wtmp, other security suggestions
-**
-** Thanks to everyone who has contributed.
-**
-** Geoff Arnold, PC-NFS architect <geoff@East.Sun.COM>
-**=====================================================================
-*/
-/*
-**=====================================================================
-** C U S T O M I Z A T I O N S E C T I O N *
-** *
-** You should not uncomment these #defines in this version of pcnfsd *
-** Instead you should edit the makefile CDEFS variable. *
-** *
-**=====================================================================
-*/
-
-/*
-**---------------------------------------------------------------------
-** Define (via Makefile) the following symbol to enable the use of a
-** shadow password file
-**---------------------------------------------------------------------
-**/
-
-/* #define SHADOW_SUPPORT */
-
-/*
-**---------------------------------------------------------------------
-** Define (via Makefile) the following symbol to enable the logging
-** of authentication requests to /usr/adm/wtmp
-**---------------------------------------------------------------------
-**/
-
-/* #define WTMP */
-
-/*
-**------------------------------------------------------------------------
-** Define (via Makefile) the following symbol conform to Interactive
-** System's 2.0
-**------------------------------------------------------------------------
-*/
-
-/* #define ISC_2_0 */
-
-/*
-**---------------------------------------------------------------------
-** Define (via Makefile) the following symbol to use a cache of recently-used
-** user names. This has certain uses in university and other settings
-** where (1) the pasword file is very large, and (2) a group of users
-** frequently logs in together using the same account (for example,
-** a class userid).
-**---------------------------------------------------------------------
-*/
-
-/* #define USER_CACHE */
-
-/*
-**---------------------------------------------------------------------
-** Define (via Makefile) the following symbol to build a System V version
-**---------------------------------------------------------------------
-*/
-
-/* #define SYSV */
-
-/*
-**---------------------------------------------------------------------
-** Define (via Makefile) the following symbol to build a version that uses
-** System V style "lp" instead of BSD-style "lpr" to print
-**---------------------------------------------------------------------
-*/
-
-/* #define USE_LP */
-
-/*
-**---------------------------------------------------------------------
-** Define (via Makefile) the following symbol to build a typical
-** "local feature": in this case recognizing the special printer
-** names "rotated" and "2column" and using the Adobe "enscript"
-** command to format the output appropriately.
-**---------------------------------------------------------------------
-*/
-
-/* #define HACK_FOR_ROTATED_TRANSCRIPT */
-
-/*
-**---------------------------------------------------------------------
-** Define (via Makefile) the following symbol to build a version that
-** will use the setusershell()/getusershell()/endusershell() calls
-** to determine if a password entry contains a legal shell (and therefore
-** identifies a user who may log in). The default is to check that
-** the last two characters of the shell field are "sh", which should
-** cope with "sh", "csh", "ksh", "bash".... See the routine get_pasword()
-** in pcnfsd_misc.c for more details.
-**
-** Note: For some reason that I haven't yet figured out, getusershell()
-** only seems to work when RPC_SVC_FG is defined (for debugging). It doesn't
-** seem to matter whether /etc/shells exists or not. Tracing
-** things doesn't throw any light on this.... Geoff Dec.17 '91
-*/
-
-/*
-**---------------------------------------------------------------------
-** Define (via Makefile) the following symbol to build a version that
-** will consult the NIS (formerly Yellow Pages) "auto.home" map to
-** locate the user's home directory (returned by the V2 authentication
-** procedure).
-**---------------------------------------------------------------------
-*/
-
-/* #define USE_YP */
-
-
-/* #define USE_GETUSERSHELL */
-
-
-/*
-**---------------------------------------------------------------------
-** The following should force the right things for Interactive 2.0
-**---------------------------------------------------------------------
-*/
-#ifdef ISC_2_0
-#define SYSV
-#define USE_LP
-#define SHADOW_SUPPORT
-#endif
-
-/*
-**---------------------------------------------------------------------
-** Other #define's
-**---------------------------------------------------------------------
-*/
-
-#define assert(ex) {\
- if (!(ex)) { \
- char asstmp[256]; \
- (void)snprintf(asstmp, sizeof asstmp, \
- "rpc.pcnfsd: Assertion failed: line %d of %s: \"%s\"\n", \
- __LINE__, __FILE__, "ex"); \
- (void)msg_out(asstmp); \
- sleep (10); \
- exit(1); \
- } \
-}
diff --git a/usr.sbin/rpc.pcnfsd/paths.h b/usr.sbin/rpc.pcnfsd/paths.h
index 9c589d3cf62..14336ad057b 100644
--- a/usr.sbin/rpc.pcnfsd/paths.h
+++ b/usr.sbin/rpc.pcnfsd/paths.h
@@ -1,13 +1,25 @@
+/* $OpenBSD: paths.h,v 1.2 2001/08/19 19:16:12 ericj Exp $ */
/* $NetBSD: paths.h,v 1.1 1995/08/14 19:50:09 gwr Exp $ */
-#ifndef SPOOLDIR
#define SPOOLDIR "/export/pcnfs"
-#endif
-
-#ifndef LPRDIR
#define LPRDIR "/usr/bin"
-#endif
-
-#ifndef LPCDIR
#define LPCDIR "/usr/sbin"
-#endif
+
+pr_list printers;
+pr_queue queue;
+
+/* pcnfsd_misc.c */
+void scramble __P((char *, char *));
+void wlogin __P((char *, struct svc_req *));
+struct passwd *get_password __P((char *));
+
+/* pcnfsd_print.c */
+void *grab __P((int));
+FILE *su_popen __P((char *, char *, int));
+int su_pclose __P((FILE *));
+int build_pr_list __P((void));
+pirstat build_pr_queue __P((printername, username, int, int *, int *));
+psrstat pr_start2 __P((char *, char *, char *, char *, char *, char **));
+pcrstat pr_cancel __P((char *, char *, char *));
+pirstat get_pr_status __P((printername, bool_t *, bool_t *, int *, bool_t *,
+ char *));
diff --git a/usr.sbin/rpc.pcnfsd/pcnfsd.8 b/usr.sbin/rpc.pcnfsd/pcnfsd.8
index dd3872de422..0882fbfe8f3 100644
--- a/usr.sbin/rpc.pcnfsd/pcnfsd.8
+++ b/usr.sbin/rpc.pcnfsd/pcnfsd.8
@@ -1,3 +1,4 @@
+.\" $OpenBSD: pcnfsd.8,v 1.8 2001/08/19 19:16:12 ericj Exp $
.\" $NetBSD: pcnfsd.8,v 1.4 1995/08/14 19:48:07 gwr Exp $
.\" @(#) @(#)pcnfsd.8c 1.1 9/3/91;
.TH PCNFSD 8 "25 April 1991"
diff --git a/usr.sbin/rpc.pcnfsd/pcnfsd.x b/usr.sbin/rpc.pcnfsd/pcnfsd.x
index 9274d768aef..947ba0b3436 100644
--- a/usr.sbin/rpc.pcnfsd/pcnfsd.x
+++ b/usr.sbin/rpc.pcnfsd/pcnfsd.x
@@ -1,3 +1,4 @@
+/* $OpenBSD: pcnfsd.x,v 1.2 2001/08/19 19:16:12 ericj Exp $ */
/* $NetBSD: pcnfsd.x,v 1.2 1995/07/25 22:20:33 gwr Exp $ */
/* The maximum number of bytes in a user name argument */
diff --git a/usr.sbin/rpc.pcnfsd/pcnfsd_cache.c b/usr.sbin/rpc.pcnfsd/pcnfsd_cache.c
index b5a1fe7b95c..9053205cedc 100644
--- a/usr.sbin/rpc.pcnfsd/pcnfsd_cache.c
+++ b/usr.sbin/rpc.pcnfsd/pcnfsd_cache.c
@@ -1,69 +1,39 @@
+/* $OpenBSD: pcnfsd_cache.c,v 1.4 2001/08/19 19:16:12 ericj Exp $ */
/* $NetBSD: pcnfsd_cache.c,v 1.2 1995/07/25 22:20:37 gwr Exp $ */
/* RE_SID: @(%)/usr/dosnfs/shades_SCCS/unix/pcnfsd/v2/src/SCCS/s.pcnfsd_cache.c 1.1 91/09/03 12:45:14 SMI */
/*
-**=====================================================================
-** Copyright (c) 1986,1987,1988,1989,1990,1991 by Sun Microsystems, Inc.
-** @(#)pcnfsd_cache.c 1.1 9/3/91
-**=====================================================================
-*/
-#include "common.h"
-/*
-**=====================================================================
-** I N C L U D E F I L E S E C T I O N *
-** *
-** If your port requires different include files, add a suitable *
-** #define in the customization section, and make the inclusion or *
-** exclusion of the files conditional on this. *
-**=====================================================================
-*/
-#include "pcnfsd.h"
+ *=====================================================================
+ * Copyright (c) 1986,1987,1988,1989,1990,1991 by Sun Microsystems, Inc.
+ * @(#)pcnfsd_cache.c 1.1 9/3/91
+ *=====================================================================
+ */
#include <stdio.h>
#include <pwd.h>
#include <errno.h>
#include <string.h>
+#include <unistd.h>
-extern char *crypt();
-
-
-/*
-**---------------------------------------------------------------------
-** Misc. variable definitions
-**---------------------------------------------------------------------
-*/
-
+#include "pcnfsd.h"
-#ifdef USER_CACHE
#define CACHE_SIZE 16 /* keep it small, as linear searches are
* done */
struct cache
- {
+{
int cuid;
int cgid;
char cpw[_PASSWORD_LEN];
char cuname[10]; /* keep this even for machines
* with alignment problems */
- }User_cache[CACHE_SIZE];
-
-
-
-/*
-**---------------------------------------------------------------------
-** User cache support procedures
-**---------------------------------------------------------------------
-*/
-
+} User_cache[CACHE_SIZE];
int
check_cache(name, pw, p_uid, p_gid)
- char *name;
- char *pw;
- int *p_uid;
- int *p_gid;
+ char *name, *pw;
+ int *p_uid, *p_gid;
{
- int i;
- int c1, c2;
+ int i, c1, c2;
for (i = 0; i < CACHE_SIZE; i++) {
if (!strcmp(User_cache[i].cuname, name)) {
@@ -85,9 +55,9 @@ check_cache(name, pw, p_uid, p_gid)
void
add_cache_entry(p)
- struct passwd *p;
+ struct passwd *p;
{
- int i;
+ int i;
for (i = CACHE_SIZE - 1; i > 0; i--)
User_cache[i] = User_cache[i - 1];
@@ -98,8 +68,3 @@ add_cache_entry(p)
(void)strncpy(User_cache[0].cuname, p->pw_name, sizeof User_cache[0].cuname-1);
User_cache[0].cuname[sizeof User_cache[0].cuname-1] = '\0';
}
-
-
-#endif /* USER_CACHE */
-
-
diff --git a/usr.sbin/rpc.pcnfsd/pcnfsd_misc.c b/usr.sbin/rpc.pcnfsd/pcnfsd_misc.c
index f696d26f8ba..93ae185c207 100644
--- a/usr.sbin/rpc.pcnfsd/pcnfsd_misc.c
+++ b/usr.sbin/rpc.pcnfsd/pcnfsd_misc.c
@@ -1,23 +1,18 @@
+/* $OpenBSD: pcnfsd_misc.c,v 1.4 2001/08/19 19:16:12 ericj Exp $ */
/* $NetBSD: pcnfsd_misc.c,v 1.2 1995/07/25 22:20:42 gwr Exp $ */
/* RE_SID: @(%)/usr/dosnfs/shades_SCCS/unix/pcnfsd/v2/src/SCCS/s.pcnfsd_misc.c 1.5 92/01/24 19:59:13 SMI */
/*
-**=====================================================================
-** Copyright (c) 1986,1987,1988,1989,1990,1991 by Sun Microsystems, Inc.
-** @(#)pcnfsd_misc.c 1.5 1/24/92
-**=====================================================================
-*/
-#include "common.h"
-/*
-**=====================================================================
-** I N C L U D E F I L E S E C T I O N *
-** *
-** If your port requires different include files, add a suitable *
-** #define in the customization section, and make the inclusion or *
-** exclusion of the files conditional on this. *
-**=====================================================================
-*/
-#include "pcnfsd.h"
+ *=====================================================================
+ * Copyright (c) 1986,1987,1988,1989,1990,1991 by Sun Microsystems, Inc.
+ * @(#)pcnfsd_misc.c 1.5 1/24/92
+ *=====================================================================
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
#include <stdio.h>
#include <pwd.h>
@@ -30,169 +25,67 @@
#include <errno.h>
#include <string.h>
#include <ctype.h>
+#include <utmp.h>
-#ifdef ISC_2_0
-#include <sys/fcntl.h>
-#endif
-
-#ifdef SHADOW_SUPPORT
-#include <shadow.h>
-#endif
-
-#ifdef WTMP
-int wtmp_enabled = 1;
-#endif
-
-#ifdef USE_GETUSERSHELL
-extern char *getusershell();
-#endif
-
-/*
-**---------------------------------------------------------------------
-** Other #define's
-**---------------------------------------------------------------------
-*/
+#include "pcnfsd.h"
#define zchar 0x5b
char tempstr[256];
extern char sp_name[1024]; /* in pcnfsd_print.c */
-/*
-**=====================================================================
-** C O D E S E C T I O N * **=====================================================================
-*/
-/*
-**---------------------------------------------------------------------
-** Support procedures
-**---------------------------------------------------------------------
-*/
-
-
void
scramble(s1, s2)
-char *s1;
-char *s2;
+ char *s1, *s2;
{
- while (*s1)
- {
- *s2++ = (*s1 ^ zchar) & 0x7f;
- s1++;
- }
+ while (*s1) {
+ *s2++ = (*s1 ^ zchar) & 0x7f;
+ s1++;
+ }
*s2 = 0;
}
-
-
-struct passwd *
-get_password(usrnam)
-char *usrnam;
+struct passwd *
+get_password(user)
+ char *user;
{
-struct passwd *p;
-static struct passwd localp;
-char *pswd;
-char *ushell;
-int ok = 0;
+ struct passwd *pwd;
+ static struct passwd lpwd;
+ char *pass, *ushell;
+ int ok = 0;
+ if ((pwd = getpwnam(user)) == NULL)
+ return (NULL);
-#ifdef SHADOW_SUPPORT
-struct spwd *sp;
-int shadowfile;
-#endif
+ pass = pwd->pw_passwd;
-#ifdef SHADOW_SUPPORT
- /*
- **--------------------------------------------------------------
- ** Check the existence of SHADOW. If it is there, then we are
- ** running a two-password-file system.
- **--------------------------------------------------------------
- */
- if (access(SHADOW, 0))
- shadowfile = 0; /* SHADOW is not there */
- else
- shadowfile = 1;
-
- setpwent();
- if (shadowfile)
- (void) setspent(); /* Setting the shadow password
- * file */
- if ((p = getpwnam(usrnam)) == (struct passwd *)NULL ||
- (shadowfile && (sp = getspnam(usrnam)) == (struct spwd *)NULL))
- return ((struct passwd *)NULL);
-
- if (shadowfile)
- {
- pswd = sp->sp_pwdp;
- (void) endspent();
- }
- else
- pswd = p->pw_passwd;
-
-#else
- p = getpwnam(usrnam);
- if (p == (struct passwd *)NULL)
- return ((struct passwd *)NULL);
- pswd = p->pw_passwd;
-#endif
+ lpwd = *pwd;
+ lpwd.pw_passwd = pass;
-#ifdef ISC_2_0
- /*
- **-----------------------------------------------------------
- ** We may have an 'x' in which case look in /etc/shadow ..
- **-----------------------------------------------------------
- */
- if (((strlen(pswd)) == 1) && pswd[0] == 'x')
- {
- struct spwd *shadow = getspnam(usrnam);
-
- if (!shadow)
- return ((struct passwd *)NULL);
- pswd = shadow->sp_pwdp;
- }
-#endif
- localp = *p;
- localp.pw_passwd = pswd;
-#ifdef USE_GETUSERSHELL
-
- setusershell();
- while(ushell = getusershell()){
- if(!strcmp(ushell, localp.pw_shell)) {
- ok = 1;
- break;
- }
- }
- endusershell();
- if(!ok)
- return ((struct passwd *)NULL);
-#else
-/*
- * the best we can do is to ensure that the shell ends in "sh"
- */
- ushell = localp.pw_shell;
- if(strlen(ushell) < 2)
+ /*
+ * ensure that the shell ends in "sh" - probobly not worth it.
+ */
+ ushell = lpwd.pw_shell;
+ if (strlen(ushell) < 2)
return ((struct passwd *)NULL);
ushell += strlen(ushell) - 2;
- if(strcmp(ushell, "sh"))
+ if (strcmp(ushell, "sh"))
return ((struct passwd *)NULL);
-#endif
- return (&localp);
+ return (&lpwd);
}
-
/*
-**---------------------------------------------------------------------
-** Print support procedures
-**---------------------------------------------------------------------
-*/
+ *---------------------------------------------------------------------
+ * Print support procedures
+ *---------------------------------------------------------------------
+ */
char *
mapfont(f, i, b)
- char f;
- char i;
- char b;
+ char f, i, b;
{
- static char fontname[64];
+ static char fontname[64];
fontname[0] = 0; /* clear it out */
@@ -221,101 +114,26 @@ mapfont(f, i, b)
if (i == 'o') /* o-blique */
(void)strcat(fontname, f == 't' ? "Italic" : "Oblique");
-finis: return (&fontname[0]);
-}
-
-/*
- * run_ps630 performs the Diablo 630 emulation filtering process. ps630
- * was broken in certain Sun releases: it would not accept point size or
- * font changes. If your version is fixed, undefine the symbol
- * PS630_IS_BROKEN and rebuild pc-nfsd.
- */
-/* #define PS630_IS_BROKEN 1 */
-
-void
-run_ps630(f, opts)
- char *f;
- char *opts;
-{
- char temp_file[256];
- char commbuf[256];
- int i;
-
- (void)strcpy(temp_file, f);
- (void)strcat(temp_file, "X"); /* intermediate file name */
-
-#ifndef PS630_IS_BROKEN
- (void)snprintf(commbuf, sizeof commbuf, "ps630 -s %c%c -p %s -f ",
- opts[2], opts[3], temp_file);
- (void)strcat(commbuf, mapfont(opts[4], opts[5], opts[6]));
- (void)strcat(commbuf, " -F ");
- (void)strcat(commbuf, mapfont(opts[7], opts[8], opts[9]));
- (void)strcat(commbuf, " ");
- (void)strcat(commbuf, f);
-#else /* PS630_IS_BROKEN */
- /*
- * The pitch and font features of ps630 appear to be broken at
- * this time.
- */
- (void)snprintf(commbuf, sizeof commbuf, "ps630 -p %s %s", temp_file, f);
-#endif /* PS630_IS_BROKEN */
-
-
- if (i = system(commbuf)) {
- /*
- * Under (un)certain conditions, ps630 may return -1 even
- * if it worked. Hence the commenting out of this error
- * report.
- */
- /* (void)fprintf(stderr, "\n\nrun_ps630 rc = %d\n", i) */ ;
- /* exit(1); */
- }
- if (rename(temp_file, f)) {
- perror("run_ps630: rename");
- exit(1);
- }
- return;
+finis:
+ return (&fontname[0]);
}
-
-
-
-/*
-**---------------------------------------------------------------------
-** WTMP update support
-**---------------------------------------------------------------------
-*/
-
-
-#ifdef WTMP
-
-#include <utmp.h>
-
-#ifndef _PATH_WTMP
-#define _PATH_WTMP "/usr/adm/wtmp"
-#endif
-
void
wlogin(name, req)
char *name;
struct svc_req *req;
{
- extern char *inet_ntoa();
struct sockaddr_in *who;
struct hostent *hp;
char *host;
struct utmp ut;
int fd;
- if(!wtmp_enabled)
- return;
-
/* Get network address of client. */
who = &req->rq_xprt->xp_raddr;
/* Get name of connected client */
- hp = gethostbyaddr((char *)&who->sin_addr,
- sizeof (struct in_addr),
+ hp = gethostbyaddr((char *)&who->sin_addr, sizeof(struct in_addr),
who->sin_family);
if (hp && (strlen(hp->h_name) <= sizeof(ut.ut_host))) {
@@ -324,23 +142,22 @@ wlogin(name, req)
host = inet_ntoa(who->sin_addr);
}
- (void) strcpy(ut.ut_line, "PC-NFS");
- (void) strncpy(ut.ut_name,name,sizeof ut.ut_name);
- (void) strncpy(ut.ut_host, host, sizeof ut.ut_host);
- ut.ut_time = time( (time_t *) 0);
+ (void)strcpy(ut.ut_line, "PC-NFS");
+ (void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
+ (void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
+ (void)time(&ut.ut_time);
if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) >= 0) {
(void)write(fd, (char *)&ut, sizeof(struct utmp));
(void)close(fd);
}
}
-#endif /* WTMP */
-
+
/*
-**---------------------------------------------------------------------
-** Run-process-as-user procedures
-**---------------------------------------------------------------------
-*/
+ *---------------------------------------------------------------------
+ * Run-process-as-user procedures
+ *---------------------------------------------------------------------
+ */
#define READER_FD 0
@@ -359,16 +176,17 @@ static struct itimerval timer;
int interrupted = 0;
static FILE *pipe_handle;
-static void myhandler()
+static void
+myhandler()
{
- interrupted = 1;
- fclose(pipe_handle);
- kill(child_pid, SIGKILL);
- msg_out("rpc.pcnfsd: su_popen timeout - killed child process");
+ interrupted = 1;
+ (void)fclose(pipe_handle);
+ kill(child_pid, SIGKILL);
}
-void start_watchdog(n)
-int n;
+void
+start_watchdog(n)
+ int n;
{
/*
* Setup SIGALRM handler, force interrupt of ongoing syscall
@@ -391,7 +209,6 @@ int n;
timer.it_value.tv_usec = 0;
setitimer(ITIMER_REAL, &timer, NULL);
interrupted = 0;
-
}
void stop_watchdog()
@@ -414,7 +231,7 @@ void stop_watchdog()
-FILE *
+FILE *
su_popen(user, cmd, maxtime)
char *user;
char *cmd;
@@ -490,116 +307,17 @@ su_pclose(ptr)
return (pid == -1 ? -1 : status);
}
-
-/*
-** The following routine reads a file "/etc/pcnfsd.conf" if present,
-** and uses it to replace certain builtin elements, like the
-** name of the print spool directory. The configuration file
-** Is the usual kind: Comments begin with '#', blank lines are ignored,
-** and valid lines are of the form
-**
-** <keyword><whitespace><value>
-**
-** The following keywords are recognized:
-**
-** spooldir
-** printer name alias-for command
-** wtmp yes|no
-*/
-void
-config_from_file()
-{
-FILE *fd;
-char buff[1024];
-char *cp;
-char *kw;
-char *val;
-char *arg1;
-char *arg2;
-
- if((fd = fopen("/etc/pcnfsd.conf", "r")) == NULL)
- return;
- while(fgets(buff, 1024, fd)) {
- cp = strchr(buff, '\n');
- *cp = '\0';
- cp = strchr(buff, '#');
- if(cp)
- *cp = '\0';
- kw = strtok(buff, " \t");
- if(kw == NULL)
- continue;
- val = strtok(NULL, " \t");
- if(val == NULL)
- continue;
- if(!mystrcasecmp(kw, "spooldir")) {
- strcpy(sp_name, val);
- continue;
- }
-#ifdef WTMP
- if(!mystrcasecmp(kw, "wtmp")) {
- /* assume default is YES, just look for negatives */
- if(!mystrcasecmp(val, "no") ||
- !mystrcasecmp(val, "off") ||
- !mystrcasecmp(val, "disable") ||
- !strcmp(val, "0"))
- wtmp_enabled = 0;;
- continue;
- }
-#endif
- if(!mystrcasecmp(kw, "printer")) {
- arg1 = strtok(NULL, " \t");
- arg2 = strtok(NULL, "");
- (void)add_printer_alias(val, arg1, arg2);
- continue;
- }
-/*
-** Add new cases here
-*/
- }
- fclose(fd);
-}
-
-
/*
-** The following are replacements for the SunOS library
-** routines strcasecmp and strncasecmp, which SVR4 doesn't
-** include.
-*/
-
-mystrcasecmp(s1, s2)
- char *s1, *s2;
-{
-
- while (toupper(*s1) == toupper(*s2++))
- if (*s1++ == '\0')
- return(0);
- return(toupper(*s1) - toupper(*--s2));
-}
-
-mystrncasecmp(s1, s2, n)
+ * strembedded - returns true if s1 is embedded (in any case) in s2
+ */
+int
+strembedded(s1, s2)
char *s1, *s2;
- int n;
-{
-
- while (--n >= 0 && toupper(*s1) == toupper(*s2++))
- if (*s1++ == '\0')
- return(0);
- return(n < 0 ? 0 : toupper(*s1) - toupper(*--s2));
-}
-
-
-/*
-** strembedded - returns true if s1 is embedded (in any case) in s2
-*/
-
-int strembedded(s1, s2)
-char *s1;
-char *s2;
{
- while(*s2) {
- if(!mystrcasecmp(s1, s2))
- return 1;
+ while (*s2) {
+ if (!strcasecmp(s1, s2))
+ return (1);
s2++;
}
- return 0;
+ return (0);
}
diff --git a/usr.sbin/rpc.pcnfsd/pcnfsd_print.c b/usr.sbin/rpc.pcnfsd/pcnfsd_print.c
index 0382e5d41ba..f3fb87aede7 100644
--- a/usr.sbin/rpc.pcnfsd/pcnfsd_print.c
+++ b/usr.sbin/rpc.pcnfsd/pcnfsd_print.c
@@ -1,23 +1,13 @@
+/* $OpenBSD: pcnfsd_print.c,v 1.12 2001/08/19 19:16:12 ericj Exp $ */
/* $NetBSD: pcnfsd_print.c,v 1.3 1995/08/14 19:45:18 gwr Exp $ */
/* RE_SID: @(%)/usr/dosnfs/shades_SCCS/unix/pcnfsd/v2/src/SCCS/s.pcnfsd_print.c 1.7 92/01/24 19:58:58 SMI */
/*
-**=====================================================================
-** Copyright (c) 1986,1987,1988,1989,1990,1991 by Sun Microsystems, Inc.
-** @(#)pcnfsd_print.c 1.7 1/24/92
-**=====================================================================
-*/
-#include "common.h"
-/*
-**=====================================================================
-** I N C L U D E F I L E S E C T I O N *
-** *
-** If your port requires different include files, add a suitable *
-** #define in the customization section, and make the inclusion or *
-** exclusion of the files conditional on this. *
-**=====================================================================
-*/
-#include "pcnfsd.h"
+ *=====================================================================
+ * Copyright (c) 1986,1987,1988,1989,1990,1991 by Sun Microsystems, Inc.
+ * @(#)pcnfsd_print.c 1.7 1/24/92
+ *=====================================================================
+ */
#include <stdlib.h>
#include <stdio.h>
#include <pwd.h>
@@ -29,30 +19,10 @@
#include <errno.h>
#include <string.h>
-#ifndef SYSV
-#include <sys/wait.h>
-#endif
-
-#ifdef ISC_2_0
-#include <sys/fcntl.h>
-#endif
-
-#ifdef SHADOW_SUPPORT
-#include <shadow.h>
-#endif
-
+#include "pcnfsd.h"
#include "paths.h"
/*
-**---------------------------------------------------------------------
-** Other #define's
-**---------------------------------------------------------------------
-*/
-#ifndef MAXPATHLEN
-#define MAXPATHLEN 1024
-#endif
-
-/*
** The following defintions give the maximum time allowed for
** an external command to run (in seconds)
*/
@@ -69,25 +39,13 @@
#define SIZECOL 62
#define FILECOL 24
-extern void scramble();
-extern void run_ps630();
-extern char *crypt();
-extern FILE *su_popen();
-extern int su_pclose();
int build_pr_list();
char *map_printer_name();
char *expand_alias();
-void *grab();
void free_pr_list_item();
void free_pr_queue_item();
pr_list list_virtual_printers();
-/*
-**---------------------------------------------------------------------
-** Misc. variable definitions
-**---------------------------------------------------------------------
-*/
-
extern int interrupted; /* in pcnfsd_misc.c */
struct stat statbuf;
char pathname[MAXPATHLEN];
@@ -96,56 +54,48 @@ char sp_name[MAXPATHLEN] = SPOOLDIR;
char tempstr[256];
char delims[] = " \t\r\n:()";
-pr_list printers = NULL;
-pr_queue queue = NULL;
-
-/*
-**=====================================================================
-** C O D E S E C T I O N *
-**=====================================================================
-*/
-
/*
* This is the latest word on the security check. The following
* routine "suspicious()" returns non-zero if the character string
* passed to it contains any shell metacharacters.
* Callers will typically code
*
- * if(suspicious(some_parameter)) reject();
+ * if (suspicious(some_parameter)) reject();
*/
-
-int suspicious (s)
-char *s;
+int
+suspicious(s)
+ char *s;
{
- if(strpbrk(s, ";|&<>`'#!?*()[]^/${}\n\r\"\\:") != NULL)
+ if (strpbrk(s, ";|&<>`'#!?*()[]^/${}\n\r\"\\:") != NULL)
return 1;
return 0;
}
-
int
valid_pr(pr)
char *pr;
{
-char *p;
-pr_list curr;
- if(printers == NULL)
+ char *p;
+ pr_list curr;
+
+ if (printers == NULL)
build_pr_list();
- if(printers == NULL)
- return(1); /* can't tell - assume it's good */
+ /* XXX */
+ if (printers == NULL)
+ return (1); /* can't tell - assume it's good */
p = map_printer_name(pr);
if (p == NULL)
- return(1); /* must be ok is maps to NULL! */
+ return (1); /* must be ok is maps to NULL! */
+
curr = printers;
- while(curr) {
- if(!strcmp(p, curr->pn))
- return(1);
+ while (curr) {
+ if (!strcmp(p, curr->pn))
+ return (1);
curr = curr->pr_next;
}
-
- return(0);
+ return (0);
}
/*
@@ -155,20 +105,19 @@ pr_list curr;
* As described in CERT advisory CA-96.08, be careful about
* doing a chmod on something that could be a symlink...
*/
-pirstat pr_init(sys, pr, sp)
-char *sys;
-char *pr;
-char**sp;
+pirstat
+pr_init(sys, pr, sp)
+ char *sys, *pr, **sp;
{
- int dir_mode = 0777;
+ int dir_mode = 0777;
int rc;
mode_t oldmask;
*sp = &pathname[0];
pathname[0] = '\0';
- if(suspicious(sys) || suspicious(pr))
- return(PI_RES_FAIL);
+ if (suspicious(sys) || suspicious(pr))
+ return (PI_RES_FAIL);
/*
* Create the client spool directory if needed.
@@ -180,7 +129,7 @@ char**sp;
rc = mkdir(pathname, dir_mode); /* DON'T ignore this return code */
umask(oldmask);
- if((rc < 0 && errno != EEXIST) ||
+ if ((rc < 0 && errno != EEXIST) ||
(stat(pathname, &statbuf) != 0) ||
!(statbuf.st_mode & S_IFDIR)) {
(void)snprintf(tempstr, sizeof tempstr,
@@ -188,109 +137,63 @@ char**sp;
pathname);
msg_out(tempstr);
pathname[0] = '\0'; /* null to tell client bad vibes */
- return(PI_RES_FAIL);
+ return (PI_RES_FAIL);
}
/* OK, we have a spool directory. */
if (!valid_pr(pr)) {
pathname[0] = '\0'; /* null to tell client bad vibes */
- return(PI_RES_NO_SUCH_PRINTER);
+ return (PI_RES_NO_SUCH_PRINTER);
}
- return(PI_RES_OK);
+ return (PI_RES_OK);
}
-
-psrstat pr_start2(system, pr, user, fname, opts, id)
-char *system;
-char *pr;
-char *user;
-char *fname;
-char *opts;
-char **id;
+psrstat
+pr_start2(system, pr, user, fname, opts, id)
+ char *system, *pr, *user, *fname, *opts;
+ char **id;
{
-static char req_id[256];
-char cmdbuf[256];
-char resbuf[256];
-FILE *fd;
-int i;
-char *xcmd;
-int failed = 0;
-
-#ifdef HACK_FOR_ROTATED_TRANSCRIPT
-char scratch[512];
-#endif
+ static char req_id[256];
+ char cmdbuf[256], resbuf[256];
+ FILE *fp;
+ int i, failed = 0;
+ char *xcmd;
+ if (suspicious(system) || suspicious(pr) || suspicious(user) ||
+ suspicious(fname))
+ return (PS_RES_FAIL);
- if(suspicious(system) ||
- suspicious(pr) ||
- suspicious(user) ||
- suspicious(fname))
- return(PS_RES_FAIL);
-
- (void)snprintf(pathname, sizeof pathname, "%s/%s/%s",sp_name,
- system,
- fname);
+ (void)snprintf(pathname, sizeof(pathname), "%s/%s/%s", sp_name,
+ system, fname);
*id = &req_id[0];
req_id[0] = '\0';
- if (stat(pathname, &statbuf))
- {
- /*
- **-----------------------------------------------------------------
- ** We can't stat the file. Let's try appending '.spl' and
- ** see if it's already in progress.
- **-----------------------------------------------------------------
- */
-
- (void)strcat(pathname, ".spl");
- if (stat(pathname, &statbuf))
- {
- /*
- **----------------------------------------------------------------
- ** It really doesn't exist.
- **----------------------------------------------------------------
- */
-
-
- return(PS_RES_NO_FILE);
- }
- /*
- **-------------------------------------------------------------
- ** It is already on the way.
- **-------------------------------------------------------------
- */
-
-
- return(PS_RES_ALREADY);
- }
-
- if (statbuf.st_size == 0)
- {
- /*
- **-------------------------------------------------------------
- ** Null file - don't print it, just kill it.
- **-------------------------------------------------------------
- */
+ if (stat(pathname, &statbuf)) {
+ (void)strcat(pathname, ".spl");
+ if (stat(pathname, &statbuf))
+ return (PS_RES_NO_FILE);
+ return (PS_RES_ALREADY);
+ }
+
+ if (statbuf.st_size == 0) {
(void)unlink(pathname);
+ return (PS_RES_NULL);
+ }
- return(PS_RES_NULL);
- }
- /*
- **-------------------------------------------------------------
- ** The file is real, has some data, and is not already going out.
- ** We rename it by appending '.spl' and exec "lpr" to do the
- ** actual work.
- **-------------------------------------------------------------
+ /*
+ * The file is real, has some data, and is not already going out.
+ * rename it by appending '.spl' and exec "lpr" to do the
+ * actual work.
*/
- if (snprintf(new_pathname, sizeof new_pathname, "%s.spl",
- pathname) >= sizeof new_pathname) {
+ if (snprintf(new_pathname, sizeof new_pathname, "%s.spl", pathname)
+ >= sizeof new_pathname) {
snprintf(tempstr, sizeof tempstr,
"rpc.pcnfsd: spool file rename (%s->%s) failed.\n",
pathname, new_pathname);
msg_out(tempstr);
- return(PS_RES_FAIL);
+ return (PS_RES_FAIL);
}
/*
@@ -298,8 +201,6 @@ char scratch[512];
** See if the new filename exists so as not to overwrite it.
**-------------------------------------------------------------
*/
-
-
if (!stat(new_pathname, &statbuf)) {
if (snprintf(new_pathname, sizeof new_pathname, "%s%d.spl",
rand(), pathname) >= sizeof new_pathname) {
@@ -307,7 +208,7 @@ char scratch[512];
"rpc.pcnfsd: spool file rename (%s->%s) failed.\n",
pathname, new_pathname);
msg_out(tempstr);
- return(PS_RES_FAIL);
+ return (PS_RES_FAIL);
}
}
if (rename(pathname, new_pathname))
@@ -321,7 +222,7 @@ char scratch[512];
"rpc.pcnfsd: spool file rename (%s->%s) failed.\n",
pathname, new_pathname);
msg_out(tempstr);
- return(PS_RES_FAIL);
+ return (PS_RES_FAIL);
}
if (*opts == 'd')
@@ -335,48 +236,38 @@ char scratch[512];
(void)snprintf(tempstr, sizeof tempstr,
"rpc.pcnfsd: ps630 filter disabled for %s\n", pathname);
msg_out(tempstr);
- return(PS_RES_FAIL);
+ return (PS_RES_FAIL);
}
/*
** Try to match to an aliased printer
*/
xcmd = expand_alias(pr, new_pathname, user, system);
- if(!xcmd) {
-#ifdef SVR4
- /*
- * Use the copy option so we can remove the orignal
- * spooled nfs file from the spool directory.
- */
- snprintf(cmdbuf, sizeof cmdbuf, "/usr/bin/lp -c -d%s %s",
- pr, new_pathname);
-#else /* SVR4 */
+ if (!xcmd) {
/* BSD way: lpr */
snprintf(cmdbuf, sizeof cmdbuf, "%s/lpr '-P%s' '%s'",
LPRDIR, pr, new_pathname);
-#endif /* SVR4 */
xcmd = cmdbuf;
}
- if ((fd = su_popen(user, xcmd, MAXTIME_FOR_PRINT)) == NULL) {
+ if ((fp = su_popen(user, xcmd, MAXTIME_FOR_PRINT)) == NULL) {
msg_out("rpc.pcnfsd: su_popen failed");
- return(PS_RES_FAIL);
+ return (PS_RES_FAIL);
}
req_id[0] = '\0'; /* asume failure */
- while(fgets(resbuf, 255, fd) != NULL) {
+ while (fgets(resbuf, 255, fp) != NULL) {
i = strlen(resbuf);
- if(i)
+ if (i)
resbuf[i-1] = '\0'; /* trim NL */
- if(!strncmp(resbuf, "request id is ", 14))
+ if (!strncmp(resbuf, "request id is ", 14))
/* New - just the first word is needed */
strcpy(req_id, strtok(&resbuf[14], delims));
else if (strembedded("disabled", resbuf))
failed = 1;
}
- if(su_pclose(fd) == 255)
+ if (su_pclose(fp) == 255)
msg_out("rpc.pcnfsd: su_pclose alert");
(void)unlink(new_pathname);
- return((failed | interrupted)? PS_RES_FAIL : PS_RES_OK);
+ return ((failed | interrupted)? PS_RES_FAIL : PS_RES_OK);
}
-
/*
* build_pr_list: determine which printers are valid.
@@ -384,159 +275,6 @@ char scratch[512];
* on BSD use "lpc status"
*/
-#ifdef SVR4
-/*
- * In SVR4 the command to determine which printers are
- * valid is lpstat -v. The output is something like this:
- *
- * device for lp: /dev/lp0
- * system for pcdslw: hinode
- * system for bletch: hinode (as printer hisname)
- *
- * On SunOS using the SysV compatibility package, the output
- * is more like:
- *
- * device for lp is /dev/lp0
- * device for pcdslw is the remote printer pcdslw on hinode
- * device for bletch is the remote printer hisname on hinode
- *
- * It is fairly simple to create logic that will handle either
- * possibility:
- */
-int
-build_pr_list()
-{
- pr_list last = NULL;
- pr_list curr = NULL;
- char buff[256];
- FILE *p;
- char *cp;
- int saw_system;
-
- p = popen("lpstat -v", "r");
- if(p == NULL) {
- msg_out("rpc.pcnfsd: unable to popen() lp status");
- return(0);
- }
-
- while(fgets(buff, 255, p) != NULL) {
- cp = strtok(buff, delims);
- if(!cp)
- continue;
- if(!strcmp(cp, "device"))
- saw_system = 0;
- else if (!strcmp(cp, "system"))
- saw_system = 1;
- else
- continue;
- cp = strtok(NULL, delims);
- if(!cp || strcmp(cp, "for"))
- continue;
- cp = strtok(NULL, delims);
- if(!cp)
- continue;
- curr = (struct pr_list_item *)
- grab(sizeof (struct pr_list_item));
-
- curr->pn = strdup(cp);
- curr->device = NULL;
- curr->remhost = NULL;
- curr->cm = strdup("-");
- curr->pr_next = NULL;
-
- cp = strtok(NULL, delims);
-
- if(cp && !strcmp(cp, "is"))
- cp = strtok(NULL, delims);
-
- if(!cp) {
- free_pr_list_item(curr);
- continue;
- }
-
- if(saw_system) {
- /* "system" OR "system (as printer pname)" */
- curr->remhost = strdup(cp);
- cp = strtok(NULL, delims);
- if(!cp) {
- /* simple format */
- curr->device = strdup(curr->pn);
- } else {
- /* "sys (as printer pname)" */
- if (strcmp(cp, "as")) {
- free_pr_list_item(curr);
- continue;
- }
- cp = strtok(NULL, delims);
- if (!cp || strcmp(cp, "printer")) {
- free_pr_list_item(curr);
- continue;
- }
- cp = strtok(NULL, delims);
- if(!cp) {
- free_pr_list_item(curr);
- continue;
- }
- curr->device = strdup(cp);
- }
- }
- else if(!strcmp(cp, "the")) {
- /* start of "the remote printer foo on bar" */
- cp = strtok(NULL, delims);
- if(!cp || strcmp(cp, "remote")) {
- free_pr_list_item(curr);
- continue;
- }
- cp = strtok(NULL, delims);
- if(!cp || strcmp(cp, "printer")) {
- free_pr_list_item(curr);
- continue;
- }
- cp = strtok(NULL, delims);
- if(!cp) {
- free_pr_list_item(curr);
- continue;
- }
- curr->device = strdup(cp);
- cp = strtok(NULL, delims);
- if(!cp || strcmp(cp, "on")) {
- free_pr_list_item(curr);
- continue;
- }
- cp = strtok(NULL, delims);
- if(!cp) {
- free_pr_list_item(curr);
- continue;
- }
- curr->remhost = strdup(cp);
- } else {
- /* the local name */
- curr->device = strdup(cp);
- curr->remhost = strdup("");
- }
-
- if(last == NULL)
- printers = curr;
- else
- last->pr_next = curr;
- last = curr;
-
- }
- (void) pclose(p);
-
- /*
- ** Now add on the virtual printers, if any
- */
- if(last == NULL)
- printers = list_virtual_printers();
- else
- last->pr_next = list_virtual_printers();
-
- return(1);
-}
-
-#else /* SVR4 */
-
/*
* BSD way: lpc stat
*/
@@ -552,12 +290,12 @@ build_pr_list()
snprintf(buff, sizeof buff, "%s/lpc status", LPCDIR);
p = popen(buff, "r");
- if(p == NULL) {
+ if (p == NULL) {
msg_out("rpc.pcnfsd: unable to popen lpc stat");
- return(0);
+ return (0);
}
- while(fgets(buff, 255, p) != NULL) {
+ while (fgets(buff, 255, p) != NULL) {
if (isspace(buff[0]))
continue;
@@ -574,7 +312,7 @@ build_pr_list()
curr->cm = strdup("-");
curr->pr_next = NULL;
- if(last == NULL)
+ if (last == NULL)
printers = curr;
else
last->pr_next = curr;
@@ -586,42 +324,41 @@ build_pr_list()
/*
** Now add on the virtual printers, if any
*/
- if(last == NULL)
+ if (last == NULL)
printers = list_virtual_printers();
else
last->pr_next = list_virtual_printers();
- return(1);
+ return (1);
}
-#endif /* SVR4 */
-
-void *grab(n)
-int n;
+void *
+grab(n)
+ int n;
{
void *p;
p = (void *)malloc(n);
- if(p == NULL) {
+ if (p == NULL) {
msg_out("rpc.pcnfsd: malloc failure");
exit(1);
}
- return(p);
+ return (p);
}
void
free_pr_list_item(curr)
pr_list curr;
{
- if(curr->pn)
+ if (curr->pn)
free(curr->pn);
- if(curr->device)
+ if (curr->device)
free(curr->device);
- if(curr->remhost)
+ if (curr->remhost)
free(curr->remhost);
- if(curr->cm)
+ if (curr->cm)
free(curr->cm);
- if(curr->pr_next)
+ if (curr->pr_next)
free_pr_list_item(curr->pr_next); /* recurse */
free(curr);
}
@@ -632,114 +369,6 @@ pr_list curr;
* Note that the first thing we do is to discard any
* existing queue.
*/
-#ifdef SVR4
-
-/*
-** In SVR4 the command to list the print jobs for printer
-** lp is "lpstat lp" (or, equivalently, "lpstat -p lp").
-** The output looks like this:
-**
-** lp-2 root 939 Jul 10 21:56
-** lp-5 geoff 15 Jul 12 23:23
-** lp-6 geoff 15 Jul 12 23:23
-**
-** If the first job is actually printing the first line
-** is modified, as follows:
-**
-** lp-2 root 939 Jul 10 21:56 on lp
-**
-** I don't yet have any info on what it looks like if the printer
-** is remote and we're spooling over the net. However for
-** the purposes of rpc.pcnfsd we can simply say that field 1 is the
-** job ID, field 2 is the submitter, and field 3 is the size.
-** We can check for the presence of the string " on " in the
-** first record to determine if we should count it as rank 0 or rank 1,
-** but it won't hurt if we get it wrong.
-**/
-
-pirstat
-build_pr_queue(pn, user, just_mine, p_qlen, p_qshown)
-printername pn;
-username user;
-int just_mine;
-int *p_qlen;
-int *p_qshown;
-{
-pr_queue last = NULL;
-pr_queue curr = NULL;
-char buff[256];
-FILE *p;
-char *owner;
-char *job;
-char *totsize;
-
- if(queue) {
- free_pr_queue_item(queue);
- queue = NULL;
- }
- *p_qlen = 0;
- *p_qshown = 0;
-
- pn = map_printer_name(pn);
- if(pn == NULL || !valid_pr(pn) || suspicious(pn))
- return(PI_RES_NO_SUCH_PRINTER);
-
- snprintf(buff, sizeof buff, "/usr/bin/lpstat %s", pn);
- p = su_popen(user, buff, MAXTIME_FOR_QUEUE);
- if(p == NULL) {
- msg_out("rpc.pcnfsd: unable to popen() lpstat queue query");
- return(PI_RES_FAIL);
- }
-
- while(fgets(buff, 255, p) != NULL) {
- job = strtok(buff, delims);
- if(!job)
- continue;
-
- owner = strtok(NULL, delims);
- if(!owner)
- continue;
-
- totsize = strtok(NULL, delims);
- if(!totsize)
- continue;
-
- *p_qlen += 1;
-
- if(*p_qshown > QMAX)
- continue;
-
- if(just_mine && mystrcasecmp(owner, user))
- continue;
-
- *p_qshown += 1;
-
- curr = (struct pr_queue_item *)
- grab(sizeof (struct pr_queue_item));
-
- curr->position = *p_qlen;
- curr->id = strdup(job);
- curr->size = strdup(totsize);
- curr->status = strdup("");
- curr->system = strdup("");
- curr->user = strdup(owner);
- curr->file = strdup("");
- curr->cm = strdup("-");
- curr->pr_next = NULL;
-
- if(last == NULL)
- queue = curr;
- else
- last->pr_next = curr;
- last = curr;
-
- }
- (void) su_pclose(p);
- return(PI_RES_OK);
-}
-
-#else /* SVR4 */
-
pirstat
build_pr_queue(pn, user, just_mine, p_qlen, p_qshown)
printername pn;
@@ -760,62 +389,62 @@ char *job;
char *files;
char *totsize;
- if(queue) {
+ if (queue) {
free_pr_queue_item(queue);
queue = NULL;
}
*p_qlen = 0;
*p_qshown = 0;
pn = map_printer_name(pn);
- if(pn == NULL || suspicious(pn))
- return(PI_RES_NO_SUCH_PRINTER);
+ if (pn == NULL || suspicious(pn))
+ return (PI_RES_NO_SUCH_PRINTER);
snprintf(buff, sizeof buff, "%s/lpq '-P%s'", LPRDIR, pn);
p = su_popen(user, buff, MAXTIME_FOR_QUEUE);
- if(p == NULL) {
+ if (p == NULL) {
msg_out("rpc.pcnfsd: unable to popen() lpq");
- return(PI_RES_FAIL);
+ return (PI_RES_FAIL);
}
- while(fgets(buff, 255, p) != NULL) {
+ while (fgets(buff, 255, p) != NULL) {
i = strlen(buff) - 1;
buff[i] = '\0'; /* zap trailing NL */
- if(i < SIZECOL)
+ if (i < SIZECOL)
continue;
- if(!mystrncasecmp(buff, "rank", 4))
+ if (!strncasecmp(buff, "rank", 4))
continue;
totsize = &buff[SIZECOL-1];
files = &buff[FILECOL-1];
cp = totsize;
cp--;
- while(cp > files && isspace(*cp))
+ while (cp > files && isspace(*cp))
*cp-- = '\0';
buff[FILECOL-2] = '\0';
cp = strtok(buff, delims);
- if(!cp)
+ if (!cp)
continue;
rank = cp;
cp = strtok(NULL, delims);
- if(!cp)
+ if (!cp)
continue;
owner = cp;
cp = strtok(NULL, delims);
- if(!cp)
+ if (!cp)
continue;
job = cp;
*p_qlen += 1;
- if(*p_qshown > QMAX)
+ if (*p_qshown > QMAX)
continue;
- if(just_mine && mystrcasecmp(owner, user))
+ if (just_mine && strcasecmp(owner, user))
continue;
*p_qshown += 1;
@@ -833,7 +462,7 @@ char *totsize;
curr->cm = strdup("-");
curr->pr_next = NULL;
- if(last == NULL)
+ if (last == NULL)
queue = curr;
else
last->pr_next = curr;
@@ -841,144 +470,32 @@ char *totsize;
}
(void) su_pclose(p);
- return(PI_RES_OK);
+ return (PI_RES_OK);
}
-#endif /* SVR4 */
-
void
free_pr_queue_item(curr)
pr_queue curr;
{
- if(curr->id)
+ if (curr->id)
free(curr->id);
- if(curr->size)
+ if (curr->size)
free(curr->size);
- if(curr->status)
+ if (curr->status)
free(curr->status);
- if(curr->system)
+ if (curr->system)
free(curr->system);
- if(curr->user)
+ if (curr->user)
free(curr->user);
- if(curr->file)
+ if (curr->file)
free(curr->file);
- if(curr->cm)
+ if (curr->cm)
free(curr->cm);
- if(curr->pr_next)
+ if (curr->pr_next)
free_pr_queue_item(curr->pr_next); /* recurse */
free(curr);
}
-#ifdef SVR4
-
-/*
-** New - SVR4 printer status handling.
-**
-** The command we'll use for checking the status of printer "lp"
-** is "lpstat -a lp -p lp". Here are some sample outputs:
-**
-**
-** lp accepting requests since Wed Jul 10 21:49:25 EDT 1991
-** printer lp disabled since Thu Feb 21 22:52:36 EST 1991. available.
-** new printer
-** ---
-** pcdslw not accepting requests since Fri Jul 12 22:30:00 EDT 1991 -
-** unknown reason
-** printer pcdslw disabled since Fri Jul 12 22:15:37 EDT 1991. available.
-** new printer
-** ---
-** lp accepting requests since Wed Jul 10 21:49:25 EDT 1991
-** printer lp now printing lp-2. enabled since Sat Jul 13 12:02:17 EDT 1991. available.
-** ---
-** lp accepting requests since Wed Jul 10 21:49:25 EDT 1991
-** printer lp now printing lp-2. enabled since Sat Jul 13 12:02:17 EDT 1991. available.
-** ---
-** lp accepting requests since Wed Jul 10 21:49:25 EDT 1991
-** printer lp disabled since Sat Jul 13 12:05:20 EDT 1991. available.
-** unknown reason
-** ---
-** pcdslw not accepting requests since Fri Jul 12 22:30:00 EDT 1991 -
-** unknown reason
-** printer pcdslw is idle. enabled since Sat Jul 13 12:05:28 EDT 1991. available.
-**
-** Note that these are actual outputs. The format (which is totally
-** different from the lpstat in SunOS) seems to break down as
-** follows:
-** (1) The first line has the form "printername [not] accepting requests,,,"
-** This is trivial to decode.
-** (2) The second line has several forms, all beginning "printer printername":
-** (2.1) "... disabled"
-** (2.2) "... is idle"
-** (2.3) "... now printing jobid"
-** The "available" comment seems to be meaningless. The next line
-** is the "reason" code which the operator can supply when issuing
-** a "disable" or "reject" command.
-** Note that there is no way to check the number of entries in the
-** queue except to ask for the queue and count them.
-*/
-
-pirstat
-get_pr_status(pn, avail, printing, qlen, needs_operator, status)
-printername pn;
-bool_t *avail;
-bool_t *printing;
-int *qlen;
-bool_t *needs_operator;
-char *status;
-{
-char buff[256];
-char cmd[64];
-FILE *p;
-int n;
-pirstat stat = PI_RES_NO_SUCH_PRINTER;
-
- /* assume the worst */
- *avail = FALSE;
- *printing = FALSE;
- *needs_operator = FALSE;
- *qlen = 0;
- *status = '\0';
-
- pn = map_printer_name(pn);
- if(pn == NULL || !valid_pr(pn) || suspicious(pn))
- return(PI_RES_NO_SUCH_PRINTER);
- n = strlen(pn);
-
- snprintf(cmd, sizeof cmd, "/usr/bin/lpstat -a %s -p %s", pn, pn);
-
- p = popen(cmd, "r");
- if(p == NULL) {
- msg_out("rpc.pcnfsd: unable to popen() lp status");
- return(PI_RES_FAIL);
- }
-
- stat = PI_RES_OK;
-
- while(fgets(buff, 255, p) != NULL) {
- if(!strncmp(buff, pn, n)) {
- if(!strstr(buff, "not accepting"))
- *avail = TRUE;
- continue;
- }
- if(!strncmp(buff, "printer ", 8)) {
- if(!strstr(buff, "disabled"))
- *printing = TRUE;
- if(strstr(buff, "printing"))
- strcpy(status, "printing");
- else if (strstr(buff, "idle"))
- strcpy(status, "idle");
- continue;
- }
- if(!strncmp(buff, "UX:", 3)) {
- stat = PI_RES_NO_SUCH_PRINTER;
- }
- }
- (void) pclose(p);
- return(stat);
-}
-
-#else /* SVR4 */
-
/*
* BSD way: lpc status
*/
@@ -1010,21 +527,21 @@ char *status;
*status = '\0';
pn = map_printer_name(pn);
- if(pn == NULL || suspicious(pn) || !valid_pr(pn))
- return(PI_RES_NO_SUCH_PRINTER);
+ if (pn == NULL || suspicious(pn) || !valid_pr(pn))
+ return (PI_RES_NO_SUCH_PRINTER);
snprintf(pname, sizeof pname, "%s:", pn);
n = strlen(pname);
snprintf(cmd, sizeof cmd, "%s/lpc status '%s'", LPCDIR, pn);
p = popen(cmd, "r");
- if(p == NULL) {
+ if (p == NULL) {
msg_out("rpc.pcnfsd: unable to popen() lp status");
- return(PI_RES_FAIL);
+ return (PI_RES_FAIL);
}
- while(fgets(buff, 255, p) != NULL) {
- if(strncmp(buff, pname, n))
+ while (fgets(buff, 255, p) != NULL) {
+ if (strncmp(buff, pname, n))
continue;
/*
** We have a match. The only failure now is PI_RES_FAIL if
@@ -1039,11 +556,11 @@ char *status;
** [no entries | N entr[y|ies] in spool area]
** <status message, may include the word "attention">
*/
- while(fgets(buff, 255, p) != NULL && isspace(buff[0])) {
+ while (fgets(buff, 255, p) != NULL && isspace(buff[0])) {
cp = buff;
- while(isspace(*cp))
+ while (isspace(*cp))
cp++;
- if(*cp == '\0')
+ if (*cp == '\0')
break;
cp1 = cp;
cp2 = buff2;
@@ -1058,23 +575,23 @@ char *status;
** Now buff2 has a lower-cased copy and cp points at the original;
** both are null terminated without any newline
*/
- if(!strncmp(buff2, "queuing", 7)) {
+ if (!strncmp(buff2, "queuing", 7)) {
*avail = (strstr(buff2, "enabled") != NULL);
continue;
}
- if(!strncmp(buff2, "printing", 8)) {
+ if (!strncmp(buff2, "printing", 8)) {
*printing = (strstr(buff2, "enabled") != NULL);
continue;
}
- if(isdigit(buff2[0]) && (strstr(buff2, "entr") !=NULL)) {
+ if (isdigit(buff2[0]) && (strstr(buff2, "entr") !=NULL)) {
*qlen = atoi(buff2);
continue;
}
- if(strstr(buff2, "attention") != NULL ||
+ if (strstr(buff2, "attention") != NULL ||
strstr(buff2, "error") != NULL)
*needs_operator = TRUE;
- if(*needs_operator || strstr(buff2, "waiting") != NULL) {
+ if (*needs_operator || strstr(buff2, "waiting") != NULL) {
strncpy(status, cp, 127);
status[127] = '\0';
}
@@ -1083,11 +600,9 @@ char *status;
break;
}
(void) pclose(p);
- return(stat);
+ return (stat);
}
-#endif /* SVR4 */
-
/*
* pr_cancel: cancel a print job
*/
@@ -1134,32 +649,32 @@ FILE *fd;
pcrstat stat = PC_RES_NO_SUCH_JOB;
pr = map_printer_name(pr);
- if(pr == NULL || suspicious(pr))
- return(PC_RES_NO_SUCH_PRINTER);
- if(suspicious(id))
- return(PC_RES_NO_SUCH_JOB);
+ if (pr == NULL || suspicious(pr))
+ return (PC_RES_NO_SUCH_PRINTER);
+ if (suspicious(id))
+ return (PC_RES_NO_SUCH_JOB);
snprintf(cmdbuf, sizeof cmdbuf, "/usr/bin/cancel %s", id);
if ((fd = su_popen(user, cmdbuf, MAXTIME_FOR_CANCEL)) == NULL) {
msg_out("rpc.pcnfsd: su_popen failed");
- return(PC_RES_FAIL);
+ return (PC_RES_FAIL);
}
- if(fgets(resbuf, 255, fd) == NULL)
+ if (fgets(resbuf, 255, fd) == NULL)
stat = PC_RES_FAIL;
- else if(!strstr(resbuf, "UX:"))
+ else if (!strstr(resbuf, "UX:"))
stat = PC_RES_OK;
- else if(strstr(resbuf, "doesn't exist"))
+ else if (strstr(resbuf, "doesn't exist"))
stat = PC_RES_NO_SUCH_JOB;
- else if(strstr(resbuf, "not a request id"))
+ else if (strstr(resbuf, "not a request id"))
stat = PC_RES_NO_SUCH_JOB;
- else if(strstr(resbuf, "Can't cancel request"))
+ else if (strstr(resbuf, "Can't cancel request"))
stat = PC_RES_NOT_OWNER;
else stat = PC_RES_FAIL;
- if(su_pclose(fd) == 255)
+ if (su_pclose(fd) == 255)
msg_out("rpc.pcnfsd: su_pclose alert");
- return(stat);
+ return (stat);
}
#else /* SVR4 */
@@ -1179,31 +694,31 @@ char *id;
pcrstat stat = PC_RES_NO_SUCH_JOB;
pr = map_printer_name(pr);
- if(pr == NULL || suspicious(pr))
- return(PC_RES_NO_SUCH_PRINTER);
- if(suspicious(id))
- return(PC_RES_NO_SUCH_JOB);
+ if (pr == NULL || suspicious(pr))
+ return (PC_RES_NO_SUCH_PRINTER);
+ if (suspicious(id))
+ return (PC_RES_NO_SUCH_JOB);
snprintf(cmdbuf, sizeof cmdbuf, "%s/lprm '-P%s' '%s'",
LPRDIR, pr, id);
if ((fd = su_popen(user, cmdbuf, MAXTIME_FOR_CANCEL)) == NULL) {
msg_out("rpc.pcnfsd: su_popen failed");
- return(PC_RES_FAIL);
+ return (PC_RES_FAIL);
}
- while(fgets(resbuf, 255, fd) != NULL) {
+ while (fgets(resbuf, 255, fd) != NULL) {
i = strlen(resbuf);
- if(i)
+ if (i)
resbuf[i-1] = '\0'; /* trim NL */
- if(strstr(resbuf, "dequeued") != NULL)
+ if (strstr(resbuf, "dequeued") != NULL)
stat = PC_RES_OK;
- if(strstr(resbuf, "unknown printer") != NULL)
+ if (strstr(resbuf, "unknown printer") != NULL)
stat = PC_RES_NO_SUCH_PRINTER;
- if(strstr(resbuf, "Permission denied") != NULL)
+ if (strstr(resbuf, "Permission denied") != NULL)
stat = PC_RES_NOT_OWNER;
}
- if(su_pclose(fd) == 255)
+ if (su_pclose(fd) == 255)
msg_out("rpc.pcnfsd: su_pclose alert");
- return(stat);
+ return (stat);
}
#endif /* SVR4 */
@@ -1267,11 +782,11 @@ char *printer;
char *alias_for;
char *command;
{
- if(num_aliases < NPRINTERDEFS) {
+ if (num_aliases < NPRINTERDEFS) {
alias[num_aliases].a_printer = strdup(printer);
alias[num_aliases].a_alias_for =
(strcmp(alias_for, "-") ? strdup(alias_for) : NULL);
- if(strstr(command, "$FILE"))
+ if (strstr(command, "$FILE"))
alias[num_aliases].a_command = strdup(command);
else {
alias[num_aliases].a_command = (char *)grab(strlen(command) + 8);
@@ -1290,54 +805,51 @@ pr_list curr = NULL;
int i;
- if(num_aliases == 0)
- return(NULL);
+ if (num_aliases == 0)
+ return (NULL);
for (i = 0; i < num_aliases; i++) {
curr = (struct pr_list_item *)
grab(sizeof (struct pr_list_item));
curr->pn = strdup(alias[i].a_printer);
- if(alias[i].a_alias_for == NULL)
+ if (alias[i].a_alias_for == NULL)
curr->device = strdup("");
else
curr->device = strdup(alias[i].a_alias_for);
curr->remhost = strdup("");
curr->cm = strdup("(alias)");
curr->pr_next = NULL;
- if(last == NULL)
+ if (last == NULL)
first = curr;
else
last->pr_next = curr;
last = curr;
}
- return(first);
+ return (first);
}
-
char *
map_printer_name(printer)
-char *printer;
+ char *printer;
{
-int i;
+ int i;
+
for (i = 0; i < num_aliases; i++){
- if(!strcmp(printer, alias[i].a_printer))
- return(alias[i].a_alias_for);
+ if (!strcmp(printer, alias[i].a_printer))
+ return (alias[i].a_alias_for);
}
- return(printer);
+ return (printer);
}
static void
substitute(string, token, data)
-char *string;
-char *token;
-char *data;
+ char *string, *token, *data;
{
-char temp[512];
-char *c;
+ char temp[512], *c;
- while(c = strstr(string, token)) {
+ while (c = strstr(string, token)) {
*c = '\0';
strcpy(temp, string);
strcat(temp, data);
@@ -1357,13 +869,13 @@ char *host;
static char expansion[512];
int i;
for (i = 0; i < num_aliases; i++){
- if(!strcmp(printer, alias[i].a_printer)) {
+ if (!strcmp(printer, alias[i].a_printer)) {
strcpy(expansion, alias[i].a_command);
substitute(expansion, "$FILE", file);
substitute(expansion, "$USER", user);
substitute(expansion, "$HOST", host);
- return(expansion);
+ return (expansion);
}
}
- return(NULL);
+ return (NULL);
}
diff --git a/usr.sbin/rpc.pcnfsd/pcnfsd_test.c b/usr.sbin/rpc.pcnfsd/pcnfsd_test.c
index cefa5e44cd5..984f6a3efaa 100644
--- a/usr.sbin/rpc.pcnfsd/pcnfsd_test.c
+++ b/usr.sbin/rpc.pcnfsd/pcnfsd_test.c
@@ -1,6 +1,8 @@
+/* $OpenBSD: pcnfsd_test.c,v 1.4 2001/08/19 19:16:12 ericj Exp $ */
/* $NetBSD: pcnfsd_test.c,v 1.2 1995/07/25 22:21:01 gwr Exp $ */
/* RE_SID: @(%)/usr/dosnfs/shades_SCCS/unix/pcnfsd/v2/src/SCCS/s.pcnfsd_test.c 1.2 92/01/27 18:00:39 SMI */
+
#include <stdio.h>
#include <rpc/rpc.h>
#include <stdlib.h>
diff --git a/usr.sbin/rpc.pcnfsd/pcnfsd_v1.c b/usr.sbin/rpc.pcnfsd/pcnfsd_v1.c
index 0b3219b5c02..6bad324e04c 100644
--- a/usr.sbin/rpc.pcnfsd/pcnfsd_v1.c
+++ b/usr.sbin/rpc.pcnfsd/pcnfsd_v1.c
@@ -1,3 +1,4 @@
+/* $OpenBSD: pcnfsd_v1.c,v 1.2 2001/08/19 19:16:12 ericj Exp $ */
/* $NetBSD: pcnfsd_v1.c,v 1.2 1995/07/25 22:21:19 gwr Exp $ */
/* RE_SID: @(%)/usr/dosnfs/shades_SCCS/unix/pcnfsd/v2/src/SCCS/s.pcnfsd_v1.c 1.1 91/09/03 12:41:50 SMI */
@@ -7,89 +8,40 @@
** @(#)pcnfsd_v1.c 1.1 9/3/91
**=====================================================================
*/
-#include "common.h"
-/*
-**=====================================================================
-** I N C L U D E F I L E S E C T I O N *
-** *
-** If your port requires different include files, add a suitable *
-** #define in the customization section, and make the inclusion or *
-** exclusion of the files conditional on this. *
-**=====================================================================
-*/
-#include "pcnfsd.h"
+#include <sys/types.h>
+#include <sys/stat.h>
-#include <stdio.h>
+#include <netdb.h>
#include <pwd.h>
-#include <sys/file.h>
#include <signal.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <netdb.h>
+#include <stdio.h>
#include <string.h>
+#include <unistd.h>
-#ifndef SYSV
-#include <sys/wait.h>
-#endif
-
-#ifdef ISC_2_0
-#include <sys/fcntl.h>
-#endif
-
-#ifdef SHADOW_SUPPORT
-#include <shadow.h>
-#endif
-
-/*
-**---------------------------------------------------------------------
-** Other #define's
-**---------------------------------------------------------------------
-*/
-
-extern void scramble();
-extern char *crypt();
-
-#ifdef WTMP
-extern void wlogin();
-#endif
-
-extern struct passwd *get_password();
-
-/*
-**---------------------------------------------------------------------
-** Misc. variable definitions
-**---------------------------------------------------------------------
-*/
-
-int buggit = 0;
-
-/*
-**=====================================================================
-** C O D E S E C T I O N *
-**=====================================================================
-*/
-
+#include "pcnfsd.h"
+#include "paths.h"
/*ARGSUSED*/
-void *pcnfsd_null_1_svc(arg, req)
-void *arg;
-struct svc_req *req;
+void *
+pcnfsd_null_1_svc(arg, req)
+ void *arg;
+ struct svc_req *req;
{
-static char dummy;
-return((void *)&dummy);
+ static char dummy;
+
+ return ((void *)&dummy);
}
-auth_results *pcnfsd_auth_1_svc(arg, req)
-auth_args *arg;
-struct svc_req *req;
+auth_results *
+pcnfsd_auth_1_svc(arg, req)
+ auth_args *arg;
+ struct svc_req *req;
{
-static auth_results r;
-
-char uname[32];
-char pw[64];
-int c1, c2;
-struct passwd *p;
+ static auth_results r;
+ char uname[32], pw[64];
+ int c1, c2;
+ struct passwd *p;
r.stat = AUTH_RES_FAIL; /* assume failure */
@@ -99,19 +51,14 @@ struct passwd *p;
scramble(arg->id, uname);
scramble(arg->pw, pw);
-#ifdef USER_CACHE
- if(check_cache(uname, pw, &r.uid, &r.gid)) {
- r.stat = AUTH_RES_OK;
-#ifdef WTMP
+ if (check_cache(uname, pw, &r.uid, &r.gid)) {
+ r.stat = AUTH_RES_OK;
wlogin(uname, req);
-#endif
- return (&r);
- }
-#endif
+ return (&r);
+ }
- p = get_password(uname);
- if (p == (struct passwd *)NULL)
- return (&r);
+ if ((p = get_password(uname)) == NULL)
+ return (&r);
c1 = strlen(pw);
c2 = strlen(p->pw_passwd);
@@ -123,40 +70,35 @@ struct passwd *p;
r.stat = AUTH_RES_OK;
r.uid = p->pw_uid;
r.gid = p->pw_gid;
-#ifdef WTMP
wlogin(uname, req);
-#endif
-#ifdef USER_CACHE
add_cache_entry(p);
-#endif
-return(&r);
+ return (&r);
}
-pr_init_results *pcnfsd_pr_init_1_svc(pi_arg, req)
-pr_init_args *pi_arg;
-struct svc_req *req;
+pr_init_results *
+pcnfsd_pr_init_1_svc(pi_arg, req)
+ pr_init_args *pi_arg;
+ struct svc_req *req;
{
-static pr_init_results pi_res;
+ static pr_init_results pi_res;
- pi_res.stat =
- (pirstat) pr_init(pi_arg->system, pi_arg->pn, &pi_res.dir);
+ pi_res.stat = (pirstat)pr_init(pi_arg->system, pi_arg->pn, &pi_res.dir);
-return(&pi_res);
+ return (&pi_res);
}
-pr_start_results *pcnfsd_pr_start_1_svc(ps_arg, req)
-pr_start_args *ps_arg;
-struct svc_req *req;
+pr_start_results *
+pcnfsd_pr_start_1_svc(ps_arg, req)
+ pr_start_args *ps_arg;
+ struct svc_req *req;
{
-static pr_start_results ps_res;
-char *dummyptr;
+ static pr_start_results ps_res;
+ char *dummyptr;
- ps_res.stat =
- (psrstat) pr_start2(ps_arg->system, ps_arg->pn, ps_arg->user,
- ps_arg ->file, ps_arg->opts, &dummyptr);
+ ps_res.stat = (psrstat)pr_start2(ps_arg->system, ps_arg->pn,
+ ps_arg->user, ps_arg->file, ps_arg->opts, &dummyptr);
-return(&ps_res);
+ return (&ps_res);
}
-
diff --git a/usr.sbin/rpc.pcnfsd/pcnfsd_v2.c b/usr.sbin/rpc.pcnfsd/pcnfsd_v2.c
index 96889a2b01d..8c08b87323c 100644
--- a/usr.sbin/rpc.pcnfsd/pcnfsd_v2.c
+++ b/usr.sbin/rpc.pcnfsd/pcnfsd_v2.c
@@ -1,3 +1,4 @@
+/* $OpenBSD: pcnfsd_v2.c,v 1.3 2001/08/19 19:16:12 ericj Exp $ */
/* $NetBSD: pcnfsd_v2.c,v 1.4 1995/08/14 19:50:10 gwr Exp $ */
/* RE_SID: @(%)/usr/dosnfs/shades_SCCS/unix/pcnfsd/v2/src/SCCS/s.pcnfsd_v2.c 1.2 91/12/18 13:26:13 SMI */
@@ -7,18 +8,6 @@
** @(#)pcnfsd_v2.c 1.2 12/18/91
**=====================================================================
*/
-#include "common.h"
-/*
-**=====================================================================
-** I N C L U D E F I L E S E C T I O N *
-** *
-** If your port requires different include files, add a suitable *
-** #define in the customization section, and make the inclusion or *
-** exclusion of the files conditional on this. *
-**=====================================================================
-*/
-#include "pcnfsd.h"
-
#include <stdio.h>
#include <pwd.h>
#include <grp.h>
@@ -28,96 +17,40 @@
#include <sys/ioctl.h>
#include <netdb.h>
#include <string.h>
+#include <unistd.h>
-#ifdef USE_YP
-#include <rpcsvc/ypclnt.h>
-#endif
-
-#ifndef SYSV
-#include <sys/wait.h>
-#endif
-
-#ifdef ISC_2_0
-#include <sys/fcntl.h>
-#endif
-
-#ifdef SHADOW_SUPPORT
-#include <shadow.h>
-#endif
-
-/*
-**---------------------------------------------------------------------
-** Other #define's
-**---------------------------------------------------------------------
-*/
-
-void fillin_extra_groups();
-extern void scramble();
-extern void *grab();
-extern char *crypt();
-extern int build_pr_list();
-extern pirstat build_pr_queue();
-extern psrstat pr_start();
-extern psrstat pr_start2();
-extern pcrstat pr_cancel();
-extern pirstat get_pr_status();
-
-extern struct passwd *get_password();
-
-#ifdef WTMP
-extern void wlogin();
-#endif
-
-#ifdef USE_YP
-char *find_entry();
-#endif
-
-/*
-**---------------------------------------------------------------------
-** Misc. variable definitions
-**---------------------------------------------------------------------
-*/
-
-extern pr_list printers;
-extern pr_queue queue;
-
-/*
-**=====================================================================
-** C O D E S E C T I O N *
-**=====================================================================
-*/
+#include "pcnfsd.h"
+#include "paths.h"
+static void fillin_extra_groups __P((char *, u_int, int *, u_int *));
static char no_comment[] = "No comment";
static char not_supported[] = "Not supported";
static char pcnfsd_version[] = "@(#)pcnfsd_v2.c 1.2 - rpc.pcnfsd V2.0 (c) 1991 Sun Technology Enterprises, Inc.";
/*ARGSUSED*/
-void *pcnfsd2_null_2_svc(arg, req)
-void*arg;
-struct svc_req *req;
+void *
+pcnfsd2_null_2_svc(arg, req)
+ void*arg;
+ struct svc_req *req;
{
-static char dummy;
-return((void *)&dummy);
+ static char dummy;
+
+ return ((void *)&dummy);
}
-v2_auth_results *pcnfsd2_auth_2_svc(arg, req)
-v2_auth_args *arg;
-struct svc_req *req;
+v2_auth_results *
+pcnfsd2_auth_2_svc(arg, req)
+ v2_auth_args *arg;
+ struct svc_req *req;
{
-static v2_auth_results r;
-
-char uname[32];
-char pw[64];
-int c1, c2;
-struct passwd *p;
-static u_int extra_gids[EXTRAGIDLEN];
-static char home[MAXPATHLEN];
-#ifdef USE_YP
-char *yphome;
-char *cp;
-#endif /*USE_YP*/
+ static v2_auth_results r;
+ char uname[32], pw[64];
+ int c1, c2;
+ struct passwd *p;
+ static u_int extra_gids[EXTRAGIDLEN];
+ static char home[MAXPATHLEN];
r.stat = AUTH_RES_FAIL; /* assume failure */
r.uid = (int)-2;
@@ -133,238 +66,190 @@ char *cp;
scramble(arg->id, uname);
scramble(arg->pw, pw);
-#ifdef USER_CACHE
- if(check_cache(uname, pw, &r.uid, &r.gid)) {
- r.stat = AUTH_RES_OK;
-#ifdef WTMP
+ if (check_cache(uname, pw, &r.uid, &r.gid)) {
+ r.stat = AUTH_RES_OK;
wlogin(uname, req);
-#endif
- fillin_extra_groups
- (uname, r.gid, &r.gids.gids_len, extra_gids);
-#ifdef USE_YP
- yphome = find_entry(uname, "auto.home");
- if(yphome) {
- strncpy(home, yphome, sizeof home-1);
- home[sizeof home-1] = '\0';
- free(yphome);
- cp = strchr(home, ':');
- cp++;
- cp = strchr(cp, ':');
- if(cp)
- *cp = '/';
- }
-#endif
- return (&r);
- }
-#endif
+ fillin_extra_groups(uname, r.gid, &r.gids.gids_len, extra_gids);
+ return (&r);
+ }
- p = get_password(uname);
- if (p == (struct passwd *)NULL)
- return (&r);
+ if ((p = get_password(uname)) == NULL)
+ return (&r);
c1 = strlen(pw);
c2 = strlen(p->pw_passwd);
if ((c1 && !c2) || (c2 && !c1) ||
- (strcmp(p->pw_passwd, crypt(pw, p->pw_passwd))))
- {
- return (&r);
- }
+ (strcmp(p->pw_passwd, crypt(pw, p->pw_passwd)))) {
+ return (&r);
+ }
+
r.stat = AUTH_RES_OK;
r.uid = p->pw_uid;
r.gid = p->pw_gid;
-#ifdef WTMP
wlogin(uname, req);
-#endif
fillin_extra_groups(uname, r.gid, &r.gids.gids_len, extra_gids);
-#ifdef USE_YP
- yphome = find_entry(uname, "auto.home");
- if(yphome) {
- strncpy(home, yphome, sizeof home-1);
- home[sizeof home-1] = '\0';
- free(yphome);
- cp = strchr(home, ':');
- cp++;
- cp = strchr(cp, ':');
- if(cp)
- *cp = '/';
- }
-#endif
-
-#ifdef USER_CACHE
add_cache_entry(p);
-#endif
-
-return(&r);
+ return (&r);
}
-v2_pr_init_results *pcnfsd2_pr_init_2_svc(arg, req)
-v2_pr_init_args *arg;
-struct svc_req *req;
+v2_pr_init_results *
+pcnfsd2_pr_init_2_svc(arg, req)
+ v2_pr_init_args *arg;
+ struct svc_req *req;
{
-static v2_pr_init_results res;
+ static v2_pr_init_results res;
- res.stat =
- (pirstat) pr_init(arg->system, arg->pn, &res.dir);
+ res.stat = (pirstat)pr_init(arg->system, arg->pn, &res.dir);
res.cm = &no_comment[0];
-
-return(&res);
+ return (&res);
}
-v2_pr_start_results *pcnfsd2_pr_start_2_svc(arg, req)
-v2_pr_start_args *arg;
-struct svc_req *req;
+v2_pr_start_results *
+pcnfsd2_pr_start_2_svc(arg, req)
+ v2_pr_start_args *arg;
+ struct svc_req *req;
{
-static v2_pr_start_results res;
+ static v2_pr_start_results res;
- res.stat =
- (psrstat) pr_start2(arg->system, arg->pn, arg->user,
- arg ->file, arg->opts, &res.id);
+ res.stat = (psrstat)pr_start2(arg->system, arg->pn, arg->user,
+ arg->file, arg->opts, &res.id);
res.cm = &no_comment[0];
-return(&res);
+ return (&res);
}
/*ARGSUSED*/
-v2_pr_list_results *pcnfsd2_pr_list_2_svc(arg, req)
-void *arg;
-struct svc_req *req;
+v2_pr_list_results *
+pcnfsd2_pr_list_2_svc(arg, req)
+ void *arg;
+ struct svc_req *req;
{
-static v2_pr_list_results res;
+ static v2_pr_list_results res;
- if(printers == NULL)
+ if (printers == NULL)
(void)build_pr_list();
res.cm = &no_comment[0];
res.printers = printers;
-return(&res);
+ return (&res);
}
-v2_pr_queue_results *pcnfsd2_pr_queue_2_svc(arg, req)
-v2_pr_queue_args *arg;
-struct svc_req *req;
+v2_pr_queue_results *
+pcnfsd2_pr_queue_2_svc(arg, req)
+ v2_pr_queue_args *arg;
+ struct svc_req *req;
{
-static v2_pr_queue_results res;
+ static v2_pr_queue_results res;
- res.stat = build_pr_queue(arg->pn, arg->user,
- arg->just_mine, &res.qlen, &res.qshown);
+ res.stat = build_pr_queue(arg->pn, arg->user, arg->just_mine,
+ &res.qlen, &res.qshown);
res.cm = &no_comment[0];
res.just_yours = arg->just_mine;
res.jobs = queue;
-
-return(&res);
+ return (&res);
}
-v2_pr_status_results *pcnfsd2_pr_status_2_svc(arg, req)
-v2_pr_status_args *arg;
-struct svc_req *req;
+v2_pr_status_results *
+pcnfsd2_pr_status_2_svc(arg, req)
+ v2_pr_status_args *arg;
+ struct svc_req *req;
{
-static v2_pr_status_results res;
-static char status[128];
+ static v2_pr_status_results res;
+ static char status[128];
res.stat = get_pr_status(arg->pn, &res.avail, &res.printing,
- &res.qlen, &res.needs_operator, &status[0]);
+ &res.qlen, &res.needs_operator, &status[0]);
res.status = &status[0];
res.cm = &no_comment[0];
-return(&res);
+ return (&res);
}
-v2_pr_cancel_results *pcnfsd2_pr_cancel_2_svc(arg, req)
-v2_pr_cancel_args *arg;
-struct svc_req *req;
+v2_pr_cancel_results *
+pcnfsd2_pr_cancel_2_svc(arg, req)
+ v2_pr_cancel_args *arg;
+ struct svc_req *req;
{
-static v2_pr_cancel_results res;
+ static v2_pr_cancel_results res;
res.stat = pr_cancel(arg->pn, arg->user, arg->id);
res.cm = &no_comment[0];
-return(&res);
+ return (&res);
}
/*ARGSUSED*/
-v2_pr_requeue_results *pcnfsd2_pr_requeue_2_svc(arg, req)
-v2_pr_requeue_args *arg;
-struct svc_req *req;
+v2_pr_requeue_results *
+pcnfsd2_pr_requeue_2_svc(arg, req)
+ v2_pr_requeue_args *arg;
+ struct svc_req *req;
{
-static v2_pr_requeue_results res;
+ static v2_pr_requeue_results res;
+
res.stat = PC_RES_FAIL;
res.cm = &not_supported[0];
-return(&res);
+ return (&res);
}
/*ARGSUSED*/
-v2_pr_hold_results *pcnfsd2_pr_hold_2_svc(arg, req)
-v2_pr_hold_args *arg;
-struct svc_req *req;
+v2_pr_hold_results *
+pcnfsd2_pr_hold_2_svc(arg, req)
+ v2_pr_hold_args *arg;
+ struct svc_req *req;
{
-static v2_pr_hold_results res;
+ static v2_pr_hold_results res;
res.stat = PC_RES_FAIL;
res.cm = &not_supported[0];
-return(&res);
+ return (&res);
}
/*ARGSUSED*/
-v2_pr_release_results *pcnfsd2_pr_release_2_svc(arg, req)
-v2_pr_release_args *arg;
-struct svc_req *req;
+v2_pr_release_results *
+pcnfsd2_pr_release_2_svc(arg, req)
+ v2_pr_release_args *arg;
+ struct svc_req *req;
{
-static v2_pr_release_results res;
+ static v2_pr_release_results res;
res.stat = PC_RES_FAIL;
res.cm = &not_supported[0];
-return(&res);
+ return (&res);
}
/*ARGSUSED*/
-v2_pr_admin_results *pcnfsd2_pr_admin_2_svc(arg, req)
-v2_pr_admin_args *arg;
-struct svc_req *req;
+v2_pr_admin_results *
+pcnfsd2_pr_admin_2_svc(arg, req)
+ v2_pr_admin_args *arg;
+ struct svc_req *req;
{
-static v2_pr_admin_results res;
-/*
-** The default action for admin is to fail.
-** If someone wishes to implement an administration
-** mechanism, and isn't worried about the security
-** holes, go right ahead.
-*/
+ static v2_pr_admin_results res;
res.cm = &not_supported[0];
res.stat = PI_RES_FAIL;
-return(&res);
+ return (&res);
}
void
free_mapreq_results(p)
mapreq_res p;
{
- if(p->mapreq_next)
+ if (p->mapreq_next)
free_mapreq_results(p->mapreq_next); /* recurse */
- if(p->name)
+ if (p->name)
(void)free(p->name);
(void)free(p);
return;
}
-static char *
-my_strdup(s)
-char *s;
-{
- char *r;
-
- r = (char *)grab(strlen(s)+1);
- strcpy(r, s);
- return(r);
-}
-
v2_mapid_results *pcnfsd2_mapid_2_svc(arg, req)
v2_mapid_args *arg;
struct svc_req *req;
@@ -378,13 +263,13 @@ mapreq_res next_r;
mapreq_res last_r = NULL;
- if(res.res_list) {
+ if (res.res_list) {
free_mapreq_results(res.res_list);
res.res_list = NULL;
}
a = arg->req_list;
- while(a) {
+ while (a) {
next_r = (struct mapreq_res_item *)
grab(sizeof(struct mapreq_res_item));
next_r->stat = MAP_RES_UNKNOWN;
@@ -393,7 +278,7 @@ mapreq_res last_r = NULL;
next_r->name = NULL;
next_r->mapreq_next = NULL;
- if(last_r == NULL)
+ if (last_r == NULL)
res.res_list = next_r;
else
last_r->mapreq_next = next_r;
@@ -401,43 +286,43 @@ mapreq_res last_r = NULL;
switch(a->req) {
case MAP_REQ_UID:
p_passwd = getpwuid((uid_t)a->id);
- if(p_passwd) {
- next_r->name = my_strdup(p_passwd->pw_name);
+ if (p_passwd) {
+ next_r->name = strdup(p_passwd->pw_name);
next_r->stat = MAP_RES_OK;
}
break;
case MAP_REQ_GID:
p_group = getgrgid((gid_t)a->id);
- if(p_group) {
- next_r->name = my_strdup(p_group->gr_name);
+ if (p_group) {
+ next_r->name = strdup(p_group->gr_name);
next_r->stat = MAP_RES_OK;
}
break;
case MAP_REQ_UNAME:
- next_r->name = my_strdup(a->name);
+ next_r->name = strdup(a->name);
p_passwd = getpwnam(a->name);
- if(p_passwd) {
+ if (p_passwd) {
next_r->id = p_passwd->pw_uid;
next_r->stat = MAP_RES_OK;
}
break;
case MAP_REQ_GNAME:
- next_r->name = my_strdup(a->name);
+ next_r->name = strdup(a->name);
p_group = getgrnam(a->name);
- if(p_group) {
+ if (p_group) {
next_r->id = p_group->gr_gid;
next_r->stat = MAP_RES_OK;
}
break;
}
- if(next_r->name == NULL)
- next_r->name = my_strdup("");
+ if (next_r->name == NULL)
+ next_r->name = strdup("");
a = a->mapreq_next;
}
res.cm = &no_comment[0];
-return(&res);
+ return (&res);
}
@@ -451,7 +336,7 @@ static v2_alert_results res;
res.stat = ALERT_RES_FAIL;
res.cm = &not_supported[0];
-return(&res);
+ return (&res);
}
/*ARGSUSED*/
@@ -467,7 +352,7 @@ static int onetime = 1;
#define QUICK 100
#define SLOW 2000
- if(onetime) {
+ if (onetime) {
onetime = 0;
facilities[PCNFSD2_NULL] = QUICK;
facilities[PCNFSD2_INFO] = QUICK;
@@ -491,12 +376,12 @@ static int onetime = 1;
res.vers = &pcnfsd_version[0];
res.cm = &no_comment[0];
-return(&res);
+ return (&res);
}
-void
+static void
fillin_extra_groups(uname, main_gid, len, extra_gids)
char *uname;
u_int main_gid;
@@ -509,14 +394,14 @@ int n = 0;
setgrent();
- while(n < EXTRAGIDLEN) {
+ while (n < EXTRAGIDLEN) {
grp = getgrent();
- if(grp == NULL)
+ if (grp == NULL)
break;
- if(grp->gr_gid == main_gid)
+ if (grp->gr_gid == main_gid)
continue;
- for(members = grp->gr_mem; members && *members; members++) {
- if(!strcmp(*members, uname)) {
+ for (members = grp->gr_mem; members && *members; members++) {
+ if (!strcmp(*members, uname)) {
extra_gids[n++] = grp->gr_gid;
break;
}
@@ -525,48 +410,3 @@ int n = 0;
endgrent();
*len = n;
}
-
-#ifdef USE_YP
-/* the following is from rpcsvc/yp_prot.h */
-#define YPMAXDOMAIN 64
-/*
- * find_entry returns NULL on any error (printing a message) and
- * otherwise returns a pointer to the malloc'd result. The caller
- * is responsible for free()ing the result string.
- */
-char *
-find_entry(key, map)
-char *key;
-char *map;
-{
- int err;
- char *val = NULL;
- char *cp;
- int len = 0;
- static char domain[YPMAXDOMAIN+1];
-
- if(getdomainname(domain, YPMAXDOMAIN) ) {
- msg_out("rpc.pcnfsd: getdomainname failed");
- return(NULL);
- }
-
- if (err = yp_bind(domain)) {
-#ifdef DEBUG
- msg_out("rpc.pcnfsd: yp_bind failed");
-#endif
- return(NULL);
- }
-
- err = yp_match(domain, map, key, strlen(key), &val, &len);
-
- if (err) {
- msg_out("rpc.pcnfsd: yp_match failed");
- return(NULL);
- }
-
- if(cp = strchr(val, '\n'))
- *cp = '\0'; /* in case we get an extra NL at the end */
- return(val);
-}
-
-#endif