mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
Remove pstring from printing/*.c except for the
tdb_unpack requirement (I'll be making that an allocating interface later). Jeremy.
This commit is contained in:
parent
a04e916b89
commit
d2ee75326a
File diff suppressed because it is too large
Load Diff
@ -159,8 +159,9 @@ void pcap_cache_reload(void)
|
||||
goto done;
|
||||
}
|
||||
|
||||
for (; (pcap_line = fgets_slash(NULL, sizeof(pstring), pcap_file)) != NULL; safe_free(pcap_line)) {
|
||||
pstring name, comment;
|
||||
for (; (pcap_line = fgets_slash(NULL, 1024, pcap_file)) != NULL; safe_free(pcap_line)) {
|
||||
char name[MAXPRINTERLEN+1];
|
||||
char comment[62];
|
||||
char *p, *q;
|
||||
|
||||
if (*pcap_line == '#' || *pcap_line == 0)
|
||||
@ -186,22 +187,22 @@ void pcap_cache_reload(void)
|
||||
strchr_m(p, ')'));
|
||||
|
||||
if (strlen(p) > strlen(comment) && has_punctuation) {
|
||||
pstrcpy(comment, p);
|
||||
strlcpy(comment, p, sizeof(comment));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strlen(p) <= MAXPRINTERLEN &&
|
||||
strlen(p) > strlen(name) && !has_punctuation) {
|
||||
if (!*comment)
|
||||
pstrcpy(comment, name);
|
||||
|
||||
pstrcpy(name, p);
|
||||
if (!*comment) {
|
||||
strlcpy(comment, name, sizeof(comment));
|
||||
}
|
||||
strlcpy(name, p, sizeof(name));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strchr_m(comment, ' ') &&
|
||||
strlen(p) > strlen(comment)) {
|
||||
pstrcpy(comment, p);
|
||||
strlcpy(comment, p, sizeof(comment));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -32,21 +32,26 @@ bool aix_cache_reload(void)
|
||||
int iEtat;
|
||||
XFILE *pfile;
|
||||
char *line = NULL, *p;
|
||||
pstring name, comment;
|
||||
char *name;
|
||||
TALLOC_CTX *ctx = talloc_init("aix_cache_reload");
|
||||
|
||||
if (!ctx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*name = 0;
|
||||
*comment = 0;
|
||||
|
||||
DEBUG(5, ("reloading aix printcap cache\n"));
|
||||
|
||||
if ((pfile = x_fopen(lp_printcapname(), O_RDONLY, 0)) == NULL) {
|
||||
DEBUG(0,( "Unable to open qconfig file %s for read!\n", lp_printcapname()));
|
||||
return False;
|
||||
TALLOC_FREE(ctx);
|
||||
return false;
|
||||
}
|
||||
|
||||
iEtat = 0;
|
||||
/* scan qconfig file for searching <printername>: */
|
||||
for (;(line = fgets_slash(NULL, sizeof(pstring), pfile)); safe_free(line)) {
|
||||
for (;(line = fgets_slash(NULL, 1024, pfile)); safe_free(line)) {
|
||||
if (*line == '*' || *line == 0)
|
||||
continue;
|
||||
|
||||
@ -59,7 +64,13 @@ bool aix_cache_reload(void)
|
||||
*p = '\0';
|
||||
p = strtok(line, ":");
|
||||
if (strcmp(p, "bsh") != 0) {
|
||||
pstrcpy(name, p);
|
||||
name = talloc_strdup(ctx, p);
|
||||
if (!name) {
|
||||
safe_free(line);
|
||||
x_fclose(pfile);
|
||||
TALLOC_FREE(ctx);
|
||||
return false;
|
||||
}
|
||||
iEtat = 1;
|
||||
continue;
|
||||
}
|
||||
@ -77,11 +88,12 @@ bool aix_cache_reload(void)
|
||||
if (!pcap_cache_add(name, NULL)) {
|
||||
safe_free(line);
|
||||
x_fclose(pfile);
|
||||
return False;
|
||||
TALLOC_FREE(ctx);
|
||||
return false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (strstr_m(line, "backend")) {
|
||||
/* it's a device, not a virtual printer */
|
||||
iEtat = 0;
|
||||
@ -91,7 +103,8 @@ bool aix_cache_reload(void)
|
||||
if (!pcap_cache_add(name, NULL)) {
|
||||
safe_free(line);
|
||||
x_fclose(pfile);
|
||||
return False;
|
||||
TALLOC_FREE(ctx);
|
||||
return false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -100,7 +113,8 @@ bool aix_cache_reload(void)
|
||||
}
|
||||
|
||||
x_fclose(pfile);
|
||||
return True;
|
||||
TALLOC_FREE(ctx);
|
||||
return true;
|
||||
}
|
||||
|
||||
#else
|
||||
|
@ -564,8 +564,8 @@ static int cups_job_submit(int snum, struct printjob *pjob)
|
||||
cups_lang_t *language = NULL; /* Default language */
|
||||
char uri[HTTP_MAX_URI]; /* printer-uri attribute */
|
||||
const char *clientname = NULL; /* hostname of client for job-originating-host attribute */
|
||||
pstring new_jobname;
|
||||
int num_options = 0;
|
||||
char *new_jobname = NULL;
|
||||
int num_options = 0;
|
||||
cups_option_t *options = NULL;
|
||||
char addr[INET6_ADDRSTRLEN];
|
||||
|
||||
@ -627,8 +627,10 @@ static int cups_job_submit(int snum, struct printjob *pjob)
|
||||
"job-originating-host-name", NULL,
|
||||
clientname);
|
||||
|
||||
pstr_sprintf(new_jobname,"%s%.8u %s", PRINT_SPOOL_PREFIX,
|
||||
(unsigned int)pjob->smbjob, pjob->jobname);
|
||||
if (asprintf(&new_jobname,"%s%.8u %s", PRINT_SPOOL_PREFIX,
|
||||
(unsigned int)pjob->smbjob, pjob->jobname) < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
|
||||
new_jobname);
|
||||
@ -676,6 +678,8 @@ static int cups_job_submit(int snum, struct printjob *pjob)
|
||||
if (http)
|
||||
httpClose(http);
|
||||
|
||||
SAFE_FREE(new_jobname);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -24,45 +24,63 @@ extern struct current_user current_user;
|
||||
extern userdom_struct current_user_info;
|
||||
|
||||
/****************************************************************************
|
||||
run a given print command
|
||||
a null terminated list of value/substitute pairs is provided
|
||||
for local substitution strings
|
||||
Run a given print command
|
||||
a null terminated list of value/substitute pairs is provided
|
||||
for local substitution strings
|
||||
****************************************************************************/
|
||||
static int print_run_command(int snum, const char* printername, bool do_sub,
|
||||
const char *command, int *outfd, ...)
|
||||
{
|
||||
pstring syscmd;
|
||||
char *syscmd;
|
||||
char *arg;
|
||||
int ret;
|
||||
TALLOC_CTX *ctx = talloc_tos();
|
||||
va_list ap;
|
||||
va_start(ap, outfd);
|
||||
|
||||
/* check for a valid system printername and valid command to run */
|
||||
|
||||
if ( !printername || !*printername )
|
||||
if ( !printername || !*printername ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!command || !*command)
|
||||
if (!command || !*command) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
pstrcpy(syscmd, command);
|
||||
syscmd = talloc_strdup(ctx, command);
|
||||
if (!syscmd) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
while ((arg = va_arg(ap, char *))) {
|
||||
char *value = va_arg(ap,char *);
|
||||
pstring_sub(syscmd, arg, value);
|
||||
syscmd = talloc_string_sub(ctx, syscmd, arg, value);
|
||||
if (!syscmd) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
pstring_sub( syscmd, "%p", printername );
|
||||
|
||||
if ( do_sub && snum != -1 )
|
||||
standard_sub_advanced(lp_servicename(snum),
|
||||
current_user_info.unix_name, "",
|
||||
current_user.ut.gid,
|
||||
get_current_username(),
|
||||
current_user_info.domain,
|
||||
syscmd, sizeof(syscmd));
|
||||
|
||||
syscmd = talloc_string_sub(ctx, syscmd, "%p", printername);
|
||||
if (!syscmd) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (do_sub && snum != -1) {
|
||||
syscmd = talloc_sub_advanced(ctx,
|
||||
lp_servicename(snum),
|
||||
current_user_info.unix_name,
|
||||
"",
|
||||
current_user.ut.gid,
|
||||
get_current_username(),
|
||||
current_user_info.domain,
|
||||
syscmd);
|
||||
if (!syscmd) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
ret = smbrun_no_sanitize(syscmd,outfd);
|
||||
|
||||
DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret));
|
||||
@ -107,7 +125,7 @@ resume a job
|
||||
static int generic_job_resume(int snum, struct printjob *pjob)
|
||||
{
|
||||
fstring jobstr;
|
||||
|
||||
|
||||
/* need to pause the spooled entry */
|
||||
slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob);
|
||||
return print_run_command(snum, PRINTERNAME(snum), True,
|
||||
@ -122,30 +140,52 @@ static int generic_job_resume(int snum, struct printjob *pjob)
|
||||
|
||||
static int generic_job_submit(int snum, struct printjob *pjob)
|
||||
{
|
||||
int ret;
|
||||
pstring current_directory;
|
||||
pstring print_directory;
|
||||
char *wd, *p;
|
||||
pstring jobname;
|
||||
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 */
|
||||
current_directory = TALLOC_ARRAY(ctx,
|
||||
char,
|
||||
PATH_MAX+1);
|
||||
if (!current_directory) {
|
||||
return -1;
|
||||
}
|
||||
wd = sys_getwd(current_directory);
|
||||
if (!wd)
|
||||
return 0;
|
||||
if (!wd) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
pstrcpy(print_directory, pjob->filename);
|
||||
print_directory = talloc_strdup(ctx, pjob->filename);
|
||||
if (!print_directory) {
|
||||
return -1;
|
||||
}
|
||||
p = strrchr_m(print_directory,'/');
|
||||
if (!p)
|
||||
return 0;
|
||||
if (!p) {
|
||||
return -1;
|
||||
}
|
||||
*p++ = 0;
|
||||
|
||||
if (chdir(print_directory) != 0)
|
||||
return 0;
|
||||
if (chdir(print_directory) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
pstrcpy(jobname, pjob->jobname);
|
||||
pstring_sub(jobname, "'", "_");
|
||||
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);
|
||||
|
||||
@ -159,8 +199,10 @@ static int generic_job_submit(int snum, struct printjob *pjob)
|
||||
"%c", job_page_count,
|
||||
NULL);
|
||||
|
||||
chdir(wd);
|
||||
out:
|
||||
|
||||
chdir(wd);
|
||||
TALLOC_FREE(current_directory);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ struct tdb_print_db *get_print_db_byname(const char *printername)
|
||||
{
|
||||
struct tdb_print_db *p = NULL, *last_entry = NULL;
|
||||
int num_open = 0;
|
||||
pstring printdb_path;
|
||||
char *printdb_path = NULL;
|
||||
bool done_become_root = False;
|
||||
|
||||
SMB_ASSERT(printername != NULL);
|
||||
@ -78,7 +78,7 @@ struct tdb_print_db *get_print_db_byname(const char *printername)
|
||||
p = print_db_head;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!p) {
|
||||
/* Create one. */
|
||||
p = SMB_MALLOC_P(struct tdb_print_db);
|
||||
@ -90,9 +90,13 @@ struct tdb_print_db *get_print_db_byname(const char *printername)
|
||||
DLIST_ADD(print_db_head, p);
|
||||
}
|
||||
|
||||
pstrcpy(printdb_path, lock_path("printing/"));
|
||||
pstrcat(printdb_path, printername);
|
||||
pstrcat(printdb_path, ".tdb");
|
||||
if (asprintf(&printdb_path, "%s%s.tdb",
|
||||
lock_path("printing/"),
|
||||
printername) < 0) {
|
||||
DLIST_REMOVE(print_db_head, p);
|
||||
SAFE_FREE(p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (geteuid() != 0) {
|
||||
become_root();
|
||||
@ -109,9 +113,11 @@ struct tdb_print_db *get_print_db_byname(const char *printername)
|
||||
DEBUG(0,("get_print_db: Failed to open printer backend database %s.\n",
|
||||
printdb_path ));
|
||||
DLIST_REMOVE(print_db_head, p);
|
||||
SAFE_FREE(printdb_path);
|
||||
SAFE_FREE(p);
|
||||
return NULL;
|
||||
}
|
||||
SAFE_FREE(printdb_path);
|
||||
fstrcpy(p->printer_name, printername);
|
||||
p->ref_count++;
|
||||
return p;
|
||||
|
Loading…
Reference in New Issue
Block a user