Author: jerry Date: 2005-07-15 17:38:55 +0000 (Fri, 15 Jul 2005) New Revision: 8506
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=8506 Log: BUG 2853: don't strip out characters like '$' from printer names when substituting for the lpq command. Modified: branches/SAMBA_3_0/source/lib/util_str.c branches/SAMBA_3_0/source/printing/printing.c trunk/source/lib/util_str.c trunk/source/printing/printing.c Changeset: Modified: branches/SAMBA_3_0/source/lib/util_str.c =================================================================== --- branches/SAMBA_3_0/source/lib/util_str.c 2005-07-15 15:17:35 UTC (rev 8505) +++ branches/SAMBA_3_0/source/lib/util_str.c 2005-07-15 17:38:55 UTC (rev 8506) @@ -916,7 +916,7 @@ use of len==0 which was for no length checks to be done. **/ -void string_sub(char *s,const char *pattern, const char *insert, size_t len) +void string_sub2(char *s,const char *pattern, const char *insert, size_t len, BOOL remove_unsafe_characters) { char *p; ssize_t ls,lp,li, i; @@ -951,8 +951,12 @@ case '%': case '\r': case '\n': - p[i] = '_'; - break; + if ( remove_unsafe_characters ) { + p[i] = '_'; + /* yes this break should be here since we want to + fall throw if not replacing unsafe chars */ + break; + } default: p[i] = insert[i]; } @@ -962,6 +966,11 @@ } } +void string_sub(char *s,const char *pattern, const char *insert, size_t len) +{ + string_sub2( s, pattern, insert, len, True ); +} + void fstring_sub(char *s,const char *pattern,const char *insert) { string_sub(s, pattern, insert, sizeof(fstring)); Modified: branches/SAMBA_3_0/source/printing/printing.c =================================================================== --- branches/SAMBA_3_0/source/printing/printing.c 2005-07-15 15:17:35 UTC (rev 8505) +++ branches/SAMBA_3_0/source/printing/printing.c 2005-07-15 17:38:55 UTC (rev 8506) @@ -43,13 +43,6 @@ jobids are assigned when a job starts spooling. */ -struct print_queue_update_context { - char* sharename; - int printing_type; - char* lpqcommand; -}; - - static TDB_CONTEXT *rap_tdb; static uint16 next_rap_jobid; struct rap_jobid_key { @@ -1290,14 +1283,14 @@ ****************************************************************************/ static void print_queue_receive(int msg_type, pid_t src, void *buf, size_t msglen) { - struct print_queue_update_context ctx; fstring sharename; pstring lpqcommand; + int printing_type; size_t len; len = tdb_unpack( buf, msglen, "fdP", sharename, - &ctx.printing_type, + &printing_type, lpqcommand ); if ( len == -1 ) { @@ -1305,13 +1298,10 @@ return; } - ctx.sharename = sharename; - ctx.lpqcommand = lpqcommand; + print_queue_update_with_lock(sharename, + get_printer_fns_from_type(printing_type), + lpqcommand ); - print_queue_update_with_lock(ctx.sharename, - get_printer_fns_from_type(ctx.printing_type), - ctx.lpqcommand ); - return; } @@ -1390,8 +1380,10 @@ fstrcpy( sharename, lp_const_servicename(snum)); + /* don't strip out characters like '$' from the printername */ + pstrcpy( lpqcommand, lp_lpqcommand(snum)); - pstring_sub( lpqcommand, "%p", PRINTERNAME(snum) ); + string_sub2( lpqcommand, "%p", PRINTERNAME(snum), sizeof(lpqcommand), False ); standard_sub_snum( snum, lpqcommand, sizeof(lpqcommand) ); /* Modified: trunk/source/lib/util_str.c =================================================================== --- trunk/source/lib/util_str.c 2005-07-15 15:17:35 UTC (rev 8505) +++ trunk/source/lib/util_str.c 2005-07-15 17:38:55 UTC (rev 8506) @@ -916,7 +916,7 @@ use of len==0 which was for no length checks to be done. **/ -void string_sub(char *s,const char *pattern, const char *insert, size_t len) +void string_sub2(char *s,const char *pattern, const char *insert, size_t len, BOOL remove_unsafe_characters) { char *p; ssize_t ls,lp,li, i; @@ -951,8 +951,12 @@ case '%': case '\r': case '\n': - p[i] = '_'; - break; + if ( remove_unsafe_characters ) { + p[i] = '_'; + /* yes this break should be here since we want to + fall throw if not replacing unsafe chars */ + break; + } default: p[i] = insert[i]; } @@ -962,6 +966,11 @@ } } +void string_sub(char *s,const char *pattern, const char *insert, size_t len) +{ + string_sub2( s, pattern, insert, len, True ); +} + void fstring_sub(char *s,const char *pattern,const char *insert) { string_sub(s, pattern, insert, sizeof(fstring)); Modified: trunk/source/printing/printing.c =================================================================== --- trunk/source/printing/printing.c 2005-07-15 15:17:35 UTC (rev 8505) +++ trunk/source/printing/printing.c 2005-07-15 17:38:55 UTC (rev 8506) @@ -43,13 +43,6 @@ jobids are assigned when a job starts spooling. */ -struct print_queue_update_context { - char* sharename; - int printing_type; - char* lpqcommand; -}; - - static TDB_CONTEXT *rap_tdb; static uint16 next_rap_jobid; struct rap_jobid_key { @@ -1290,14 +1283,14 @@ ****************************************************************************/ static void print_queue_receive(int msg_type, pid_t src, void *buf, size_t msglen) { - struct print_queue_update_context ctx; fstring sharename; pstring lpqcommand; + int printing_type; size_t len; len = tdb_unpack( buf, msglen, "fdP", sharename, - &ctx.printing_type, + &printing_type, lpqcommand ); if ( len == -1 ) { @@ -1305,13 +1298,10 @@ return; } - ctx.sharename = sharename; - ctx.lpqcommand = lpqcommand; + print_queue_update_with_lock(sharename, + get_printer_fns_from_type(printing_type), + lpqcommand ); - print_queue_update_with_lock(ctx.sharename, - get_printer_fns_from_type(ctx.printing_type), - ctx.lpqcommand ); - return; } @@ -1390,8 +1380,10 @@ fstrcpy( sharename, lp_const_servicename(snum)); + /* don't strip out characters like '$' from the printername */ + pstrcpy( lpqcommand, lp_lpqcommand(snum)); - pstring_sub( lpqcommand, "%p", PRINTERNAME(snum) ); + string_sub2( lpqcommand, "%p", PRINTERNAME(snum), sizeof(lpqcommand), False ); standard_sub_snum( snum, lpqcommand, sizeof(lpqcommand) ); /*
