/*
+ * $Id: main.c,v 1.14 2002-01-03 17:49:39 sibaz Exp $
+ *
* Copyright (c) 1990,1995 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
#include <sys/param.h>
-#include <sys/types.h>
#include <sys/time.h>
#include <sys/uio.h>
#if defined( sun ) && defined( __svr4__ )
#include </usr/ucbinclude/sys/file.h>
-#else sun __svr4__
+#else /* sun && __svr4__ */
#include <sys/file.h>
-#endif sun __svr4__
+#endif /* sun && __svr4__ */
#include <sys/socket.h>
-#include <sys/syslog.h>
+#include <syslog.h>
+
+/* POSIX.1 sys/wait.h check */
+#include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
+#endif /* HAVE_SYS_WAIT_H */
+#ifndef WEXITSTATUS
+#define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
+#endif /* ! WEXITSTATUS */
+#ifndef WIFEXITED
+#define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
+#endif /* ! WIFEXITED */
+
#include <errno.h>
+/* STDC check */
+#if STDC_HEADERS
#include <string.h>
+#else /* STDC_HEADERS */
+#ifndef HAVE_STRCHR
+#define strchr index
+#define strrchr index
+#endif /* HAVE_STRCHR */
+char *strchr (), *strrchr ();
+#ifndef HAVE_MEMCPY
+#define memcpy(d,s,n) bcopy ((s), (d), (n))
+#define memmove(d,s,n) bcopy ((s), (d), (n))
+#endif /* ! HAVE_MEMCPY */
+#endif /* STDC_HEADERS */
+
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
#include <fcntl.h>
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif /* HAVE_UNISTD_H */
#include <netatalk/endian.h>
#include <netatalk/at.h>
#include <atalk/pap.h>
#include <atalk/paths.h>
#include <atalk/util.h>
+#include <atalk/nbp.h>
#include "printer.h"
+#include "printcap.h"
+#include "session.h"
+#include "uam_auth.h"
#define _PATH_PAPDPPDFILE ".ppd"
char *version = VERSION;
static char *pidfile = _PATH_PAPDLOCK;
+char *uamlist;
+char *uampath = _PATH_PAPDUAMPATH;
+
+/* Prototypes for locally used functions */
+int getstatus( struct printer *pr, char *buf );
+int rprintcap( struct printer *pr );
+void getprinters( char *cf );
+
+
/* this only needs to be used by the server process */
static void papd_exit(const int i)
{
server_unlock(pidfile);
+ auth_unload();
exit(i);
}
#if !defined( ibm032 ) && !defined( _IBMR2 )
void
-#endif ibm032 _IBMR2
+#endif /* ! ibm032 && ! _IBMR2 */
die( n )
int n;
{
struct printer *pr;
+ struct at_addr addr;
+
+ memset(&addr, 0, sizeof(addr));
for ( pr = printers; pr; pr = pr->p_next ) {
if ( pr->p_flags & P_REGISTERED ) {
- if ( nbp_unrgstr( pr->p_name, pr->p_type, pr->p_zone ) < 0 ) {
+ if ( nbp_unrgstr( pr->p_name, pr->p_type, pr->p_zone, &addr ) < 0 ) {
syslog( LOG_ERR, "can't unregister %s:%s@%s\n", pr->p_name,
pr->p_type, pr->p_zone );
papd_exit( n + 1 );
#if !defined( ibm032 ) && !defined( _IBMR2 )
void
-#endif ibm032 _IBMR2
+#endif /* ! ibm032 && ! _IBMR2 */
reap()
{
int status;
char rbuf[ 255 + 1 + 8 ];
-main( ac, av )
+int main( ac, av )
int ac;
char **av;
{
extern char *optarg;
- extern int optind;
ATP atp;
struct atp_block atpb;
#ifdef __svr4__
defprinter.p_flags = P_PIPED;
defprinter.p_printer = "/usr/bin/lp -T PS";
-#else
+#else /* __svr4__ */
defprinter.p_flags = P_SPOOLED;
defprinter.p_printer = "lp";
-#endif
+#endif /* __svr4__ */
defprinter.p_operator = "operator";
defprinter.p_spool = _PATH_PAPDSPOOLDIR;
#ifdef ABS_PRINT
defprinter.p_role = NULL;
defprinter.p_srvid = 0;
-#endif ABS_PRINT
+#endif /* ABS_PRINT */
defprinter.p_pagecost = 200; /* default cost */
defprinter.p_pagecost_msg = NULL;
defprinter.p_lock = "lock";
- while (( c = getopt( ac, av, "adf:p:P:" )) != EOF ) {
+ while (( c = getopt( ac, av, "adf:p:P:v" )) != EOF ) {
switch ( c ) {
case 'a' : /* for compatibility with old papd */
break;
pidfile = optarg;
break;
+ case 'v' : /* version */
+ printf( "papd (version %s)\n", VERSION );
+ exit ( 1 );
+ break;
+
default :
fprintf( stderr,
"Usage:\t%s [ -d ] [ -f conffile ] [ -p printcap ]\n",
}
#ifdef ultrix
openlog( p, LOG_PID );
-#else ultrix
+#else /* ultrix */
openlog( p, LOG_NDELAY|LOG_PID, LOG_LPR );
-#endif ultrix
+#endif /* ultrix */
syslog( LOG_INFO, "restart (%s)", version );
pr->p_zone );
die( 1 );
}
+ if ( pr->p_flags & P_AUTH ) {
+ syslog( LOG_INFO, "Authentication enabled: %s", pr->p_name );
+ }
+ else {
+ syslog( LOG_INFO, "Authentication disabled: %s", pr->p_name );
+ }
syslog( LOG_INFO, "register %s:%s@%s", pr->p_name, pr->p_type,
pr->p_zone );
pr->p_flags |= P_REGISTERED;
papd_exit( 1 );
}
+ /*
+ * Load UAMS
+ */
+ auth_load(uampath, uamlist);
+
/*
* Begin accepting connections.
*/
if ( FD_ISSET( atp_fileno( pr->p_atp ), &fdset )) {
int err = 0;
- bzero( &sat, sizeof( struct sockaddr_at ));
+ memset( &sat, 0, sizeof( struct sockaddr_at ));
#ifdef BSD4_4
sat.sat_len = sizeof( struct sockaddr_at );
-#endif BSD4_4
+#endif /* BSD4_4 */
sat.sat_family = AF_APPLETALK;
sat.sat_addr.s_net = ATADDR_ANYNET;
sat.sat_addr.s_node = ATADDR_ANYNODE;
if ( atp_sresp( pr->p_atp, &atpb ) < 0 ) {
syslog( LOG_ERR, "atp_sresp: %m" );
}
-#endif notdef
+#endif /* notdef */
}
}
}
+ return 0;
}
/*
* We assume buf is big enough for 255 bytes of data and a length byte.
*/
- int
-getstatus( pr, buf )
+
+int getstatus( pr, buf )
struct printer *pr;
char *buf;
{
char *pgetstr();
char *getpname();
-getprinters( cf )
+void getprinters( cf )
char *cf;
{
char buf[ 1024 ], area[ 1024 ], *a, *p, *name, *type, *zone;
perror( "malloc" );
exit( 1 );
}
- bzero( pr, sizeof( struct printer ));
+ memset( pr, 0, sizeof( struct printer ));
name = defprinter.p_name;
type = defprinter.p_type;
strcpy( pr->p_printer, p );
}
+ /*
+ * Do we want authenticated printing?
+ */
+ if ((p = pgetstr( "ca", &a )) != NULL ) {
+ if ((pr->p_authprintdir = (char *)malloc(strlen(p)+1)) == NULL) {
+ perror( "malloc" );
+ exit(1);
+ }
+ strcpy( pr->p_authprintdir, p );
+ pr->p_flags |= P_AUTH;
+ pr->p_flags |= P_AUTH_CAP;
+ } else { pr->p_authprintdir = NULL; }
+
+ if ( pgetflag( "sp" ) == 1 ) {
+ pr->p_flags |= P_AUTH;
+ pr->p_flags |= P_AUTH_PSSP;
+ }
+
+ if ((p = pgetstr("am", &a)) != NULL ) {
+ if ((uamlist = (char *)malloc(strlen(p)+1)) == NULL ) {
+ perror("malloc");
+ exit(1);
+ }
+ strcpy(uamlist, p);
+ }
+
if ( pr->p_flags & P_SPOOLED ) {
/*
* Get operator name.
}
}
-rprintcap( pr )
+int rprintcap( pr )
struct printer *pr;
{
char buf[ 1024 ], area[ 1024 ], *a, *p;
} else {
pr->p_srvid = c;
}
-#endif ABS_PRINT
+#endif /* ABS_PRINT */
}
* Must Kerberos authenticate?
*/
if ( pgetflag( "ka" ) == 1 ) {
- pr->p_flags |= P_AUTH;
+ pr->p_flags |= P_KRB;
} else {
- pr->p_flags &= ~P_AUTH;
+ pr->p_flags &= ~P_KRB;
}
-#endif
+#endif /* KRB */
endprent();
}