X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=etc%2Fpapd%2Fqueries.c;h=ef1c5a6e8991c0e074408dbac5fd3563397ae101;hb=815d557e167e76015934397dffbfa869180dcdbc;hp=af5fad79e68936459ca4648795dc71444b164731;hpb=19657d41043cf48a7767c4d7a995d002c24e1d7a;p=netatalk.git diff --git a/etc/papd/queries.c b/etc/papd/queries.c index af5fad79..ef1c5a6e 100644 --- a/etc/papd/queries.c +++ b/etc/papd/queries.c @@ -1,5 +1,5 @@ /* - * $Id: queries.c,v 1.11 2002-02-15 07:12:41 morgana Exp $ + * $Id: queries.c,v 1.22 2009-10-13 22:55:37 didg Exp $ * * Copyright (c) 1990,1994 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -50,13 +50,14 @@ int cq_font( struct papfile *, struct papfile * ); int cq_feature( struct papfile *, struct papfile * ); int cq_printer( struct papfile *, struct papfile * ); int cq_rmjob( struct papfile *, struct papfile * ); +#ifndef HAVE_CUPS int cq_listq( struct papfile *, struct papfile * ); int cq_rbilogin( struct papfile *, struct papfile * ); +#endif /* HAVE_CUPS */ -int cq_default( in, out ) - struct papfile *in, *out; +int cq_default( struct papfile *in, struct papfile *out) { char *start, *stop, *p; int linelength, crlflength; @@ -69,6 +70,9 @@ int cq_default( in, out ) case -1 : return( CH_MORE ); + + case -2 : + return( CH_ERROR ); } stop = start+linelength; @@ -89,9 +93,11 @@ int cq_default( in, out ) break; } } - p++; - while ( *p == ' ' ) { + if (p < stop) { p++; + while ( *p == ' ' ) { + p++; + } } append( out, p, stop - p + crlflength ); @@ -111,8 +117,7 @@ char *LoginFailed = "LoginFailed\n"; #define h2b(x) (isdigit((x))?(x)-'0':(isupper((x))?(x)-'A':(x)-'a')+10) -int cq_k4login( in, out ) - struct papfile *in, *out; +int cq_k4login( struct papfile *in, struct papfile *out) { char *start, *p; int linelength, crlflength; @@ -128,6 +133,9 @@ int cq_k4login( in, out ) case -1 : return( CH_MORE ); + + case -2 : + return( CH_ERROR ); } p = start + strlen( comment->c_begin ); @@ -137,6 +145,7 @@ int cq_k4login( in, out ) bzero( &tkt, sizeof( tkt )); stop = start+linelength; + /* FIXME */ for ( i = 0, t = tkt.dat; p < stop; p += 2, t++, i++ ) { *t = ( h2b( (unsigned char)*p ) << 4 ) + h2b( (unsigned char)*( p + 1 )); @@ -145,13 +154,13 @@ int cq_k4login( in, out ) if (( rc = krb_rd_req( &tkt, "LaserWriter", printer->p_name, 0, &ad, "" )) != RD_AP_OK ) { - LOG(log_error, logtype_default, "cq_k4login: %s", krb_err_txt[ rc ] ); + LOG(log_error, logtype_papd, "cq_k4login: %s", krb_err_txt[ rc ] ); append( out, LoginFailed, strlen( LoginFailed )); compop(); CONSUME( in, linelength + crlflength ); return( CH_DONE ); } - LOG(log_info, logtype_default, "cq_k4login: %s.%s@%s", ad.pname, ad.pinst, + LOG(log_info, logtype_papd, "cq_k4login: %s.%s@%s", ad.pname, ad.pinst, ad.prealm ); lp_person( ad.pname ); lp_host( ad.prealm ); @@ -164,8 +173,7 @@ int cq_k4login( in, out ) char *uameth = "UMICHKerberosIV\n*\n"; -int cq_uameth( in, out ) - struct papfile *in, *out; +int cq_uameth( struct papfile *in, struct papfile *out) { char *start; int linelength, crlflength; @@ -178,12 +186,15 @@ int cq_uameth( in, out ) case -1 : return( CH_MORE ); + + case -2 : + return( CH_ERROR ); } if ( comgetflags() == 0 ) { /* start */ if (( printer->p_flags & P_KRB ) == 0 ) { /* no kerberos */ if ( comswitch( queries, cq_default ) < 0 ) { - LOG(log_error, logtype_default, "cq_uameth: can't find default!" ); + LOG(log_error, logtype_papd, "cq_uameth: can't find default!" ); exit( 1 ); } return( CH_DONE ); @@ -202,8 +213,7 @@ int cq_uameth( in, out ) } #endif /* KRB */ -int gq_true( out ) - struct papfile *out; +int gq_true( struct papfile *out) { if ( printer->p_flags & P_SPOOLED ) { append( out, "true\n", 5 ); @@ -213,8 +223,7 @@ int gq_true( out ) } } -int gq_pagecost( out ) - struct papfile *out; +int gq_pagecost( struct papfile *out) { char cost[ 60 ]; @@ -236,8 +245,7 @@ int gq_pagecost( out ) } #ifdef ABS_PRINT -int gq_balance( out ) - struct papfile *out; +int gq_balance( struct papfile *out) { char balance[ 60 ]; @@ -255,10 +263,9 @@ int gq_balance( out ) * Handler for RBISpoolerID */ -static const char *spoolerid = "(PAPD Spooler) 2.1 (2.1.4 pre-release)\n"; +static const char *spoolerid = "(PAPD Spooler) 1.0 (" VERSION ")\n"; -int gq_rbispoolerid( out ) - struct papfile *out; +int gq_rbispoolerid( struct papfile *out) { append( out, spoolerid, strlen( spoolerid )); return(0); @@ -272,8 +279,7 @@ int gq_rbispoolerid( out ) static const char *nouams = "*\n"; -int gq_rbiuamlist( out ) - struct papfile *out; +int gq_rbiuamlist( struct papfile *out) { char uamnames[128] = "\0"; @@ -305,11 +311,10 @@ struct genquery { { "ADOIsBinaryOK?", gq_true }, { "UMICHListQueue", gq_true }, { "UMICHDeleteJob", gq_true }, - { NULL }, + { NULL, NULL }, }; -int cq_query( in, out ) - struct papfile *in, *out; +int cq_query( struct papfile *in, struct papfile *out) { char *start, *stop, *p, *q; int linelength, crlflength; @@ -324,6 +329,9 @@ int cq_query( in, out ) case -1 : return( CH_MORE ); + + case -2 : + return( CH_ERROR ); } stop = start+linelength; @@ -337,7 +345,7 @@ int cq_query( in, out ) } } - for ( p++; p < stop; p++ ) { + if (p < stop) for ( p++; p < stop; p++ ) { if ( *p != ' ' && *p != '\t' ) { break; } @@ -350,7 +358,7 @@ int cq_query( in, out ) } for ( gq = genqueries; gq->gq_name; gq++ ) { - if (( strlen( gq->gq_name ) == q - p ) && + if (( strlen( gq->gq_name ) == (size_t)(q - p) ) && ( strncmp( gq->gq_name, p, q - p ) == 0 )) { break; } @@ -358,7 +366,7 @@ int cq_query( in, out ) if ( gq->gq_name == NULL || gq->gq_handler == NULL || (gq->gq_handler)( out ) < 0 ) { if ( comswitch( queries, cq_default ) < 0 ) { - LOG(log_error, logtype_default, "cq_feature: can't find default!" ); + LOG(log_error, logtype_papd, "cq_feature: can't find default!" ); exit( 1 ); } return( CH_DONE ); @@ -375,23 +383,23 @@ int cq_query( in, out ) } } -void cq_font_answer( start, stop, out ) - char *start, *stop; - struct papfile *out; +void cq_font_answer( char *start, char *stop, struct papfile *out) { char *p, *q, buf[ 256 ]; struct ppd_font *pfo; p = start; while ( p < stop ) { + unsigned int count = 0; while (( *p == ' ' || *p == '\t' ) && p < stop ) { p++; } q = buf; while ( *p != ' ' && *p != '\t' && - *p != '\n' && *p != '\r' && p < stop ) { + *p != '\n' && *p != '\r' && p < stop && count < sizeof(buf)) { *q++ = *p++; + count++; } if ( q != buf ) { @@ -412,8 +420,7 @@ void cq_font_answer( start, stop, out ) return; } -int cq_font( in, out ) - struct papfile *in, *out; +int cq_font(struct papfile *in, struct papfile *out) { char *start, *stop, *p; int linelength, crlflength; @@ -426,6 +433,9 @@ int cq_font( in, out ) case -1 : return( CH_MORE ); + + case -2 : + return( CH_ERROR ); } stop = start + linelength; @@ -438,7 +448,8 @@ int cq_font( in, out ) break; } } - p++; + if (p < stop) + p++; cq_font_answer( p, stop, out ); } else { @@ -451,7 +462,8 @@ int cq_font( in, out ) break; } } - p++; + if (p < stop) + p++; cq_font_answer( p, stop, out ); } else { @@ -469,8 +481,7 @@ int cq_font( in, out ) } } -int cq_feature( in, out ) - struct papfile *in, *out; +int cq_feature( struct papfile *in, struct papfile *out) { char *start, *stop, *p; int linelength, crlflength; @@ -484,6 +495,9 @@ int cq_feature( in, out ) case -1 : return( CH_MORE ); + + case -2 : + return( CH_ERROR ); } stop = start + linelength; @@ -497,14 +511,15 @@ int cq_feature( in, out ) break; } } - p++; + if (p < stop) + p++; while ( *p == ' ' ) { p++; } if (( pfe = ppd_feature( p, stop - p )) == NULL ) { if ( comswitch( queries, cq_default ) < 0 ) { - LOG(log_error, logtype_default, "cq_feature: can't find default!" ); + LOG(log_error, logtype_papd, "cq_feature: can't find default!" ); exit( 1 ); } return( CH_DONE ); @@ -527,8 +542,7 @@ int cq_feature( in, out ) static const char *psver = "*PSVersion\n"; static const char *prod = "*Product\n"; -int cq_printer( in, out ) - struct papfile *in, *out; +int cq_printer(struct papfile *in, struct papfile *out) { char *start, *p; int linelength, crlflength; @@ -542,6 +556,9 @@ int cq_printer( in, out ) case -1 : return( CH_MORE ); + + case -2 : + return( CH_ERROR ); } if ( comgetflags() == 0 ) { @@ -549,7 +566,7 @@ int cq_printer( in, out ) if (( pdpsver = ppd_feature( psver, strlen( psver ))) == NULL ) { if ( comswitch( queries, cq_default ) < 0 ) { - LOG(log_error, logtype_default, "cq_printer: can't find default!" ); + LOG(log_error, logtype_papd, "cq_printer: can't find default!" ); exit( 1 ); } return( CH_DONE ); @@ -561,9 +578,9 @@ int cq_printer( in, out ) } } if ( *p == '\0' ) { - LOG(log_error, logtype_default, "cq_printer: can't parse PSVersion!" ); + LOG(log_error, logtype_papd, "cq_printer: can't parse PSVersion!" ); if ( comswitch( queries, cq_default ) < 0 ) { - LOG(log_error, logtype_default, "cq_printer: can't find default!" ); + LOG(log_error, logtype_papd, "cq_printer: can't find default!" ); exit( 1 ); } return( CH_DONE ); @@ -571,7 +588,7 @@ int cq_printer( in, out ) if (( pdprod = ppd_feature( prod, strlen( prod ))) == NULL ) { if ( comswitch( queries, cq_default ) < 0 ) { - LOG(log_error, logtype_default, "cq_printer: can't find default!" ); + LOG(log_error, logtype_papd, "cq_printer: can't find default!" ); exit( 1 ); } return( CH_DONE ); @@ -600,11 +617,12 @@ int cq_printer( in, out ) } } +#ifndef HAVE_CUPS + static const char *rmjobfailed = "Failed\n"; static const char *rmjobok = "Ok\n"; -int cq_rmjob( in, out ) - struct papfile *in, *out; +int cq_rmjob( struct papfile *in, struct papfile *out) { char *start, *stop, *p; int linelength, crlflength; @@ -616,6 +634,9 @@ int cq_rmjob( in, out ) case -1 : return( CH_MORE ); + + case -2 : + return( CH_ERROR ); } stop = start + linelength; @@ -644,8 +665,7 @@ int cq_rmjob( in, out ) return( CH_DONE ); } -int cq_listq( in, out ) - struct papfile *in, *out; +int cq_listq( struct papfile *in, struct papfile *out) { char *start; int linelength, crlflength; @@ -656,16 +676,20 @@ int cq_listq( in, out ) case -1 : return( CH_MORE ); + + case -2 : + return( CH_ERROR ); } if ( lp_queue( out )) { - LOG(log_error, logtype_default, "cq_listq: lp_queue failed" ); + LOG(log_error, logtype_papd, "cq_listq: lp_queue failed" ); } compop(); CONSUME( in, linelength + crlflength ); return( CH_DONE ); } +#endif /* HAVE_CUPS */ /* @@ -677,17 +701,16 @@ static const char *rbiloginok = "0\r"; static const char *rbiloginbad = "-1\r"; static const char *rbiloginerrstr = "%%[Error: SecurityError; \ SecurityViolation: Unknown user, incorrect password or log on is \ -disabled ]%%\r%%Flushing: rest of job (to end-of-file) will be \ +disabled ]%%\r%%[Flushing: rest of job (to end-of-file) will be \ ignored ]%%\r"; -int cq_rbilogin( in, out ) - struct papfile *in, *out; +int cq_rbilogin( struct papfile *in, struct papfile *out) { char *start, *stop, *p, *begin; int linelength, crlflength; - char username[9] = "\0"; + char username[UAM_USERNAMELEN + 1] = "\0"; struct papd_comment *comment = compeek(); - char uamtype[20] = "\0"; + char uamtype[20]; for (;;) { switch ( markline( in, &start, &linelength, &crlflength )) { @@ -696,6 +719,9 @@ int cq_rbilogin( in, out ) case -1 : return( CH_MORE ); + + case -2 : + return( CH_ERROR ); } stop = start + linelength; @@ -704,20 +730,25 @@ int cq_rbilogin( in, out ) begin = start + strlen(comment->c_begin); p = begin; - while (*p != ' ') { + while (*p != ' ' && p < stop) { p++; } - strncat(uamtype, begin, p - begin); + memset(uamtype, 0, sizeof(uamtype)); + if ((size_t)(p -begin) <= sizeof(uamtype) -1) { + strncpy(uamtype, begin, p - begin); + } - if ((papd_uam = auth_uamfind(UAM_SERVER_PRINTAUTH, + if ( !*uamtype || (papd_uam = auth_uamfind(UAM_SERVER_PRINTAUTH, uamtype, strlen(uamtype))) == NULL) { - LOG(log_info, logtype_default, "Could not find uam: %s", uamtype); + LOG(log_info, logtype_papd, "Could not find uam: %s", uamtype); append(out, rbiloginbad, strlen(rbiloginbad)); append(out, rbiloginerrstr, strlen(rbiloginerrstr)); } else { if ( (papd_uam->u.uam_printer(p,stop,username,out)) == 0 ) { lp_person( username ); + append(out, rbiloginok, strlen( rbiloginok )); + LOG(log_info, logtype_papd, "RBILogin: Logged in '%s'", username); } else { append(out, rbiloginbad, strlen( rbiloginbad)); append(out, rbiloginerrstr, strlen(rbiloginerrstr)); @@ -742,16 +773,18 @@ int cq_rbilogin( in, out ) */ struct papd_comment queries[] = { #ifdef KRB - { "%%Login: UMICHKerberosIV", 0, cq_k4login, 0 }, - { "%%?BeginUAMethodsQuery", "%%?EndUAMethodsQuery:", cq_uameth, C_FULL }, + { "%%Login: UMICHKerberosIV", NULL, cq_k4login, 0 }, + { "%%?BeginUAMethodsQuery", "%%?EndUAMethodsQuery:", cq_uameth,C_FULL }, #endif /* KRB */ - { "%UMICHListQueue", 0, cq_listq, C_FULL }, - { "%UMICHDeleteJob", 0, cq_rmjob, 0 }, +#ifndef HAVE_CUPS + { "%UMICHListQueue", NULL, cq_listq, C_FULL }, + { "%UMICHDeleteJob", NULL, cq_rmjob, 0 }, +#endif /* HAVE_CUPS */ { "%%?BeginQuery: RBILogin ", "%%?EndQuery", cq_rbilogin, 0 }, { "%%?BeginQuery", "%%?EndQuery", cq_query, 0 }, { "%%?BeginFeatureQuery", "%%?EndFeatureQuery", cq_feature, 0 }, { "%%?BeginFontQuery", "%%?EndFontQuery", cq_font, 0 }, - { "%%?BeginPrinterQuery", "%%?EndPrinterQuery", cq_printer, C_FULL }, + { "%%?BeginPrinterQuery", "%%?EndPrinterQuery", cq_printer,C_FULL }, { "%%?Begin", "%%?End", cq_default, 0 }, - { 0 }, + { NULL, NULL, NULL, 0 }, };