summaryrefslogtreecommitdiff
path: root/source3/printing
diff options
context:
space:
mode:
Diffstat (limited to 'source3/printing')
-rw-r--r--source3/printing/load.c4
-rw-r--r--source3/printing/lpq_parse.c17
-rw-r--r--source3/printing/nt_printing.c93
-rw-r--r--source3/printing/print_aix.c3
-rw-r--r--source3/printing/print_generic.c4
-rw-r--r--source3/printing/printfsp.c2
-rw-r--r--source3/printing/printing.c24
7 files changed, 105 insertions, 42 deletions
diff --git a/source3/printing/load.c b/source3/printing/load.c
index f8aba3996d..23144d5a95 100644
--- a/source3/printing/load.c
+++ b/source3/printing/load.c
@@ -28,6 +28,7 @@ static void add_auto_printers(void)
const char *p;
int pnum = lp_servicenumber(PRINTERS_NAME);
char *str;
+ char *saveptr;
if (pnum < 0)
return;
@@ -35,7 +36,8 @@ static void add_auto_printers(void)
if ((str = SMB_STRDUP(lp_auto_services())) == NULL)
return;
- for (p = strtok(str, LIST_SEP); p; p = strtok(NULL, LIST_SEP)) {
+ for (p = strtok_r(str, LIST_SEP, &saveptr); p;
+ p = strtok_r(NULL, LIST_SEP, &saveptr)) {
if (lp_servicenumber(p) >= 0)
continue;
diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c
index 56e228f219..afa3b4850a 100644
--- a/source3/printing/lpq_parse.c
+++ b/source3/printing/lpq_parse.c
@@ -127,6 +127,7 @@ static bool parse_lpq_bsd(char *line,print_queue_struct *buf,bool first)
int count = 0;
TALLOC_CTX *ctx = talloc_tos();
char *line2 = NULL;
+ char *saveptr;
line2 = talloc_strdup(ctx, line);
if (!line2) {
@@ -144,10 +145,11 @@ static bool parse_lpq_bsd(char *line,print_queue_struct *buf,bool first)
#endif /* OSF1 */
/* FIXME: Use next_token_talloc rather than strtok! */
- tok[0] = strtok(line2," \t");
+ tok[0] = strtok_r(line2," \t", &saveptr);
count++;
- while ((count < MAXTOK) && ((tok[count] = strtok(NULL," \t")) != NULL)) {
+ while ((count < MAXTOK)
+ && ((tok[count] = strtok_r(NULL, " \t", &saveptr)) != NULL)) {
count++;
}
@@ -444,7 +446,7 @@ static bool parse_lpq_hpux(char *line, print_queue_struct *buf, bool first)
{
/* must read two lines to process, therefore keep some values static */
static bool header_line_ok=False, base_prio_reset=False;
- static fstring jobuser;
+ static char *jobuser;
static int jobid;
static int jobprio;
static time_t jobtime;
@@ -511,7 +513,11 @@ static bool parse_lpq_hpux(char *line, print_queue_struct *buf, bool first)
buf->job = jobid;
buf->status = jobstat;
buf->priority = jobprio;
- fstrcpy(buf->fs_user,jobuser);
+ if (jobuser) {
+ fstrcpy(buf->fs_user,jobuser);
+ } else {
+ buf->fs_user[0] = '\0';
+ }
TALLOC_FREE(frame);
return True;
@@ -548,7 +554,8 @@ static bool parse_lpq_hpux(char *line, print_queue_struct *buf, bool first)
return False;
}
jobid = atoi(tok[1]);
- fstrcpy(jobuser,tok[2]);
+ SAFE_FREE(jobuser);
+ jobuser = SMB_STRDUP(tok[2]);
jobprio = atoi(tok[4]);
/* process time */
diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c
index ec4e8c59d5..d5803b711b 100644
--- a/source3/printing/nt_printing.c
+++ b/source3/printing/nt_printing.c
@@ -429,7 +429,8 @@ static int sec_desc_upg_fn( TDB_CONTEXT *the_tdb, TDB_DATA key,
/* store it back */
- sd_size = sec_desc_size(sd_store->sd) + sizeof(SEC_DESC_BUF);
+ sd_size = ndr_size_security_descriptor(sd_store->sd, 0)
+ + sizeof(SEC_DESC_BUF);
prs_init(&ps, sd_size, ctx, MARSHALL);
if ( !sec_io_desc_buf( "sec_desc_upg_fn", &sd_store, &ps, 1 ) ) {
@@ -1096,7 +1097,7 @@ static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32
}
/* Skip OEM header (if any) and the DOS stub to start of Windows header */
- if (SMB_VFS_LSEEK(fsp, fsp->fh->fd, SVAL(buf,DOS_HEADER_LFANEW_OFFSET), SEEK_SET) == (SMB_OFF_T)-1) {
+ if (SMB_VFS_LSEEK(fsp, SVAL(buf,DOS_HEADER_LFANEW_OFFSET), SEEK_SET) == (SMB_OFF_T)-1) {
DEBUG(3,("get_file_version: File [%s] too short, errno = %d\n",
fname, errno));
/* Assume this isn't an error... the file just looks sort of like a PE/NE file */
@@ -1117,7 +1118,7 @@ static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32
unsigned int section_table_bytes;
/* Just skip over optional header to get to section table */
- if (SMB_VFS_LSEEK(fsp, fsp->fh->fd,
+ if (SMB_VFS_LSEEK(fsp,
SVAL(buf,PE_HEADER_OPTIONAL_HEADER_SIZE)-(NE_HEADER_SIZE-PE_HEADER_SIZE),
SEEK_CUR) == (SMB_OFF_T)-1) {
DEBUG(3,("get_file_version: File [%s] Windows optional header too short, errno = %d\n",
@@ -1163,7 +1164,7 @@ static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32
}
/* Seek to the start of the .rsrc section info */
- if (SMB_VFS_LSEEK(fsp, fsp->fh->fd, section_pos, SEEK_SET) == (SMB_OFF_T)-1) {
+ if (SMB_VFS_LSEEK(fsp, section_pos, SEEK_SET) == (SMB_OFF_T)-1) {
DEBUG(3,("get_file_version: PE file [%s] too short for section info, errno = %d\n",
fname, errno));
goto error_exit;
@@ -1259,7 +1260,7 @@ static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32
* twice, as it is simpler to read the code. */
if (strcmp(&buf[i], VS_SIGNATURE) == 0) {
/* Compute skip alignment to next long address */
- int skip = -(SMB_VFS_LSEEK(fsp, fsp->fh->fd, 0, SEEK_CUR) - (byte_count - i) +
+ int skip = -(SMB_VFS_LSEEK(fsp, 0, SEEK_CUR) - (byte_count - i) +
sizeof(VS_SIGNATURE)) & 3;
if (IVAL(buf,i+sizeof(VS_SIGNATURE)+skip) != 0xfeef04bd) continue;
@@ -1359,7 +1360,7 @@ static int file_version_is_newer(connection_struct *conn, fstring new_file, fstr
DEBUG(6,("file_version_is_newer: Version info not found [%s], use mod time\n",
old_file));
use_version = false;
- if (SMB_VFS_FSTAT(fsp, fsp->fh->fd, &st) == -1) {
+ if (SMB_VFS_FSTAT(fsp, &st) == -1) {
goto error_exit;
}
old_create_time = st.st_mtime;
@@ -1399,7 +1400,7 @@ static int file_version_is_newer(connection_struct *conn, fstring new_file, fstr
DEBUG(6,("file_version_is_newer: Version info not found [%s], use mod time\n",
new_file));
use_version = false;
- if (SMB_VFS_FSTAT(fsp, fsp->fh->fd, &st) == -1) {
+ if (SMB_VFS_FSTAT(fsp, &st) == -1) {
goto error_exit;
}
new_create_time = st.st_mtime;
@@ -1866,7 +1867,7 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
goto err_exit;
}
- create_directory(conn, new_dir);
+ create_directory(conn, NULL, new_dir);
/* For each driver file, archi\filexxx.yyy, if there is a duplicate file
* listed for this driver which has already been moved, skip it (note:
@@ -3314,8 +3315,13 @@ static WERROR nt_printer_publish_ads(ADS_STRUCT *ads,
/* publish it */
ads_rc = ads_mod_printer_entry(ads, prt_dn, ctx, &mods);
- if (ads_rc.err.rc == LDAP_NO_SUCH_OBJECT)
+ if (ads_rc.err.rc == LDAP_NO_SUCH_OBJECT) {
+ int i;
+ for (i=0; mods[i] != 0; i++)
+ ;
+ mods[i] = (LDAPMod *)-1;
ads_rc = ads_add_printer_entry(ads, prt_dn, ctx, &mods);
+ }
if (!ADS_ERR_OK(ads_rc))
DEBUG(3, ("error publishing %s: %s\n", printer->info_2->sharename, ads_errstr(ads_rc)));
@@ -3849,10 +3855,46 @@ static int unpack_values(NT_PRINTER_DATA *printer_data, const uint8 *buf, int bu
/****************************************************************************
***************************************************************************/
+static char *last_from;
+static char *last_to;
+
+static const char *get_last_from(void)
+{
+ if (!last_from) {
+ return "";
+ }
+ return last_from;
+}
+
+static const char *get_last_to(void)
+{
+ if (!last_to) {
+ return "";
+ }
+ return last_to;
+}
+
+static bool set_last_from_to(const char *from, const char *to)
+{
+ char *orig_from = last_from;
+ char *orig_to = last_to;
+
+ last_from = SMB_STRDUP(from);
+ last_to = SMB_STRDUP(to);
+
+ SAFE_FREE(orig_from);
+ SAFE_FREE(orig_to);
+
+ if (!last_from || !last_to) {
+ SAFE_FREE(last_from);
+ SAFE_FREE(last_to);
+ return false;
+ }
+ return true;
+}
+
static void map_to_os2_driver(fstring drivername)
{
- static bool initialised=False;
- static fstring last_from,last_to;
char *mapfile = lp_os2_driver_map();
char **lines = NULL;
int numlines = 0;
@@ -3864,14 +3906,10 @@ static void map_to_os2_driver(fstring drivername)
if (!*mapfile)
return;
- if (!initialised) {
- *last_from = *last_to = 0;
- initialised = True;
- }
-
- if (strequal(drivername,last_from)) {
- DEBUG(3,("Mapped Windows driver %s to OS/2 driver %s\n",drivername,last_to));
- fstrcpy(drivername,last_to);
+ if (strequal(drivername,get_last_from())) {
+ DEBUG(3,("Mapped Windows driver %s to OS/2 driver %s\n",
+ drivername,get_last_to()));
+ fstrcpy(drivername,get_last_to());
return;
}
@@ -3920,8 +3958,7 @@ static void map_to_os2_driver(fstring drivername)
if (strequal(nt_name,drivername)) {
DEBUG(3,("Mapped windows driver %s to os2 driver%s\n",drivername,os2_name));
- fstrcpy(last_from,drivername);
- fstrcpy(last_to,os2_name);
+ set_last_from_to(drivername,os2_name);
fstrcpy(drivername,os2_name);
file_lines_free(lines);
return;
@@ -5294,6 +5331,7 @@ WERROR nt_printing_setsec(const char *sharename, SEC_DESC_BUF *secdesc_ctr)
SEC_DESC_BUF *new_secdesc_ctr = NULL;
SEC_DESC_BUF *old_secdesc_ctr = NULL;
prs_struct ps;
+ bool prs_init_done = false;
TALLOC_CTX *mem_ctx = NULL;
TDB_DATA kbuf;
WERROR status;
@@ -5358,8 +5396,11 @@ WERROR nt_printing_setsec(const char *sharename, SEC_DESC_BUF *secdesc_ctr)
/* Store the security descriptor in a tdb */
- prs_init(&ps, (uint32)sec_desc_size(new_secdesc_ctr->sd) +
- sizeof(SEC_DESC_BUF), mem_ctx, MARSHALL);
+ prs_init(&ps,
+ (uint32)ndr_size_security_descriptor(new_secdesc_ctr->sd, 0)
+ + sizeof(SEC_DESC_BUF), mem_ctx, MARSHALL);
+
+ prs_init_done = true;
if (!sec_io_desc_buf("nt_printing_setsec", &new_secdesc_ctr,
&ps, 1)) {
@@ -5380,7 +5421,9 @@ WERROR nt_printing_setsec(const char *sharename, SEC_DESC_BUF *secdesc_ctr)
out:
- prs_mem_free(&ps);
+ if (prs_init_done) {
+ prs_mem_free(&ps);
+ }
if (mem_ctx)
talloc_destroy(mem_ctx);
return status;
@@ -5503,7 +5546,7 @@ bool nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **s
/* Save default security descriptor for later */
- prs_init(&ps, (uint32)sec_desc_size((*secdesc_ctr)->sd) +
+ prs_init(&ps, (uint32)ndr_size_security_descriptor((*secdesc_ctr)->sd, 0) +
sizeof(SEC_DESC_BUF), ctx, MARSHALL);
if (sec_io_desc_buf("nt_printing_getsec", secdesc_ctr, &ps, 1)) {
diff --git a/source3/printing/print_aix.c b/source3/printing/print_aix.c
index fd85ca0833..57590cc39e 100644
--- a/source3/printing/print_aix.c
+++ b/source3/printing/print_aix.c
@@ -59,8 +59,9 @@ bool aix_cache_reload(void)
continue;
if ((p = strchr_m(line, ':'))) {
+ char *saveptr;
*p = '\0';
- p = strtok(line, ":");
+ p = strtok_r(line, ":", &saveptr);
if (strcmp(p, "bsh") != 0) {
name = talloc_strdup(ctx, p);
if (!name) {
diff --git a/source3/printing/print_generic.c b/source3/printing/print_generic.c
index cc4b744a11..2a324fdd5c 100644
--- a/source3/printing/print_generic.c
+++ b/source3/printing/print_generic.c
@@ -41,15 +41,18 @@ static int print_run_command(int snum, const char* printername, bool do_sub,
/* check for a valid system printername and valid command to run */
if ( !printername || !*printername ) {
+ va_end(ap);
return -1;
}
if (!command || !*command) {
+ va_end(ap);
return -1;
}
syscmd = talloc_strdup(ctx, command);
if (!syscmd) {
+ va_end(ap);
return -1;
}
@@ -57,6 +60,7 @@ static int print_run_command(int snum, const char* printername, bool do_sub,
char *value = va_arg(ap,char *);
syscmd = talloc_string_sub(ctx, syscmd, arg, value);
if (!syscmd) {
+ va_end(ap);
return -1;
}
}
diff --git a/source3/printing/printfsp.c b/source3/printing/printfsp.c
index 337fd4f74b..1fde16b802 100644
--- a/source3/printing/printfsp.c
+++ b/source3/printing/printfsp.c
@@ -83,7 +83,7 @@ NTSTATUS print_fsp_open(connection_struct *conn, const char *fname,
fsp->is_directory = False;
string_set(&fsp->fsp_name,print_job_fname(lp_const_servicename(SNUM(conn)),jobid));
fsp->wcp = NULL;
- SMB_VFS_FSTAT(fsp,fsp->fh->fd, &sbuf);
+ SMB_VFS_FSTAT(fsp, &sbuf);
fsp->mode = sbuf.st_mode;
fsp->file_id = vfs_file_id_from_sbuf(conn, &sbuf);
diff --git a/source3/printing/printing.c b/source3/printing/printing.c
index fa6ed89edd..9f2c08629d 100644
--- a/source3/printing/printing.c
+++ b/source3/printing/printing.c
@@ -373,13 +373,17 @@ static struct printjob *print_job_find(const char *sharename, uint32 jobid)
/* Convert a unix jobid to a smb jobid */
-static uint32 sysjob_to_jobid_value;
+struct unixjob_traverse_state {
+ int sysjob;
+ uint32 sysjob_to_jobid_value;
+};
static int unixjob_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key,
- TDB_DATA data, void *state)
+ TDB_DATA data, void *private_data)
{
struct printjob *pjob;
- int *sysjob = (int *)state;
+ struct unixjob_traverse_state *state =
+ (struct unixjob_traverse_state *)private_data;
if (!data.dptr || data.dsize == 0)
return 0;
@@ -388,10 +392,10 @@ static int unixjob_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key,
if (key.dsize != sizeof(uint32))
return 0;
- if (*sysjob == pjob->sysjob) {
+ if (state->sysjob == pjob->sysjob) {
uint32 jobid = IVAL(key.dptr,0);
- sysjob_to_jobid_value = jobid;
+ state->sysjob_to_jobid_value = jobid;
return 1;
}
@@ -407,8 +411,10 @@ uint32 sysjob_to_jobid(int unix_jobid)
{
int services = lp_numservices();
int snum;
+ struct unixjob_traverse_state state;
- sysjob_to_jobid_value = (uint32)-1;
+ state.sysjob = unix_jobid;
+ state.sysjob_to_jobid_value = (uint32)-1;
for (snum = 0; snum < services; snum++) {
struct tdb_print_db *pdb;
@@ -418,10 +424,10 @@ uint32 sysjob_to_jobid(int unix_jobid)
if (!pdb) {
continue;
}
- tdb_traverse(pdb->tdb, unixjob_traverse_fn, &unix_jobid);
+ tdb_traverse(pdb->tdb, unixjob_traverse_fn, &state);
release_print_db(pdb);
- if (sysjob_to_jobid_value != (uint32)-1)
- return sysjob_to_jobid_value;
+ if (state.sysjob_to_jobid_value != (uint32)-1)
+ return state.sysjob_to_jobid_value;
}
return (uint32)-1;
}