static int generic_job_submit(int snum, struct printjob *pjob) { int ret; pstring current_directory; pstring print_directory; char *wd, *p; pstring jobname; fstring job_page_count, job_size; /* we print from the directory path to give the best chance of parsing the lpq output */ wd = sys_getwd(current_directory); if (!wd) return 0; pstrcpy(print_directory, pjob->filename); p = strrchr_m(print_directory,'/'); if (!p) return 0; *p++ = 0; if (chdir(print_directory) != 0) return 0; pstrcpy(jobname, pjob->jobname); pstring_sub(jobname, "'", "_"); slprintf(job_page_count, sizeof(job_page_count)-1, "%d", pjob->page_count); slprintf(job_size, sizeof(job_size)-1, "%lu", (unsigned long)pjob->size); /* send it to the system spooler */ ret = print_run_command(snum, PRINTERNAME(snum), True, lp_printcommand(snum), NULL, "%s", p, "%J", jobname, "%f", p, "%z", job_size, "%c", job_page_count, NULL); chdir(wd); return ret; }
static int generic_job_submit(int snum, struct printjob *pjob) { int ret = -1; char *current_directory = NULL; char *print_directory = NULL; char *wd = NULL; char *p = NULL; char *jobname = NULL; TALLOC_CTX *ctx = talloc_tos(); fstring job_page_count, job_size; /* we print from the directory path to give the best chance of parsing the lpq output */ wd = sys_getwd(); if (!wd) { return -1; } current_directory = talloc_strdup(ctx, wd); SAFE_FREE(wd); if (!current_directory) { return -1; } print_directory = talloc_strdup(ctx, pjob->filename); if (!print_directory) { return -1; } p = strrchr_m(print_directory,'/'); if (!p) { return -1; } *p++ = 0; if (chdir(print_directory) != 0) { return -1; } jobname = talloc_strdup(ctx, pjob->jobname); if (!jobname) { ret = -1; goto out; } jobname = talloc_string_sub(ctx, jobname, "'", "_"); if (!jobname) { ret = -1; goto out; } slprintf(job_page_count, sizeof(job_page_count)-1, "%d", pjob->page_count); slprintf(job_size, sizeof(job_size)-1, "%lu", (unsigned long)pjob->size); /* send it to the system spooler */ ret = print_run_command(snum, lp_printername(snum), True, lp_printcommand(snum), NULL, "%s", p, "%J", jobname, "%f", p, "%z", job_size, "%c", job_page_count, NULL); out: if (chdir(current_directory) == -1) { smb_panic("chdir failed in generic_job_submit"); } TALLOC_FREE(current_directory); return ret; }