From eb1123e5009c900c0eb741c0a075f918b16bbeab Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 15 Jul 2005 17:38:55 +0000 Subject: r8506: BUG 2853: don't strip out characters like '$' from printer names when substituting for the lpq command. (This used to be commit 2f5de718a98e56fe55d8905b12505dfc3e432544) --- source3/lib/util_str.c | 15 ++++++++++++--- source3/printing/printing.c | 24 ++++++++---------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 42229f105a1..6b91a0d625e 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -916,7 +916,7 @@ BOOL string_set(char **dest,const char *src) 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 @@ void string_sub(char *s,const char *pattern, const char *insert, size_t len) 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) } } +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)); diff --git a/source3/printing/printing.c b/source3/printing/printing.c index 0737cf00d1d..b49f0716ea4 100644 --- a/source3/printing/printing.c +++ b/source3/printing/printing.c @@ -43,13 +43,6 @@ static BOOL remove_from_jobs_changed(const char* sharename, uint32 jobid); 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 @@ this is the receive function of the background lpq updater ****************************************************************************/ 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,12 +1298,9 @@ static void print_queue_receive(int msg_type, pid_t src, void *buf, size_t msgle return; } - ctx.sharename = sharename; - ctx.lpqcommand = lpqcommand; - - print_queue_update_with_lock(ctx.sharename, - get_printer_fns_from_type(ctx.printing_type), - ctx.lpqcommand ); + print_queue_update_with_lock(sharename, + get_printer_fns_from_type(printing_type), + lpqcommand ); return; } @@ -1390,8 +1380,10 @@ static void print_queue_update(int snum, BOOL force) 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) ); /* -- cgit