2001-04-18 13:17:43 +00:00
|
|
|
$OpenBSD: patch-etcpapd-lpc,v 1.3 2001/04/18 13:17:44 brad Exp $
|
1999-12-15 02:54:39 +00:00
|
|
|
--- etc/papd/lp.c.orig Sun Aug 17 09:20:25 1997
|
2001-04-18 13:17:43 +00:00
|
|
|
+++ etc/papd/lp.c Thu Mar 29 16:31:06 2001
|
1999-12-15 02:54:39 +00:00
|
|
|
@@ -44,6 +44,8 @@
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
+#include <sys/types.h>
|
|
|
|
+#include <sys/uio.h>
|
|
|
|
#if defined( sun ) && defined( __svr4__ )
|
|
|
|
#include </usr/ucbinclude/sys/file.h>
|
|
|
|
#else sun __svr4__
|
|
|
|
@@ -60,11 +62,13 @@
|
|
|
|
#include <math.h>
|
|
|
|
#endif ABS_PRINT
|
|
|
|
|
|
|
|
+#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
-#include <strings.h>
|
|
|
|
+#include <string.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
+#include <unistd.h>
|
|
|
|
|
|
|
|
#include "printer.h"
|
|
|
|
#include "file.h"
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -100,20 +104,26 @@ struct lp {
|
1999-12-15 02:54:39 +00:00
|
|
|
#define LP_CONNECT (1<<3)
|
|
|
|
#define LP_QUEUE (1<<4)
|
|
|
|
|
|
|
|
+int
|
|
|
|
lp_person( person )
|
|
|
|
char *person;
|
|
|
|
{
|
|
|
|
+ size_t len;
|
|
|
|
+
|
|
|
|
if ( lp.lp_person != NULL ) {
|
|
|
|
free( lp.lp_person );
|
|
|
|
}
|
|
|
|
- if (( lp.lp_person = (char *)malloc( strlen( person ) + 1 )) == NULL ) {
|
|
|
|
+ len = (strlen( person ) + 1);
|
|
|
|
+ if (( lp.lp_person = (char *)malloc( len )) == NULL ) {
|
|
|
|
syslog( LOG_ERR, "malloc: %m" );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
- strcpy( lp.lp_person, person );
|
|
|
|
+ (void)strlcpy( lp.lp_person, person, len );
|
|
|
|
+ return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ABS_PRINT
|
|
|
|
+int
|
|
|
|
lp_pagecost()
|
|
|
|
{
|
|
|
|
char cost[ 22 ];
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -131,19 +141,25 @@ lp_pagecost()
|
1999-12-15 02:54:39 +00:00
|
|
|
}
|
|
|
|
#endif ABS_PRINT
|
|
|
|
|
|
|
|
+int
|
|
|
|
lp_host( host )
|
|
|
|
char *host;
|
|
|
|
{
|
|
|
|
+ size_t len;
|
|
|
|
+
|
|
|
|
if ( lp.lp_host != NULL ) {
|
|
|
|
free( lp.lp_host );
|
|
|
|
}
|
|
|
|
- if (( lp.lp_host = (char *)malloc( strlen( host ) + 1 )) == NULL ) {
|
|
|
|
+ len = (strlen( host ) + 1);
|
|
|
|
+ if (( lp.lp_host = (char *)malloc( len )) == NULL ) {
|
|
|
|
syslog( LOG_ERR, "malloc: %m" );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
- strcpy( lp.lp_host, host );
|
|
|
|
+ (void)strlcpy( lp.lp_host, host, len);
|
|
|
|
+ return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
+int
|
|
|
|
lp_job( job )
|
|
|
|
char *job;
|
|
|
|
{
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -164,12 +180,14 @@ lp_job( job )
|
1999-12-15 02:54:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*q = '\0';
|
|
|
|
+ return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
+int
|
|
|
|
lp_init( out )
|
|
|
|
struct papfile *out;
|
|
|
|
{
|
2000-06-12 17:27:33 +00:00
|
|
|
- int fd, n, len;
|
|
|
|
+ int fd, n, len, lfd;
|
|
|
|
char *cp, buf[ BUFSIZ ];
|
|
|
|
struct stat st;
|
|
|
|
#ifdef ABS_PRINT
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -209,12 +227,27 @@ lp_init( out )
|
2000-06-12 17:27:33 +00:00
|
|
|
lp.lp_letter = 'A';
|
|
|
|
|
|
|
|
if ( printer->p_flags & P_SPOOLED ) {
|
|
|
|
- /* check if queuing is enabled: mode & 010 on lock file */
|
|
|
|
+ /* check if queuing is enabled: mode & 010 on lock file.
|
|
|
|
+ if lock file doesn't exist create it and close it.
|
|
|
|
+ So far I can't see papd actually using the lock file.
|
|
|
|
+ it seems to pass this on to the default host print system.
|
|
|
|
+ ianm@cit.nepean.uws.edu.au */
|
|
|
|
+
|
|
|
|
if ( stat( printer->p_lock, &st ) < 0 ) {
|
|
|
|
- syslog( LOG_ERR, "lp_init: %s: %m", printer->p_lock );
|
|
|
|
- spoolerror( out, NULL );
|
|
|
|
- return( -1 );
|
|
|
|
+ if ( lfd = open( printer->p_lock, O_CREAT, 0644) < 0 ) {
|
|
|
|
+ syslog( LOG_ERR, "lp_init: %s: %m", printer->p_lock );
|
|
|
|
+ spoolerror( out, NULL );
|
|
|
|
+ return( -1 );
|
|
|
|
+ }
|
|
|
|
+ close(lfd);
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ if ( stat( printer->p_lock, &st ) < 0 ) {
|
|
|
|
+ syslog( LOG_ERR, "lp_init: %s: %m", printer->p_lock );
|
|
|
|
+ spoolerror ( out, NULL );
|
|
|
|
+ return ( -1 );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
if ( st.st_mode & 010 ) {
|
|
|
|
syslog( LOG_INFO, "lp_init: queuing is disabled" );
|
|
|
|
spoolerror( out, "Queuing is disabled." );
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -250,7 +283,7 @@ lp_init( out )
|
1999-12-15 02:54:39 +00:00
|
|
|
lp.lp_seq = n;
|
|
|
|
|
|
|
|
n = ( n + 1 ) % 1000;
|
|
|
|
- sprintf( buf, "%03d\n", n );
|
|
|
|
+ snprintf( buf, sizeof( buf ), "%03d\n", n );
|
|
|
|
lseek( fd, 0L, 0 );
|
|
|
|
write( fd, buf, strlen( buf ));
|
|
|
|
close( fd );
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -263,6 +296,7 @@ lp_init( out )
|
1999-12-15 02:54:39 +00:00
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
+int
|
|
|
|
lp_open( out )
|
|
|
|
struct papfile *out;
|
|
|
|
{
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -285,7 +319,7 @@ lp_open( out )
|
1999-12-15 02:54:39 +00:00
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
- sprintf( name, "df%c%03d%s", lp.lp_letter++, lp.lp_seq, hostname );
|
|
|
|
+ snprintf( name, sizeof ( name ), "df%c%03d%s", lp.lp_letter++, lp.lp_seq, hostname );
|
|
|
|
|
|
|
|
if (( fd = open( name, O_WRONLY|O_CREAT|O_EXCL, 0660 )) < 0 ) {
|
|
|
|
syslog( LOG_ERR, "lp_open %s: %m", name );
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -303,17 +337,19 @@ lp_open( out )
|
1999-12-15 02:54:39 +00:00
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
+int
|
|
|
|
lp_close()
|
|
|
|
{
|
|
|
|
if (( lp.lp_flags & LP_INIT ) == 0 || ( lp.lp_flags & LP_OPEN ) == 0 ) {
|
|
|
|
- return;
|
|
|
|
+ return(0);
|
|
|
|
}
|
|
|
|
fclose( lp.lp_stream );
|
|
|
|
lp.lp_stream = NULL;
|
|
|
|
lp.lp_flags &= ~LP_OPEN;
|
|
|
|
- return;
|
|
|
|
+ return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
+int
|
|
|
|
lp_write( buf, len )
|
|
|
|
char *buf;
|
|
|
|
int len;
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -329,13 +365,14 @@ lp_write( buf, len )
|
1999-12-15 02:54:39 +00:00
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
+int
|
|
|
|
lp_cancel()
|
|
|
|
{
|
|
|
|
char name[ MAXPATHLEN ];
|
|
|
|
char letter;
|
|
|
|
|
|
|
|
if (( lp.lp_flags & LP_INIT ) == 0 || lp.lp_letter == 'A' ) {
|
|
|
|
- return;
|
|
|
|
+ return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( lp.lp_flags & LP_OPEN ) {
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -343,13 +380,13 @@ lp_cancel()
|
1999-12-15 02:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for ( letter = 'A'; letter < lp.lp_letter; letter++ ) {
|
|
|
|
- sprintf( name, "df%c%03d%s", letter, lp.lp_seq, hostname );
|
|
|
|
+ snprintf( name, sizeof ( name ), "df%c%03d%s", letter, lp.lp_seq, hostname );
|
|
|
|
if ( unlink( name ) < 0 ) {
|
|
|
|
syslog( LOG_ERR, "lp_cancel unlink %s: %m", name );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- return;
|
|
|
|
+ return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -358,6 +395,7 @@ lp_cancel()
|
1999-12-15 02:54:39 +00:00
|
|
|
*
|
|
|
|
* XXX piped?
|
|
|
|
*/
|
|
|
|
+int
|
|
|
|
lp_print()
|
|
|
|
{
|
|
|
|
char buf[ MAXPATHLEN ];
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -368,19 +406,19 @@ lp_print()
|
1999-12-15 02:54:39 +00:00
|
|
|
FILE *cfile;
|
|
|
|
|
|
|
|
if (( lp.lp_flags & LP_INIT ) == 0 || lp.lp_letter == 'A' ) {
|
|
|
|
- return;
|
|
|
|
+ return (0);
|
|
|
|
}
|
|
|
|
lp_close();
|
|
|
|
|
|
|
|
if ( printer->p_flags & P_SPOOLED ) {
|
|
|
|
- sprintf( tfname, "tfA%03d%s", lp.lp_seq, hostname );
|
|
|
|
+ snprintf( tfname, sizeof ( tfname ), "tfA%03d%s", lp.lp_seq, hostname );
|
|
|
|
if (( fd = open( tfname, O_WRONLY|O_EXCL|O_CREAT, 0660 )) < 0 ) {
|
|
|
|
syslog( LOG_ERR, "lp_print %s: %m", tfname );
|
|
|
|
- return;
|
|
|
|
+ return(0);
|
|
|
|
}
|
|
|
|
if (( cfile = fdopen( fd, "w" )) == NULL ) {
|
|
|
|
syslog( LOG_ERR, "lp_print %s: %m", tfname );
|
|
|
|
- return;
|
|
|
|
+ return(0);
|
|
|
|
}
|
|
|
|
fprintf( cfile, "H%s\n", hostname ); /* XXX lp_host? */
|
|
|
|
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -418,46 +456,48 @@ lp_print()
|
1999-12-15 02:54:39 +00:00
|
|
|
}
|
|
|
|
fclose( cfile );
|
|
|
|
|
|
|
|
- sprintf( cfname, "cfA%03d%s", lp.lp_seq, hostname );
|
|
|
|
+ snprintf( cfname, sizeof ( cfname ), "cfA%03d%s", lp.lp_seq, hostname );
|
|
|
|
if ( link( tfname, cfname ) < 0 ) {
|
|
|
|
syslog( LOG_ERR, "lp_print can't link %s to %s: %m", cfname,
|
|
|
|
tfname );
|
|
|
|
- return;
|
|
|
|
+ return(0);
|
|
|
|
}
|
|
|
|
unlink( tfname );
|
|
|
|
|
|
|
|
if (( s = lp_conn_unix()) < 0 ) {
|
|
|
|
syslog( LOG_ERR, "lp_print: lp_conn_unix: %m" );
|
|
|
|
- return;
|
|
|
|
+ return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
- sprintf( buf, "\1%s\n", printer->p_printer );
|
|
|
|
+ snprintf( buf, sizeof ( buf ), "\1%s\n", printer->p_printer );
|
|
|
|
n = strlen( buf );
|
|
|
|
if ( write( s, buf, n ) != n ) {
|
|
|
|
syslog( LOG_ERR, "lp_print write: %m" );
|
|
|
|
- return;
|
|
|
|
+ return(0);
|
|
|
|
}
|
|
|
|
if ( read( s, buf, 1 ) != 1 ) {
|
|
|
|
syslog( LOG_ERR, "lp_print read: %m" );
|
|
|
|
- return;
|
|
|
|
+ return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
lp_disconn_unix( s );
|
|
|
|
|
|
|
|
if ( buf[ 0 ] != '\0' ) {
|
|
|
|
syslog( LOG_ERR, "lp_print lpd said %c: %m", buf[ 0 ] );
|
|
|
|
- return;
|
|
|
|
+ return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
syslog( LOG_INFO, "lp_print queued" );
|
|
|
|
- return;
|
|
|
|
+ return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
+int
|
|
|
|
lp_disconn_unix( fd )
|
|
|
|
{
|
|
|
|
return( close( fd ));
|
|
|
|
}
|
|
|
|
|
|
|
|
+int
|
|
|
|
lp_conn_unix()
|
|
|
|
{
|
|
|
|
int s;
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -467,11 +507,11 @@ lp_conn_unix()
|
1999-12-15 02:54:39 +00:00
|
|
|
syslog( LOG_ERR, "lp_conn_unix socket: %m" );
|
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
- bzero( &saun, sizeof( struct sockaddr_un ));
|
|
|
|
+ memset( &saun, 0,sizeof( struct sockaddr_un ));
|
|
|
|
saun.sun_family = AF_UNIX;
|
|
|
|
- strcpy( saun.sun_path, _PATH_DEVPRINTER );
|
2000-06-12 17:27:33 +00:00
|
|
|
+ (void)strlcpy( saun.sun_path, _PATH_DEVPRINTER, sizeof(saun.sun_path) );
|
1999-12-15 02:54:39 +00:00
|
|
|
if ( connect( s, (struct sockaddr *)&saun,
|
2000-06-12 17:27:33 +00:00
|
|
|
- strlen( saun.sun_path ) + 2 ) < 0 ) {
|
|
|
|
+ (strlen( saun.sun_path ) + 2) ) < 0 ) {
|
1999-12-15 02:54:39 +00:00
|
|
|
syslog( LOG_ERR, "lp_conn_unix connect %s: %m", saun.sun_path );
|
2000-06-12 17:27:33 +00:00
|
|
|
close( s );
|
|
|
|
return( -1 );
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -480,11 +520,13 @@ lp_conn_unix()
|
1999-12-15 02:54:39 +00:00
|
|
|
return( s );
|
|
|
|
}
|
|
|
|
|
|
|
|
+int
|
|
|
|
lp_disconn_inet( fd )
|
|
|
|
{
|
|
|
|
return( close( fd ));
|
|
|
|
}
|
|
|
|
|
|
|
|
+int
|
|
|
|
lp_conn_inet()
|
|
|
|
{
|
|
|
|
int privfd, port = IPPORT_RESERVED - 1;
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -513,10 +555,10 @@ lp_conn_inet()
|
1999-12-15 02:54:39 +00:00
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
- bzero( &sin, sizeof( struct sockaddr_in ));
|
|
|
|
+ memset( &sin, 0, sizeof( struct sockaddr_in ));
|
|
|
|
sin.sin_family = AF_INET;
|
|
|
|
/* sin.sin_addr.s_addr = htonl( INADDR_LOOPBACK ); */
|
|
|
|
- bcopy( hp->h_addr, &sin.sin_addr, hp->h_length );
|
|
|
|
+ memcpy( &sin.sin_addr, hp->h_addr, hp->h_length );
|
|
|
|
sin.sin_port = sp->s_port;
|
|
|
|
|
|
|
|
if ( connect( privfd, (struct sockaddr *)&sin,
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -529,6 +571,7 @@ lp_conn_inet()
|
1999-12-15 02:54:39 +00:00
|
|
|
return( privfd );
|
|
|
|
}
|
|
|
|
|
|
|
|
+int
|
|
|
|
lp_rmjob( job )
|
|
|
|
int job;
|
|
|
|
{
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -544,7 +587,7 @@ lp_rmjob( job )
|
1999-12-15 02:54:39 +00:00
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
- sprintf( buf, "\5%s %s %d\n", printer->p_printer, lp.lp_person, job );
|
|
|
|
+ snprintf( buf, sizeof ( buf ), "\5%s %s %d\n", printer->p_printer, lp.lp_person, job );
|
|
|
|
n = strlen( buf );
|
|
|
|
if ( write( s, buf, n ) != n ) {
|
|
|
|
syslog( LOG_ERR, "lp_rmjob write: %m" );
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -569,6 +612,7 @@ char *tag_files = "files: ";
|
1999-12-15 02:54:39 +00:00
|
|
|
char *tag_size = "size: ";
|
|
|
|
char *tag_status = "status: ";
|
|
|
|
|
|
|
|
+int
|
|
|
|
lp_queue( out )
|
|
|
|
struct papfile *out;
|
|
|
|
{
|
2001-04-18 13:17:43 +00:00
|
|
|
@@ -581,7 +625,7 @@ lp_queue( out )
|
1999-12-15 02:54:39 +00:00
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
- sprintf( buf, "\3%s\n", printer->p_printer );
|
|
|
|
+ snprintf( buf, sizeof( buf ), "\3%s\n", printer->p_printer );
|
|
|
|
n = strlen( buf );
|
|
|
|
if ( write( s, buf, n ) != n ) {
|
|
|
|
syslog( LOG_ERR, "lp_queue write: %m" );
|