diff options
author | Jeremy Allison <jra@samba.org> | 2007-12-07 17:32:32 -0800 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2007-12-07 17:32:32 -0800 |
commit | 42cfffae80480eae4381902fff3f7c61f858a933 (patch) | |
tree | 2fc1bc486fa988a4f2854310bcf91943db1aa566 /source3/printing | |
parent | 25288b0e4472c728fc5a3a70c6c3e1f621ffae5f (diff) | |
download | samba-42cfffae80480eae4381902fff3f7c61f858a933.tar.gz samba-42cfffae80480eae4381902fff3f7c61f858a933.tar.bz2 samba-42cfffae80480eae4381902fff3f7c61f858a933.zip |
Remove next_token - all uses must now be next_token_talloc.
No more temptations to use static length strings.
Jeremy.
(This used to be commit ec003f39369910dee852b7cafb883ddaa321c2de)
Diffstat (limited to 'source3/printing')
-rw-r--r-- | source3/printing/lpq_parse.c | 168 |
1 files changed, 113 insertions, 55 deletions
diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c index d4520b04ba..56e228f219 100644 --- a/source3/printing/lpq_parse.c +++ b/source3/printing/lpq_parse.c @@ -27,7 +27,7 @@ static const char *Months[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", Process time fields ********************************************************************/ -static time_t EntryTime(fstring tok[], int ptr, int count, int minimum) +static time_t EntryTime(char *tok[], int ptr, int count, int minimum) { time_t jobtime,jobtime1; @@ -35,7 +35,6 @@ static time_t EntryTime(fstring tok[], int ptr, int count, int minimum) if (count >= minimum) { struct tm *t; int i, day, hour, min, sec; - char *c; for (i=0; i<13; i++) { if (!strncmp(tok[ptr], Months[i],3)) { @@ -44,12 +43,13 @@ static time_t EntryTime(fstring tok[], int ptr, int count, int minimum) } if (i<12) { + fstring c; t = localtime(&jobtime); if (!t) { return (time_t)-1; } day = atoi(tok[ptr+1]); - c=(char *)(tok[ptr+2]); + fstrcpy(c,tok[ptr+2]); *(c+2)=0; hour = atoi(c); *(c+5)=0; @@ -143,7 +143,7 @@ static bool parse_lpq_bsd(char *line,print_queue_struct *buf,bool first) } #endif /* OSF1 */ - /* FIXME: Use next_token rather than strtok! */ + /* FIXME: Use next_token_talloc rather than strtok! */ tok[0] = strtok(line2," \t"); count++; @@ -255,22 +255,26 @@ static bool parse_lpq_lprng(char *line,print_queue_struct *buf,bool first) #define LPRNG_NTOK 7 #define LPRNG_MAXTOK 128 /* PFMA just to keep us from running away. */ - fstring tokarr[LPRNG_MAXTOK]; + char *tokarr[LPRNG_MAXTOK]; const char *cptr; char *ptr; int num_tok = 0; + TALLOC_CTX *frame = talloc_stackframe(); cptr = line; - while((num_tok < LPRNG_MAXTOK) && next_token( &cptr, tokarr[num_tok], " \t", sizeof(fstring))) { + while((num_tok < LPRNG_MAXTOK) && next_token_talloc(frame, &cptr, + &tokarr[num_tok], " \t")) { num_tok++; } /* We must get at least LPRNG_NTOK tokens. */ if (num_tok < LPRNG_NTOK) { + TALLOC_FREE(frame); return False; } if (!isdigit((int)*tokarr[LPRNG_JOBTOK]) || !isdigit((int)*tokarr[LPRNG_TOTALTOK])) { + TALLOC_FREE(frame); return False; } @@ -317,6 +321,7 @@ static bool parse_lpq_lprng(char *line,print_queue_struct *buf,bool first) buf->fs_file[sizeof(buf->fs_file)-1] = '\0'; } + TALLOC_FREE(frame); return True; } @@ -335,16 +340,18 @@ lazer lazer RUNNING 537 6297doc.A kvintus@IE 0 10 2445 1 1 static bool parse_lpq_aix(char *line,print_queue_struct *buf,bool first) { - fstring tok[11]; + char *tok[11]; int count=0; const char *cline = line; + TALLOC_CTX *frame = talloc_stackframe(); /* handle the case of "(standard input)" as a filename */ string_sub(line,"standard input","STDIN",0); all_string_sub(line,"(","\"",0); all_string_sub(line,")","\"",0); - for (count=0; count<10 && next_token(&cline,tok[count],NULL, sizeof(tok[count])); count++) { + for (count=0; count<10 && + next_token_talloc(frame,&cline,&tok[count],NULL); count++) { ; } @@ -353,21 +360,24 @@ static bool parse_lpq_aix(char *line,print_queue_struct *buf,bool first) if ((count == 7) && ((strcmp(tok[0],"QUEUED") == 0) || (strcmp(tok[0],"HELD") == 0))) { /* the 2nd and 5th columns must be integer */ if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4])) { + TALLOC_FREE(frame); return False; } buf->size = atoi(tok[4]) * 1024; /* if the fname contains a space then use STDIN */ if (strchr_m(tok[2],' ')) { - fstrcpy(tok[2],"STDIN"); + tok[2] = talloc_strdup(frame,"STDIN"); + if (!tok[2]) { + TALLOC_FREE(frame); + return false; + } } /* only take the last part of the filename */ { - fstring tmp; char *p = strrchr_m(tok[2],'/'); if (p) { - fstrcpy(tmp,p+1); - fstrcpy(tok[2],tmp); + tok[2] = p+1; } } @@ -379,27 +389,31 @@ static bool parse_lpq_aix(char *line,print_queue_struct *buf,bool first) fstrcpy(buf->fs_file,tok[2]); } else { DEBUG(6,("parse_lpq_aix count=%d\n", count)); + TALLOC_FREE(frame); return False; } } else { /* the 4th and 9th columns must be integer */ if (!isdigit((int)*tok[3]) || !isdigit((int)*tok[8])) { + TALLOC_FREE(frame); return False; } buf->size = atoi(tok[8]) * 1024; /* if the fname contains a space then use STDIN */ if (strchr_m(tok[4],' ')) { - fstrcpy(tok[4],"STDIN"); + tok[4] = talloc_strdup(frame,"STDIN"); + if (!tok[4]) { + TALLOC_FREE(frame); + return false; + } } /* only take the last part of the filename */ { - fstring tmp; char *p = strrchr_m(tok[4],'/'); if (p) { - fstrcpy(tmp,p+1); - fstrcpy(tok[4],tmp); + tok[4] = p+1; } } @@ -411,6 +425,7 @@ static bool parse_lpq_aix(char *line,print_queue_struct *buf,bool first) fstrcpy(buf->fs_file,tok[4]); } + TALLOC_FREE(frame); return True; } @@ -438,12 +453,13 @@ static bool parse_lpq_hpux(char *line, print_queue_struct *buf, bool first) with -p option first, to work */ static int base_prio; int count; - char htab = '\011'; + char htab = '\011'; const char *cline = line; - fstring tok[12]; + char *tok[12]; + TALLOC_CTX *frame = talloc_stackframe(); /* If a line begins with a horizontal TAB, it is a subline type */ - + if (line[0] == htab) { /* subline */ /* check if it contains the base priority */ if (!strncmp(line,"\tfence priority : ",18)) { @@ -452,6 +468,7 @@ static bool parse_lpq_hpux(char *line, print_queue_struct *buf, bool first) } if (!header_line_ok) { + TALLOC_FREE(frame); return False; /* incorrect header line */ } @@ -459,35 +476,44 @@ static bool parse_lpq_hpux(char *line, print_queue_struct *buf, bool first) string_sub(line,"standard input","STDIN",0); all_string_sub(line,"(","\"",0); all_string_sub(line,")","\"",0); - - for (count=0; count<2 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) { + + for (count=0; count<2 && + next_token_talloc(frame, &cline, &tok[count],NULL); + count++) { ; } /* we must get 2 tokens */ if (count < 2) { + TALLOC_FREE(frame); return False; } - + /* the 2nd column must be integer */ if (!isdigit((int)*tok[1])) { + TALLOC_FREE(frame); return False; } - + /* if the fname contains a space then use STDIN */ if (strchr_m(tok[0],' ')) { - fstrcpy(tok[0],"STDIN"); + tok[0] = talloc_strdup(frame, "STDIN"); + if (!tok[0]) { + TALLOC_FREE(frame); + return false; + } } - + buf->size = atoi(tok[1]); fstrcpy(buf->fs_file,tok[0]); - + /* fill things from header line */ buf->time = jobtime; buf->job = jobid; buf->status = jobstat; buf->priority = jobprio; fstrcpy(buf->fs_user,jobuser); - + + TALLOC_FREE(frame); return True; } else { /* header line */ header_line_ok=False; /* reset it */ @@ -499,28 +525,32 @@ static bool parse_lpq_hpux(char *line, print_queue_struct *buf, bool first) } else if (base_prio) { base_prio_reset=False; } - + /* handle the dash in the job id */ string_sub(line,"-"," ",0); - - for (count=0; count<12 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) { + + for (count=0; count<12 && + next_token_talloc(frame, &cline, &tok[count],NULL); + count++) { ; } - + /* we must get 8 tokens */ if (count < 8) { + TALLOC_FREE(frame); return False; } - + /* first token must be printer name (cannot check ?) */ /* the 2nd, 5th & 7th column must be integer */ if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4]) || !isdigit((int)*tok[6])) { + TALLOC_FREE(frame); return False; } jobid = atoi(tok[1]); fstrcpy(jobuser,tok[2]); jobprio = atoi(tok[4]); - + /* process time */ jobtime=EntryTime(tok, 5, count, 8); if (jobprio < base_prio) { @@ -535,8 +565,9 @@ static bool parse_lpq_hpux(char *line, print_queue_struct *buf, bool first) jobstat = LPQ_PRINTING; } } - + header_line_ok=True; /* information is correct */ + TALLOC_FREE(frame); return False; /* need subline info to include into queuelist */ } } @@ -553,12 +584,13 @@ dcslw-897 tridge 4712 Dec 20 10:30:30 being held static bool parse_lpq_sysv(char *line,print_queue_struct *buf,bool first) { - fstring tok[9]; + char *tok[9]; int count=0; char *p; const char *cline = line; + TALLOC_CTX *frame = NULL; - /* + /* * Handle the dash in the job id, but make sure that we skip over * the printer name in case we have a dash in that. * Patch from Dom.Mitchell@palmerharvey.co.uk. @@ -583,28 +615,32 @@ static bool parse_lpq_sysv(char *line,print_queue_struct *buf,bool first) *p = ' '; } - for (count=0; count<9 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) { + frame = talloc_stackframe(); + for (count=0; count<9 && + next_token_talloc(frame, &cline, &tok[count],NULL); + count++) { ; } /* we must get 7 tokens */ if (count < 7) { + TALLOC_FREE(frame); return False; } /* the 2nd and 4th, 6th columns must be integer */ if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[3])) { + TALLOC_FREE(frame); return False; } if (!isdigit((int)*tok[5])) { + TALLOC_FREE(frame); return False; } - /* if the user contains a ! then trim the first part of it */ + /* if the user contains a ! then trim the first part of it */ if ((p=strchr_m(tok[2],'!'))) { - fstring tmp; - fstrcpy(tmp,p+1); - fstrcpy(tok[2],tmp); + tok[2] = p+1; } buf->job = atoi(tok[1]); @@ -620,6 +656,7 @@ static bool parse_lpq_sysv(char *line,print_queue_struct *buf,bool first) buf->time = EntryTime(tok, 4, count, 7); fstrcpy(buf->fs_user,tok[2]); fstrcpy(buf->fs_file,tok[2]); + TALLOC_FREE(frame); return True; } @@ -628,7 +665,7 @@ parse a lpq line here is an example of lpq output under qnx Spooler: /qnx/spooler, on node 1 -Printer: txt (ready) +Printer: txt (ready) 0000: root [job #1 ] active 1146 bytes /etc/profile 0001: root [job #2 ] ready 2378 bytes /etc/install 0002: root [job #3 ] ready 1146 bytes -- standard input -- @@ -636,9 +673,10 @@ Printer: txt (ready) static bool parse_lpq_qnx(char *line,print_queue_struct *buf,bool first) { - fstring tok[7]; + char *tok[7]; int count=0; const char *cline = line; + TALLOC_CTX *frame = NULL; DEBUG(4,("antes [%s]\n", line)); @@ -653,30 +691,33 @@ static bool parse_lpq_qnx(char *line,print_queue_struct *buf,bool first) string_sub(line,"]","",0); DEBUG(4,("despues 2 [%s]\n", line)); - for (count=0; count<7 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) { + frame = talloc_stackframe(); + for (count=0; count<7 && + next_token_talloc(frame,&cline,&tok[count],NULL); + count++) { ; } /* we must get 7 tokens */ if (count < 7) { + TALLOC_FREE(frame); return False; } /* the 3rd and 5th columns must be integer */ if (!isdigit((int)*tok[2]) || !isdigit((int)*tok[4])) { + TALLOC_FREE(frame); return False; } /* only take the last part of the filename */ { - fstring tmp; char *p = strrchr_m(tok[6],'/'); if (p) { - fstrcpy(tmp,p+1); - fstrcpy(tok[6],tmp); + tok[6] = p+1; } } - + buf->job = atoi(tok[2]); buf->size = atoi(tok[4]); buf->status = strequal(tok[3],"active")?LPQ_PRINTING:LPQ_QUEUED; @@ -684,6 +725,7 @@ static bool parse_lpq_qnx(char *line,print_queue_struct *buf,bool first) buf->time = time(NULL); fstrcpy(buf->fs_user,tok[1]); fstrcpy(buf->fs_file,tok[6]); + TALLOC_FREE(frame); return True; } @@ -703,37 +745,47 @@ Local Printer 'lp2' (fjall): static bool parse_lpq_plp(char *line,print_queue_struct *buf,bool first) { - fstring tok[11]; + char *tok[11]; int count=0; const char *cline = line; + TALLOC_CTX *frame = talloc_stackframe(); /* handle the case of "(standard input)" as a filename */ string_sub(line,"stdin","STDIN",0); all_string_sub(line,"(","\"",0); all_string_sub(line,")","\"",0); - - for (count=0; count<11 && next_token(&cline,tok[count],NULL,sizeof(tok[count])); count++) { + + for (count=0; count<11 && + next_token_talloc(frame,&cline,&tok[count],NULL); + count++) { ; } /* we must get 11 tokens */ if (count < 11) { + TALLOC_FREE(frame); return False; } /* the first must be "active" or begin with an integer */ if (strcmp(tok[0],"active") && !isdigit((int)tok[0][0])) { + TALLOC_FREE(frame); return False; } /* the 5th and 8th must be integer */ if (!isdigit((int)*tok[4]) || !isdigit((int)*tok[7])) { + TALLOC_FREE(frame); return False; } /* if the fname contains a space then use STDIN */ if (strchr_m(tok[6],' ')) { - fstrcpy(tok[6],"STDIN"); + tok[6] = talloc_strdup(frame, "STDIN"); + if (!tok[6]) { + TALLOC_FREE(frame); + return false; + } } /* only take the last part of the filename */ @@ -761,6 +813,7 @@ static bool parse_lpq_plp(char *line,print_queue_struct *buf,bool first) buf->time = time(NULL); fstrcpy(buf->fs_user,tok[1]); fstrcpy(buf->fs_file,tok[6]); + TALLOC_FREE(frame); return True; } @@ -944,16 +997,20 @@ parse a vlp line static bool parse_lpq_vlp(char *line,print_queue_struct *buf,bool first) { int toknum = 0; - fstring tok; + char *tok; + TALLOC_CTX *frame = talloc_stackframe(); const char *cline = line; /* First line is printer status */ - if (!isdigit(line[0])) return False; + if (!isdigit(line[0])) { + TALLOC_FREE(frame); + return False; + } /* Parse a print job entry */ - while(next_token(&cline, tok, NULL, sizeof(fstring))) { + while(next_token_talloc(frame, &cline, &tok, NULL)) { switch (toknum) { case 0: buf->job = atoi(tok); @@ -977,6 +1034,7 @@ static bool parse_lpq_vlp(char *line,print_queue_struct *buf,bool first) toknum++; } + TALLOC_FREE(frame); return True; } |