summaryrefslogtreecommitdiff
path: root/source3/printing
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2011-06-24 16:26:23 +1000
committerAndrew Bartlett <abartlet@samba.org>2011-06-24 16:26:23 +1000
commit6da26870e0ae5acd6ff49a30ec2f6886b44d095e (patch)
tree850c71039563c16a5d563c47e7ba2ab645baf198 /source3/printing
parent6925a799d04c6fa59dd2ddef1f5510f9bb7d17d1 (diff)
parent2610c05b5b95cc7036b3d6dfb894c6cfbdb68483 (diff)
downloadsamba-6da26870e0ae5acd6ff49a30ec2f6886b44d095e.tar.gz
samba-6da26870e0ae5acd6ff49a30ec2f6886b44d095e.tar.bz2
samba-6da26870e0ae5acd6ff49a30ec2f6886b44d095e.zip
Merge 2610c05b5b95cc7036b3d6dfb894c6cfbdb68483 as Samba-4.0alpha16
Diffstat (limited to 'source3/printing')
-rw-r--r--source3/printing/load.h24
-rw-r--r--source3/printing/lpq_parse.c3
-rw-r--r--source3/printing/notify.c19
-rw-r--r--source3/printing/nt_printing.c33
-rw-r--r--source3/printing/nt_printing_ads.c5
-rw-r--r--source3/printing/nt_printing_migrate.c20
-rw-r--r--source3/printing/nt_printing_tdb.c31
-rw-r--r--source3/printing/pcap.c24
-rw-r--r--source3/printing/pcap.h27
-rw-r--r--source3/printing/print_aix.c4
-rw-r--r--source3/printing/print_cups.c192
-rw-r--r--source3/printing/print_generic.c16
-rw-r--r--source3/printing/print_iprint.c2
-rw-r--r--source3/printing/print_standard.c15
-rw-r--r--source3/printing/print_svid.c2
-rw-r--r--source3/printing/printer_list.c43
-rw-r--r--source3/printing/printer_list.h8
-rw-r--r--source3/printing/printing.c55
-rw-r--r--source3/printing/printing_db.c3
-rw-r--r--source3/printing/printspoolss.c1
-rw-r--r--source3/printing/spoolssd.c3
-rw-r--r--source3/printing/tests/vlp.c9
22 files changed, 224 insertions, 315 deletions
diff --git a/source3/printing/load.h b/source3/printing/load.h
index df401a4377..4611e9748c 100644
--- a/source3/printing/load.h
+++ b/source3/printing/load.h
@@ -1,4 +1,28 @@
+/*
+ Unix SMB/CIFS implementation.
+ load printer lists
+ Copyright (C) Andrew Tridgell 1992-2000
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _PRINTING_LOAD_H_
+#define _PRINTING_LOAD_H_
+
/* The following definitions come from printing/load.c */
void load_printers(struct tevent_context *ev,
struct messaging_context *msg_ctx);
+
+#endif /* _PRINTING_LOAD_H_ */
diff --git a/source3/printing/lpq_parse.c b/source3/printing/lpq_parse.c
index 16b9b09fef..9104497f9f 100644
--- a/source3/printing/lpq_parse.c
+++ b/source3/printing/lpq_parse.c
@@ -801,8 +801,9 @@ static bool parse_lpq_plp(char *line,print_queue_struct *buf,bool first)
fstring tmp;
char *p = strrchr_m(tok[6],'/');
if (p) {
+ size_t len = strlen(tok[6])+1;
fstrcpy(tmp,p+1);
- fstrcpy(tok[6],tmp);
+ strlcpy(tok[6],tmp, len);
}
}
diff --git a/source3/printing/notify.c b/source3/printing/notify.c
index 836f7df3d1..b6b7ea045e 100644
--- a/source3/printing/notify.c
+++ b/source3/printing/notify.c
@@ -25,6 +25,7 @@
#include "nt_printing.h"
#include "printing/notify.h"
#include "messages.h"
+#include "util_tdb.h"
static TALLOC_CTX *send_ctx;
@@ -253,9 +254,9 @@ static bool copy_notify2_msg( SPOOLSS_NOTIFY_MSG *to, SPOOLSS_NOTIFY_MSG *from )
memcpy( to, from, sizeof(SPOOLSS_NOTIFY_MSG) );
if ( from->len ) {
- to->notify.data = (char *)TALLOC_MEMDUP(send_ctx, from->notify.data, from->len );
+ to->notify.data = (char *)talloc_memdup(send_ctx, from->notify.data, from->len );
if ( !to->notify.data ) {
- DEBUG(0,("copy_notify2_msg: TALLOC_MEMDUP() of size [%d] failed!\n", from->len ));
+ DEBUG(0,("copy_notify2_msg: talloc_memdup() of size [%d] failed!\n", from->len ));
return False;
}
}
@@ -304,7 +305,7 @@ static void send_spoolss_notify2_msg(struct tevent_context *ev,
/* Store the message on the pending queue. */
- pnqueue = TALLOC_P(send_ctx, struct notify_queue);
+ pnqueue = talloc(send_ctx, struct notify_queue);
if (!pnqueue) {
DEBUG(0,("send_spoolss_notify2_msg: Out of memory.\n"));
return;
@@ -312,7 +313,7 @@ static void send_spoolss_notify2_msg(struct tevent_context *ev,
/* allocate a new msg structure and copy the fields */
- if ( !(pnqueue->msg = TALLOC_P(send_ctx, SPOOLSS_NOTIFY_MSG)) ) {
+ if ( !(pnqueue->msg = talloc(send_ctx, SPOOLSS_NOTIFY_MSG)) ) {
DEBUG(0,("send_spoolss_notify2_msg: talloc() of size [%lu] failed!\n",
(unsigned long)sizeof(SPOOLSS_NOTIFY_MSG)));
return;
@@ -356,7 +357,7 @@ static void send_notify_field_values(struct tevent_context *ev,
if (!create_send_ctx())
return;
- msg = TALLOC_P(send_ctx, struct spoolss_notify_msg);
+ msg = talloc(send_ctx, struct spoolss_notify_msg);
if (!msg)
return;
@@ -387,7 +388,7 @@ static void send_notify_field_buffer(struct tevent_context *ev,
if (!create_send_ctx())
return;
- msg = TALLOC_P(send_ctx, struct spoolss_notify_msg);
+ msg = talloc(send_ctx, struct spoolss_notify_msg);
if (!msg)
return;
@@ -398,7 +399,7 @@ static void send_notify_field_buffer(struct tevent_context *ev,
msg->field = field;
msg->id = id;
msg->len = len;
- msg->notify.data = CONST_DISCARD(char *,buffer);
+ msg->notify.data = discard_const_p(char, buffer);
send_spoolss_notify2_msg(ev, msg_ctx, msg);
}
@@ -631,7 +632,7 @@ static bool print_notify_pid_list(const char *printername, TALLOC_CTX *mem_ctx,
return False;
tdb = pdb->tdb;
- if (tdb_read_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) == -1) {
+ if (tdb_read_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) != 0) {
DEBUG(0,("print_notify_pid_list: Failed to lock printer %s database\n",
printername));
if (pdb)
@@ -649,7 +650,7 @@ static bool print_notify_pid_list(const char *printername, TALLOC_CTX *mem_ctx,
num_pids = data.dsize / 8;
if (num_pids) {
- if ((pid_list = TALLOC_ARRAY(mem_ctx, pid_t, num_pids)) == NULL) {
+ if ((pid_list = talloc_array(mem_ctx, pid_t, num_pids)) == NULL) {
ret = False;
goto done;
}
diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c
index a7539f6478..45d4191ae7 100644
--- a/source3/printing/nt_printing.c
+++ b/source3/printing/nt_printing.c
@@ -20,12 +20,7 @@
*/
#include "includes.h"
-#include "printing/pcap.h"
#include "printing/nt_printing_tdb.h"
-#include "printing/nt_printing_migrate.h"
-#include "registry.h"
-#include "registry/reg_objects.h"
-#include "../librpc/gen_ndr/ndr_security.h"
#include "../librpc/gen_ndr/ndr_spoolss.h"
#include "rpc_server/spoolss/srv_spoolss_util.h"
#include "nt_printing.h"
@@ -36,7 +31,7 @@
#include "smbd/smbd.h"
#include "auth.h"
#include "messages.h"
-#include "ntdomain.h"
+#include "rpc_server/spoolss/srv_spoolss_nt.h"
/* Map generic permissions to printer object specific permissions */
@@ -152,7 +147,7 @@ const char *get_short_archi(const char *long_archi)
do {
i++;
} while ( (archi_table[i].long_archi!=NULL ) &&
- StrCaseCmp(long_archi, archi_table[i].long_archi) );
+ strcasecmp_m(long_archi, archi_table[i].long_archi) );
if (archi_table[i].long_archi==NULL) {
DEBUGADD(10,("Unknown architecture [%s] !\n", long_archi));
@@ -578,7 +573,7 @@ static int file_version_is_newer(connection_struct *conn, fstring new_file, fstr
/****************************************************************************
Determine the correct cVersion associated with an architecture and driver
****************************************************************************/
-static uint32 get_correct_cversion(struct pipes_struct *p,
+static uint32 get_correct_cversion(struct auth_serversupplied_info *session_info,
const char *architecture,
const char *driverpath_in,
WERROR *perr)
@@ -621,7 +616,7 @@ static uint32 get_correct_cversion(struct pipes_struct *p,
nt_status = create_conn_struct(talloc_tos(), &conn, printdollar_snum,
lp_pathname(printdollar_snum),
- p->session_info, &oldcwd);
+ session_info, &oldcwd);
if (!NT_STATUS_IS_OK(nt_status)) {
DEBUG(0,("get_correct_cversion: create_conn_struct "
"returned %s\n", nt_errstr(nt_status)));
@@ -636,7 +631,7 @@ static uint32 get_correct_cversion(struct pipes_struct *p,
goto error_free_conn;
}
- if (!become_user_by_session(conn, p->session_info)) {
+ if (!become_user_by_session(conn, session_info)) {
DEBUG(0, ("failed to become user\n"));
*perr = WERR_ACCESS_DENIED;
goto error_free_conn;
@@ -766,7 +761,7 @@ static uint32 get_correct_cversion(struct pipes_struct *p,
} while (0);
static WERROR clean_up_driver_struct_level(TALLOC_CTX *mem_ctx,
- struct pipes_struct *rpc_pipe,
+ struct auth_serversupplied_info *session_info,
const char *architecture,
const char **driver_path,
const char **data_file,
@@ -826,7 +821,7 @@ static WERROR clean_up_driver_struct_level(TALLOC_CTX *mem_ctx,
* NT2K: cversion=3
*/
- *version = get_correct_cversion(rpc_pipe, short_architecture,
+ *version = get_correct_cversion(session_info, short_architecture,
*driver_path, &err);
if (*version == -1) {
return err;
@@ -839,12 +834,12 @@ static WERROR clean_up_driver_struct_level(TALLOC_CTX *mem_ctx,
****************************************************************************/
WERROR clean_up_driver_struct(TALLOC_CTX *mem_ctx,
- struct pipes_struct *rpc_pipe,
+ struct auth_serversupplied_info *session_info,
struct spoolss_AddDriverInfoCtr *r)
{
switch (r->level) {
case 3:
- return clean_up_driver_struct_level(mem_ctx, rpc_pipe,
+ return clean_up_driver_struct_level(mem_ctx, session_info,
r->info.info3->architecture,
&r->info.info3->driver_path,
&r->info.info3->data_file,
@@ -853,7 +848,7 @@ WERROR clean_up_driver_struct(TALLOC_CTX *mem_ctx,
r->info.info3->dependent_files,
&r->info.info3->version);
case 6:
- return clean_up_driver_struct_level(mem_ctx, rpc_pipe,
+ return clean_up_driver_struct_level(mem_ctx, session_info,
r->info.info6->architecture,
&r->info.info6->driver_path,
&r->info.info6->data_file,
@@ -924,7 +919,7 @@ static WERROR move_driver_file_to_download_area(TALLOC_CTX *mem_ctx,
}
/* Setup a synthetic smb_filename struct */
- smb_fname_new = TALLOC_ZERO_P(mem_ctx, struct smb_filename);
+ smb_fname_new = talloc_zero(mem_ctx, struct smb_filename);
if (!smb_fname_new) {
ret = WERR_NOMEM;
goto out;
@@ -958,7 +953,7 @@ static WERROR move_driver_file_to_download_area(TALLOC_CTX *mem_ctx,
return ret;
}
-WERROR move_driver_to_download_area(struct pipes_struct *p,
+WERROR move_driver_to_download_area(struct auth_serversupplied_info *session_info,
struct spoolss_AddDriverInfoCtr *r)
{
struct spoolss_AddDriverInfo3 *driver;
@@ -1004,7 +999,7 @@ WERROR move_driver_to_download_area(struct pipes_struct *p,
nt_status = create_conn_struct(talloc_tos(), &conn, printdollar_snum,
lp_pathname(printdollar_snum),
- p->session_info, &oldcwd);
+ session_info, &oldcwd);
if (!NT_STATUS_IS_OK(nt_status)) {
DEBUG(0,("move_driver_to_download_area: create_conn_struct "
"returned %s\n", nt_errstr(nt_status)));
@@ -1019,7 +1014,7 @@ WERROR move_driver_to_download_area(struct pipes_struct *p,
goto err_free_conn;
}
- if (!become_user_by_session(conn, p->session_info)) {
+ if (!become_user_by_session(conn, session_info)) {
DEBUG(0, ("failed to become user\n"));
err = WERR_ACCESS_DENIED;
goto err_free_conn;
diff --git a/source3/printing/nt_printing_ads.c b/source3/printing/nt_printing_ads.c
index ea41471613..6290417260 100644
--- a/source3/printing/nt_printing_ads.c
+++ b/source3/printing/nt_printing_ads.c
@@ -28,6 +28,7 @@
#include "krb5_env.h"
#include "../libcli/registry/util_reg.h"
#include "auth.h"
+#include "../librpc/ndr/libndr.h"
#ifdef HAVE_ADS
/*****************************************************************
@@ -110,7 +111,7 @@ static WERROR nt_printer_publish_ads(struct messaging_context *msg_ctx,
DEBUG(5, ("publishing printer %s\n", printer));
/* figure out where to publish */
- ads_find_machine_acct(ads, &res, global_myname());
+ ads_find_machine_acct(ads, &res, lp_netbios_name());
/* We use ldap_get_dn here as we need the answer
* in utf8 to call ldap_explode_dn(). JRA. */
@@ -213,7 +214,7 @@ static WERROR nt_printer_unpublish_ads(ADS_STRUCT *ads,
/* remove the printer from the directory */
ads_rc = ads_find_printer_on_server(ads, &res,
- printer, global_myname());
+ printer, lp_netbios_name());
if (ADS_ERR_OK(ads_rc) && res && ads_count_replies(ads, res)) {
prt_dn = ads_get_dn(ads, talloc_tos(), res);
diff --git a/source3/printing/nt_printing_migrate.c b/source3/printing/nt_printing_migrate.c
index 55e49c973b..ec66dfe816 100644
--- a/source3/printing/nt_printing_migrate.c
+++ b/source3/printing/nt_printing_migrate.c
@@ -25,10 +25,10 @@
#include "rpc_client/rpc_client.h"
#include "librpc/gen_ndr/ndr_ntprinting.h"
#include "librpc/gen_ndr/ndr_spoolss_c.h"
-#include "rpc_client/cli_spoolss.h"
#include "librpc/gen_ndr/ndr_security.h"
#include "rpc_server/rpc_ncacn_np.h"
#include "auth.h"
+#include "util_tdb.h"
#define FORMS_PREFIX "FORMS/"
#define DRIVERS_PREFIX "DRIVERS/"
@@ -73,7 +73,7 @@ static NTSTATUS migrate_form(TALLOC_CTX *mem_ctx,
DEBUG(2, ("Migrating Form: %s\n", key_name));
- srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", global_myname());
+ srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", lp_netbios_name());
if (srv_name_slash == NULL) {
return NT_STATUS_NO_MEMORY;
}
@@ -164,7 +164,7 @@ static NTSTATUS migrate_driver(TALLOC_CTX *mem_ctx,
DEBUG(2, ("Migrating Printer Driver: %s\n", key_name));
- srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", global_myname());
+ srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", lp_netbios_name());
if (srv_name_slash == NULL) {
return NT_STATUS_NO_MEMORY;
}
@@ -360,13 +360,13 @@ static NTSTATUS migrate_printer(TALLOC_CTX *mem_ctx,
/* migrate printerdata */
for (j = 0; j < r.count; j++) {
char *valuename;
- char *keyname;
+ const char *keyname;
if (r.printer_data[j].type == REG_NONE) {
continue;
}
- keyname = CONST_DISCARD(char *, r.printer_data[j].name);
+ keyname = r.printer_data[j].name;
valuename = strchr(keyname, '\\');
if (valuename == NULL) {
continue;
@@ -532,7 +532,7 @@ static NTSTATUS migrate_internal(TALLOC_CTX *mem_ctx,
struct rpc_pipe_client *pipe_hnd)
{
const char *backup_suffix = ".bak";
- TDB_DATA kbuf, newkey, dbuf;
+ TDB_DATA kbuf, dbuf;
TDB_CONTEXT *tdb;
NTSTATUS status;
int rc;
@@ -549,11 +549,11 @@ static NTSTATUS migrate_internal(TALLOC_CTX *mem_ctx,
return NT_STATUS_NO_SUCH_FILE;
}
- for (kbuf = tdb_firstkey(tdb);
+ for (kbuf = tdb_firstkey_compat(tdb);
kbuf.dptr;
- newkey = tdb_nextkey(tdb, kbuf), free(kbuf.dptr), kbuf = newkey)
+ kbuf = tdb_nextkey_compat(tdb, kbuf))
{
- dbuf = tdb_fetch(tdb, kbuf);
+ dbuf = tdb_fetch_compat(tdb, kbuf);
if (!dbuf.dptr) {
continue;
}
@@ -651,7 +651,7 @@ bool nt_printing_tdb_migrate(struct messaging_context *msg_ctx)
return false;
}
- status = rpc_pipe_open_internal(tmp_ctx,
+ status = rpc_pipe_open_interface(tmp_ctx,
&ndr_table_spoolss.syntax_id,
session_info,
NULL,
diff --git a/source3/printing/nt_printing_tdb.c b/source3/printing/nt_printing_tdb.c
index 98ac46797f..028dc0b1da 100644
--- a/source3/printing/nt_printing_tdb.c
+++ b/source3/printing/nt_printing_tdb.c
@@ -26,6 +26,7 @@
#include "librpc/gen_ndr/spoolss.h"
#include "librpc/gen_ndr/ndr_security.h"
#include "libcli/security/security.h"
+#include "util_tdb.h"
#define FORMS_PREFIX "FORMS/"
#define DRIVERS_PREFIX "DRIVERS/"
@@ -87,25 +88,25 @@ static TDB_DATA make_printers_secdesc_tdbkey(TALLOC_CTX *ctx,
static bool upgrade_to_version_3(void)
{
- TDB_DATA kbuf, newkey, dbuf;
+ TDB_DATA kbuf, dbuf;
DEBUG(0,("upgrade_to_version_3: upgrading print tdb's to version 3\n"));
- for (kbuf = tdb_firstkey(tdb_drivers); kbuf.dptr;
- newkey = tdb_nextkey(tdb_drivers, kbuf), free(kbuf.dptr), kbuf=newkey) {
+ for (kbuf = tdb_firstkey_compat(tdb_drivers); kbuf.dptr;
+ kbuf = tdb_nextkey_compat(tdb_drivers, kbuf)) {
- dbuf = tdb_fetch(tdb_drivers, kbuf);
+ dbuf = tdb_fetch_compat(tdb_drivers, kbuf);
if (strncmp((const char *)kbuf.dptr, FORMS_PREFIX, strlen(FORMS_PREFIX)) == 0) {
DEBUG(0,("upgrade_to_version_3:moving form\n"));
if (tdb_store(tdb_forms, kbuf, dbuf, TDB_REPLACE) != 0) {
SAFE_FREE(dbuf.dptr);
- DEBUG(0,("upgrade_to_version_3: failed to move form. Error (%s).\n", tdb_errorstr(tdb_forms)));
+ DEBUG(0,("upgrade_to_version_3: failed to move form. Error (%s).\n", tdb_errorstr_compat(tdb_forms)));
return False;
}
if (tdb_delete(tdb_drivers, kbuf) != 0) {
SAFE_FREE(dbuf.dptr);
- DEBUG(0,("upgrade_to_version_3: failed to delete form. Error (%s)\n", tdb_errorstr(tdb_drivers)));
+ DEBUG(0,("upgrade_to_version_3: failed to delete form. Error (%s)\n", tdb_errorstr_compat(tdb_drivers)));
return False;
}
}
@@ -114,12 +115,12 @@ static bool upgrade_to_version_3(void)
DEBUG(0,("upgrade_to_version_3:moving printer\n"));
if (tdb_store(tdb_printers, kbuf, dbuf, TDB_REPLACE) != 0) {
SAFE_FREE(dbuf.dptr);
- DEBUG(0,("upgrade_to_version_3: failed to move printer. Error (%s)\n", tdb_errorstr(tdb_printers)));
+ DEBUG(0,("upgrade_to_version_3: failed to move printer. Error (%s)\n", tdb_errorstr_compat(tdb_printers)));
return False;
}
if (tdb_delete(tdb_drivers, kbuf) != 0) {
SAFE_FREE(dbuf.dptr);
- DEBUG(0,("upgrade_to_version_3: failed to delete printer. Error (%s)\n", tdb_errorstr(tdb_drivers)));
+ DEBUG(0,("upgrade_to_version_3: failed to delete printer. Error (%s)\n", tdb_errorstr_compat(tdb_drivers)));
return False;
}
}
@@ -128,12 +129,12 @@ static bool upgrade_to_version_3(void)
DEBUG(0,("upgrade_to_version_3:moving secdesc\n"));
if (tdb_store(tdb_printers, kbuf, dbuf, TDB_REPLACE) != 0) {
SAFE_FREE(dbuf.dptr);
- DEBUG(0,("upgrade_to_version_3: failed to move secdesc. Error (%s)\n", tdb_errorstr(tdb_printers)));
+ DEBUG(0,("upgrade_to_version_3: failed to move secdesc. Error (%s)\n", tdb_errorstr_compat(tdb_printers)));
return False;
}
if (tdb_delete(tdb_drivers, kbuf) != 0) {
SAFE_FREE(dbuf.dptr);
- DEBUG(0,("upgrade_to_version_3: failed to delete secdesc. Error (%s)\n", tdb_errorstr(tdb_drivers)));
+ DEBUG(0,("upgrade_to_version_3: failed to delete secdesc. Error (%s)\n", tdb_errorstr_compat(tdb_drivers)));
return False;
}
}
@@ -161,7 +162,6 @@ static int sec_desc_upg_fn( TDB_CONTEXT *the_tdb, TDB_DATA key,
struct security_descriptor *sec, *new_sec;
TALLOC_CTX *ctx = state;
int result, i;
- uint32 sd_size;
size_t size_new_sec;
if (!data.dptr || data.dsize == 0) {
@@ -235,9 +235,6 @@ static int sec_desc_upg_fn( TDB_CONTEXT *the_tdb, TDB_DATA key,
/* store it back */
- sd_size = ndr_size_security_descriptor(sd_store->sd, 0)
- + sizeof(struct sec_desc_buf);
-
status = marshall_sec_desc_buf(ctx, sd_store, &data.dptr, &data.dsize);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0,("sec_desc_upg_fn: Failed to parse new sec_desc for %s\n", key.dptr ));
@@ -248,7 +245,7 @@ static int sec_desc_upg_fn( TDB_CONTEXT *the_tdb, TDB_DATA key,
/* 0 to continue and non-zero to stop traversal */
- return (result == -1);
+ return (result != 0);
}
/*******************************************************************
@@ -269,7 +266,7 @@ static bool upgrade_to_version_4(void)
talloc_destroy( ctx );
- return ( result != -1 );
+ return ( result >= 0 );
}
/*******************************************************************
@@ -337,7 +334,7 @@ static bool upgrade_to_version_5(void)
talloc_destroy( ctx );
- return ( result != -1 );
+ return ( result >= 0 );
}
bool nt_printing_tdb_upgrade(void)
diff --git a/source3/printing/pcap.c b/source3/printing/pcap.c
index 7208f4b7f8..62db4f5efc 100644
--- a/source3/printing/pcap.c
+++ b/source3/printing/pcap.c
@@ -43,10 +43,11 @@
struct pcap_cache {
char *name;
char *comment;
+ char *location;
struct pcap_cache *next;
};
-bool pcap_cache_add_specific(struct pcap_cache **ppcache, const char *name, const char *comment)
+bool pcap_cache_add_specific(struct pcap_cache **ppcache, const char *name, const char *comment, const char *location)
{
struct pcap_cache *p;
@@ -55,9 +56,11 @@ bool pcap_cache_add_specific(struct pcap_cache **ppcache, const char *name, cons
p->name = SMB_STRDUP(name);
p->comment = (comment && *comment) ? SMB_STRDUP(comment) : NULL;
+ p->location = (location && *location) ? SMB_STRDUP(location) : NULL;
- DEBUG(11,("pcap_cache_add_specific: Adding name %s info %s\n",
- p->name, p->comment ? p->comment : ""));
+ DEBUG(11,("pcap_cache_add_specific: Adding name %s info %s, location: %s\n",
+ p->name, p->comment ? p->comment : "",
+ p->location ? p->location : ""));
p->next = *ppcache;
*ppcache = p;
@@ -74,17 +77,18 @@ void pcap_cache_destroy_specific(struct pcap_cache **pp_cache)
SAFE_FREE(p->name);
SAFE_FREE(p->comment);
+ SAFE_FREE(p->location);
SAFE_FREE(p);
}
*pp_cache = NULL;
}
-bool pcap_cache_add(const char *name, const char *comment)
+bool pcap_cache_add(const char *name, const char *comment, const char *location)
{
NTSTATUS status;
time_t t = time_mono(NULL);
- status = printer_list_set_printer(talloc_tos(), name, comment, t);
+ status = printer_list_set_printer(talloc_tos(), name, comment, location, t);
return NT_STATUS_IS_OK(status);
}
@@ -109,7 +113,7 @@ bool pcap_cache_replace(const struct pcap_cache *pcache)
}
for (p = pcache; p; p = p->next) {
- pcap_cache_add(p->name, p->comment);
+ pcap_cache_add(p->name, p->comment, p->location);
}
status = printer_list_clean_old();
@@ -205,7 +209,7 @@ bool pcap_printername_ok(const char *printername)
{
NTSTATUS status;
- status = printer_list_get_printer(talloc_tos(), printername, NULL, 0);
+ status = printer_list_get_printer(talloc_tos(), printername, NULL, NULL, 0);
return NT_STATUS_IS_OK(status);
}
@@ -214,18 +218,18 @@ run a function on each printer name in the printcap file.
***************************************************************************/
void pcap_printer_fn_specific(const struct pcap_cache *pc,
- void (*fn)(const char *, const char *, void *),
+ void (*fn)(const char *, const char *, const char *, void *),
void *pdata)
{
const struct pcap_cache *p;
for (p = pc; p != NULL; p = p->next)
- fn(p->name, p->comment, pdata);
+ fn(p->name, p->comment, p->location, pdata);
return;
}
-void pcap_printer_fn(void (*fn)(const char *, const char *, void *), void *pdata)
+void pcap_printer_fn(void (*fn)(const char *, const char *, const char *, void *), void *pdata)
{
NTSTATUS status;
diff --git a/source3/printing/pcap.h b/source3/printing/pcap.h
index e24142e8b2..70562137ac 100644
--- a/source3/printing/pcap.h
+++ b/source3/printing/pcap.h
@@ -2,6 +2,16 @@
Unix SMB/CIFS implementation.
printcap headers
+ Copyright (C) Karl Auer 1993-1998
+
+ Re-working by Martin Kiff, 1994
+
+ Re-written again by Andrew Tridgell
+
+ Modified for SVID support by Norm Jacobs, 1997
+
+ Modified for CUPS support by Michael Sweet, 1999
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
@@ -16,17 +26,20 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifndef _PRINTING_PCAP_H_
+#define _PRINTING_PCAP_H_
+
struct pcap_cache;
/* The following definitions come from printing/pcap.c */
-bool pcap_cache_add_specific(struct pcap_cache **ppcache, const char *name, const char *comment);
+bool pcap_cache_add_specific(struct pcap_cache **ppcache, const char *name, const char *comment, const char *location);
void pcap_cache_destroy_specific(struct pcap_cache **ppcache);
-bool pcap_cache_add(const char *name, const char *comment);
+bool pcap_cache_add(const char *name, const char *comment, const char *location);
bool pcap_cache_loaded(void);
bool pcap_cache_replace(const struct pcap_cache *cache);
-void pcap_printer_fn_specific(const struct pcap_cache *, void (*fn)(const char *, const char *, void *), void *);
-void pcap_printer_fn(void (*fn)(const char *, const char *, void *), void *);
+void pcap_printer_fn_specific(const struct pcap_cache *, void (*fn)(const char *, const char *, const char *, void *), void *);
+void pcap_printer_fn(void (*fn)(const char *, const char *, const char *, void *), void *);
void pcap_cache_reload(struct tevent_context *ev,
struct messaging_context *msg_ctx,
@@ -44,10 +57,6 @@ bool cups_cache_reload(struct tevent_context *ev,
struct messaging_context *msg_ctx,
void (*post_cache_fill_fn)(struct tevent_context *,
struct messaging_context *));
-bool cups_pull_comment_location(TALLOC_CTX *mem_ctx,
- const char *printername,
- char **comment,
- char **location);
/* The following definitions come from printing/print_iprint.c */
@@ -59,3 +68,5 @@ bool sysv_cache_reload(void);
/* The following definitions come from printing/print_standard.c */
bool std_pcap_cache_reload(const char *pcap_name);
+
+#endif /* _PRINTING_PCAP_H_ */
diff --git a/source3/printing/print_aix.c b/source3/printing/print_aix.c
index b7198d3632..23d9a86fe3 100644
--- a/source3/printing/print_aix.c
+++ b/source3/printing/print_aix.c
@@ -86,7 +86,7 @@ bool aix_cache_reload(void)
/* name is found without stanza device */
/* probably a good printer ??? */
iEtat = 0;
- if (!pcap_cache_add(name, NULL)) {
+ if (!pcap_cache_add(name, NULL, NULL)) {
SAFE_FREE(line);
x_fclose(pfile);
TALLOC_FREE(ctx);
@@ -101,7 +101,7 @@ bool aix_cache_reload(void)
} else if (strstr_m(line, "device")) {
/* it's a good virtual printer */
iEtat = 0;
- if (!pcap_cache_add(name, NULL)) {
+ if (!pcap_cache_add(name, NULL, NULL)) {
SAFE_FREE(line);
x_fclose(pfile);
TALLOC_FREE(ctx);
diff --git a/source3/printing/print_cups.c b/source3/printing/print_cups.c
index da42cb6f85..b8bbddfebd 100644
--- a/source3/printing/print_cups.c
+++ b/source3/printing/print_cups.c
@@ -163,6 +163,7 @@ static bool process_cups_printers_response(TALLOC_CTX *mem_ctx,
ipp_attribute_t *attr;
char *name;
char *info;
+ char *location = NULL;
struct pcap_printer *printer;
bool ret_ok = false;
@@ -206,6 +207,16 @@ static bool process_cups_printers_response(TALLOC_CTX *mem_ctx,
}
}
+ if (strcmp(attr->name, "printer-location") == 0 &&
+ attr->value_tag == IPP_TAG_TEXT) {
+ if (!pull_utf8_talloc(mem_ctx,
+ &location,
+ attr->values[0].string.text,
+ &size)) {
+ goto err_out;
+ }
+ }
+
attr = attr->next;
}
@@ -229,6 +240,7 @@ static bool process_cups_printers_response(TALLOC_CTX *mem_ctx,
pcap_data->printers = printer;
pcap_data->printers[pcap_data->count].name = name;
pcap_data->printers[pcap_data->count].info = info;
+ pcap_data->printers[pcap_data->count].location = location;
pcap_data->count++;
}
@@ -252,7 +264,8 @@ static bool cups_cache_reload_async(int fd)
static const char *requested[] =/* Requested attributes */
{
"printer-name",
- "printer-info"
+ "printer-info",
+ "printer-location"
};
bool ret = False;
enum ndr_err_code ndr_ret;
@@ -478,7 +491,8 @@ static void cups_async_callback(struct event_context *event_ctx,
for (i = 0; i < pcap_data.count; i++) {
ret_ok = pcap_cache_add_specific(&tmp_pcap_cache,
pcap_data.printers[i].name,
- pcap_data.printers[i].info);
+ pcap_data.printers[i].info,
+ pcap_data.printers[i].location);
if (!ret_ok) {
DEBUG(0, ("failed to add to tmp pcap cache\n"));
goto err_out;
@@ -510,7 +524,7 @@ bool cups_cache_reload(struct tevent_context *ev,
struct cups_async_cb_args *cb_args;
int *p_pipe_fd;
- cb_args = TALLOC_P(NULL, struct cups_async_cb_args);
+ cb_args = talloc(NULL, struct cups_async_cb_args);
if (cb_args == NULL) {
return false;
}
@@ -1573,178 +1587,6 @@ struct printif cups_printif =
cups_job_submit,
};
-bool cups_pull_comment_location(TALLOC_CTX *mem_ctx,
- const char *printername,
- char **comment,
- char **location)
-{
- TALLOC_CTX *frame = talloc_stackframe();
- http_t *http = NULL; /* HTTP connection to server */
- ipp_t *request = NULL, /* IPP Request */
- *response = NULL; /* IPP Response */
- ipp_attribute_t *attr; /* Current attribute */
- cups_lang_t *language = NULL; /* Default language */
- char uri[HTTP_MAX_URI];
- char *server = NULL;
- char *sharename = NULL;
- char *name = NULL;
- static const char *requested[] =/* Requested attributes */
- {
- "printer-name",
- "printer-info",
- "printer-location"
- };
- bool ret = False;
- size_t size;
-
- DEBUG(5, ("pulling %s location\n", printername));
-
- /*
- * Make sure we don't ask for passwords...
- */
-
- cupsSetPasswordCB(cups_passwd_cb);
-
- /*
- * Try to connect to the server...
- */
-
- if ((http = cups_connect(frame)) == NULL) {
- goto out;
- }
-
- request = ippNew();
-
- request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
- request->request.op.request_id = 1;
-
- language = cupsLangDefault();
-
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
- "attributes-charset", NULL, "utf-8");
-
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
- "attributes-natural-language", NULL, language->language);
-
- if (lp_cups_server() != NULL && strlen(lp_cups_server()) > 0) {
- if (!push_utf8_talloc(frame, &server, lp_cups_server(), &size)) {
- goto out;
- }
- } else {
- server = talloc_strdup(frame,cupsServer());
- }
- if (server) {
- goto out;
- }
- if (!push_utf8_talloc(frame, &sharename, printername, &size)) {
- goto out;
- }
- slprintf(uri, sizeof(uri) - 1, "ipp://%s/printers/%s",
- server, sharename);
-
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
- "printer-uri", NULL, uri);
-
- ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
- "requested-attributes",
- (sizeof(requested) / sizeof(requested[0])),
- NULL, requested);
-
- /*
- * Do the request and get back a response...
- */
-
- if ((response = cupsDoRequest(http, request, "/")) == NULL) {
- DEBUG(0,("Unable to get printer attributes - %s\n",
- ippErrorString(cupsLastError())));
- goto out;
- }
-
- for (attr = response->attrs; attr != NULL;) {
- /*
- * Skip leading attributes until we hit a printer...
- */
-
- while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
- attr = attr->next;
-
- if (attr == NULL)
- break;
-
- /*
- * Pull the needed attributes from this printer...
- */
-
- while ( attr && (attr->group_tag == IPP_TAG_PRINTER) ) {
- if (strcmp(attr->name, "printer-name") == 0 &&
- attr->value_tag == IPP_TAG_NAME) {
- if (!pull_utf8_talloc(frame,
- &name,
- attr->values[0].string.text,
- &size)) {
- goto out;
- }
- }
-
- /* Grab the comment if we don't have one */
- if ( (strcmp(attr->name, "printer-info") == 0)
- && (attr->value_tag == IPP_TAG_TEXT))
- {
- if (!pull_utf8_talloc(mem_ctx,
- comment,
- attr->values[0].string.text,
- &size)) {
- goto out;
- }
- DEBUG(5,("cups_pull_comment_location: Using cups comment: %s\n",
- *comment));
- }
-
- /* Grab the location if we don't have one */
- if ( (strcmp(attr->name, "printer-location") == 0)
- && (attr->value_tag == IPP_TAG_TEXT))
- {
- if (!pull_utf8_talloc(mem_ctx,
- location,
- attr->values[0].string.text,
- &size)) {
- goto out;
- }
- DEBUG(5,("cups_pull_comment_location: Using cups location: %s\n",
- *location));
- }
-
- attr = attr->next;
- }
-
- /*
- * We have everything needed...
- */
-
- if (name != NULL)
- break;
- }
-
- ret = True;
-
- out:
- if (response)
- ippDelete(response);
-
- if (request) {
- ippDelete(request);
- }
-
- if (language)
- cupsLangFree(language);
-
- if (http)
- httpClose(http);
-
- TALLOC_FREE(frame);
- return ret;
-}
-
#else
/* this keeps fussy compilers happy */
void print_cups_dummy(void);
diff --git a/source3/printing/print_generic.c b/source3/printing/print_generic.c
index b925bedace..14f4c6dbe7 100644
--- a/source3/printing/print_generic.c
+++ b/source3/printing/print_generic.c
@@ -155,17 +155,17 @@ static int generic_job_submit(int snum, struct printjob *pjob)
/* 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);
+ 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;
@@ -205,7 +205,7 @@ static int generic_job_submit(int snum, struct printjob *pjob)
out:
- if (chdir(wd) == -1) {
+ if (chdir(current_directory) == -1) {
smb_panic("chdir failed in generic_job_submit");
}
TALLOC_FREE(current_directory);
diff --git a/source3/printing/print_iprint.c b/source3/printing/print_iprint.c
index ea375da3b7..1392cba7b8 100644
--- a/source3/printing/print_iprint.c
+++ b/source3/printing/print_iprint.c
@@ -297,7 +297,7 @@ static int iprint_cache_add_printer(http_t *http,
*/
if (name != NULL && !secure && smb_enabled)
- pcap_cache_add(name, info);
+ pcap_cache_add(name, info, NULL);
}
out:
diff --git a/source3/printing/print_standard.c b/source3/printing/print_standard.c
index a8460935c9..c4f9c5b7ae 100644
--- a/source3/printing/print_standard.c
+++ b/source3/printing/print_standard.c
@@ -93,6 +93,10 @@ bool std_pcap_cache_reload(const char *pcap_name)
has_punctuation = (strchr_m(p, ' ') ||
strchr_m(p, '\t') ||
+ strchr_m(p, '"') ||
+ strchr_m(p, '\'') ||
+ strchr_m(p, ';') ||
+ strchr_m(p, ',') ||
strchr_m(p, '(') ||
strchr_m(p, ')'));
@@ -101,11 +105,7 @@ bool std_pcap_cache_reload(const char *pcap_name)
continue;
}
- if (strlen(p) <= MAXPRINTERLEN &&
- strlen(p) > strlen(name) && !has_punctuation) {
- if (!*comment) {
- strlcpy(comment, name, sizeof(comment));
- }
+ if (strlen(p) <= MAXPRINTERLEN && *name == '\0' && !has_punctuation) {
strlcpy(name, p, sizeof(name));
continue;
}
@@ -117,10 +117,7 @@ bool std_pcap_cache_reload(const char *pcap_name)
}
}
- comment[60] = 0;
- name[MAXPRINTERLEN] = 0;
-
- if (*name && !pcap_cache_add(name, comment)) {
+ if (*name && !pcap_cache_add(name, comment, NULL)) {
x_fclose(pcap_file);
return false;
}
diff --git a/source3/printing/print_svid.c b/source3/printing/print_svid.c
index 4929be14bc..222649308c 100644
--- a/source3/printing/print_svid.c
+++ b/source3/printing/print_svid.c
@@ -111,7 +111,7 @@ bool sysv_cache_reload(void)
*tmp = '\0';
/* add it to the cache */
- if (!pcap_cache_add(name, NULL)) {
+ if (!pcap_cache_add(name, NULL, NULL)) {
TALLOC_FREE(lines);
return False;
}
diff --git a/source3/printing/printer_list.c b/source3/printing/printer_list.c
index 417eea777b..d28278d069 100644
--- a/source3/printing/printer_list.c
+++ b/source3/printing/printer_list.c
@@ -20,13 +20,14 @@
#include "includes.h"
#include "system/filesys.h"
#include "dbwrap.h"
+#include "util_tdb.h"
#include "printer_list.h"
#define PL_DB_NAME() lock_path("printer_list.tdb")
#define PL_KEY_PREFIX "PRINTERLIST/PRN/"
#define PL_KEY_FORMAT PL_KEY_PREFIX"%s"
#define PL_TIMESTAMP_KEY "PRINTERLIST/GLOBAL/LAST_REFRESH"
-#define PL_DATA_FORMAT "ddPP"
+#define PL_DATA_FORMAT "ddPPP"
#define PL_TSTAMP_FORMAT "dd"
static struct db_context *get_printer_list_db(void)
@@ -64,6 +65,7 @@ bool printer_list_parent_init(void)
NTSTATUS printer_list_get_printer(TALLOC_CTX *mem_ctx,
const char *name,
const char **comment,
+ const char **location,
time_t *last_refresh)
{
struct db_context *db;
@@ -72,6 +74,7 @@ NTSTATUS printer_list_get_printer(TALLOC_CTX *mem_ctx,
uint32_t time_h, time_l;
char *nstr = NULL;
char *cstr = NULL;
+ char *lstr = NULL;
NTSTATUS status;
int ret;
@@ -95,7 +98,7 @@ NTSTATUS printer_list_get_printer(TALLOC_CTX *mem_ctx,
ret = tdb_unpack(data.dptr, data.dsize,
PL_DATA_FORMAT,
- &time_h, &time_l, &nstr, &cstr);
+ &time_h, &time_l, &nstr, &cstr, &lstr);
if (ret == -1) {
DEBUG(1, ("Failed to un pack printer data"));
status = NT_STATUS_INTERNAL_DB_CORRUPTION;
@@ -115,6 +118,15 @@ NTSTATUS printer_list_get_printer(TALLOC_CTX *mem_ctx,
}
}
+ if (location) {
+ *location = talloc_strdup(mem_ctx, lstr);
+ if (*location == NULL) {
+ DEBUG(1, ("Failed to strdup location!\n"));
+ status = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+ }
+
status = NT_STATUS_OK;
done:
@@ -127,6 +139,7 @@ done:
NTSTATUS printer_list_set_printer(TALLOC_CTX *mem_ctx,
const char *name,
const char *comment,
+ const char *location,
time_t last_refresh)
{
struct db_context *db;
@@ -135,6 +148,7 @@ NTSTATUS printer_list_set_printer(TALLOC_CTX *mem_ctx,
uint64_t time_64;
uint32_t time_h, time_l;
const char *str = NULL;
+ const char *str2 = NULL;
NTSTATUS status;
int len;
@@ -155,11 +169,18 @@ NTSTATUS printer_list_set_printer(TALLOC_CTX *mem_ctx,
str = "";
}
+ if (location) {
+ str2 = location;
+ } else {
+ str2 = "";
+ }
+
+
time_64 = last_refresh;
time_l = time_64 & 0xFFFFFFFFL;
time_h = time_64 >> 32;
- len = tdb_pack(NULL, 0, PL_DATA_FORMAT, time_h, time_l, name, str);
+ len = tdb_pack(NULL, 0, PL_DATA_FORMAT, time_h, time_l, name, str, str2);
data.dptr = talloc_array(key, uint8_t, len);
if (!data.dptr) {
@@ -288,6 +309,7 @@ static int printer_list_clean_fn(struct db_record *rec, void *private_data)
time_t refresh;
char *name;
char *comment;
+ char *location;
int ret;
/* skip anything that does not contain PL_DATA_FORMAT data */
@@ -297,7 +319,8 @@ static int printer_list_clean_fn(struct db_record *rec, void *private_data)
}
ret = tdb_unpack(rec->value.dptr, rec->value.dsize,
- PL_DATA_FORMAT, &time_h, &time_l, &name, &comment);
+ PL_DATA_FORMAT, &time_h, &time_l, &name, &comment,
+ &location);
if (ret == -1) {
DEBUG(1, ("Failed to un pack printer data"));
state->status = NT_STATUS_INTERNAL_DB_CORRUPTION;
@@ -306,6 +329,7 @@ static int printer_list_clean_fn(struct db_record *rec, void *private_data)
SAFE_FREE(name);
SAFE_FREE(comment);
+ SAFE_FREE(location);
refresh = (time_t)(((uint64_t)time_h << 32) + time_l);
@@ -341,7 +365,7 @@ NTSTATUS printer_list_clean_old(void)
}
struct printer_list_exec_state {
- void (*fn)(const char *, const char *, void *);
+ void (*fn)(const char *, const char *, const char *, void *);
void *private_data;
NTSTATUS status;
};
@@ -353,6 +377,7 @@ static int printer_list_exec_fn(struct db_record *rec, void *private_data)
uint32_t time_h, time_l;
char *name;
char *comment;
+ char *location;
int ret;
/* always skip PL_TIMESTAMP_KEY key */
@@ -361,21 +386,23 @@ static int printer_list_exec_fn(struct db_record *rec, void *private_data)
}
ret = tdb_unpack(rec->value.dptr, rec->value.dsize,
- PL_DATA_FORMAT, &time_h, &time_l, &name, &comment);
+ PL_DATA_FORMAT, &time_h, &time_l, &name, &comment,
+ &location);
if (ret == -1) {
DEBUG(1, ("Failed to un pack printer data"));
state->status = NT_STATUS_INTERNAL_DB_CORRUPTION;
return -1;
}
- state->fn(name, comment, state->private_data);
+ state->fn(name, comment, location, state->private_data);
SAFE_FREE(name);
SAFE_FREE(comment);
+ SAFE_FREE(location);
return 0;
}
-NTSTATUS printer_list_run_fn(void (*fn)(const char *, const char *, void *),
+NTSTATUS printer_list_run_fn(void (*fn)(const char *, const char *, const char *, void *),
void *private_data)
{
struct printer_list_exec_state state;
diff --git a/source3/printing/printer_list.h b/source3/printing/printer_list.h
index fce3e34248..fb2e007ae6 100644
--- a/source3/printing/printer_list.h
+++ b/source3/printing/printer_list.h
@@ -32,6 +32,8 @@ bool printer_list_parent_init(void);
*
* @param[out] comment A pointer to store the comment of the printer.
*
+ * @param[out] location A pointer to store the location of the printer.
+ *
* @param[out] last_refresh A pointer to store the last refresh time of the
* printer.
*
@@ -41,6 +43,7 @@ bool printer_list_parent_init(void);
NTSTATUS printer_list_get_printer(TALLOC_CTX *mem_ctx,
const char *name,
const char **comment,
+ const char **location,
time_t *last_refresh);
/**
@@ -52,6 +55,8 @@ NTSTATUS printer_list_get_printer(TALLOC_CTX *mem_ctx,
*
* @param[in] comment The comment to store in the db.
*
+ * @param[in] location The location to store in the db.
+ *
* @param[in] last_refresh The last refresh time of the printer to store in
* the db.
*
@@ -61,6 +66,7 @@ NTSTATUS printer_list_get_printer(TALLOC_CTX *mem_ctx,
NTSTATUS printer_list_set_printer(TALLOC_CTX *mem_ctx,
const char *name,
const char *comment,
+ const char *location,
time_t last_refresh);
/**
@@ -94,6 +100,6 @@ NTSTATUS printer_list_mark_reload(void);
*/
NTSTATUS printer_list_clean_old(void);
-NTSTATUS printer_list_run_fn(void (*fn)(const char *, const char *, void *),
+NTSTATUS printer_list_run_fn(void (*fn)(const char *, const char *, const char *, void *),
void *private_data);
#endif /* _PRINTER_LIST_H_ */
diff --git a/source3/printing/printing.c b/source3/printing/printing.c
index 785e893d3a..0c070c7668 100644
--- a/source3/printing/printing.c
+++ b/source3/printing/printing.c
@@ -32,6 +32,7 @@
#include "smbd/smbd.h"
#include "auth.h"
#include "messages.h"
+#include "util_tdb.h"
extern struct current_user current_user;
extern userdom_struct current_user_info;
@@ -87,7 +88,7 @@ uint16 pjobid_to_rap(const char* sharename, uint32 jobid)
key.dptr = (uint8 *)&jinfo;
key.dsize = sizeof(jinfo);
- data = tdb_fetch(rap_tdb, key);
+ data = tdb_fetch_compat(rap_tdb, key);
if (data.dptr && data.dsize == sizeof(uint16)) {
rap_jobid = SVAL(data.dptr, 0);
SAFE_FREE(data.dptr);
@@ -124,7 +125,7 @@ bool rap_to_pjobid(uint16 rap_jobid, fstring sharename, uint32 *pjobid)
SSVAL(buf,0,rap_jobid);
key.dptr = buf;
key.dsize = sizeof(rap_jobid);
- data = tdb_fetch(rap_tdb, key);
+ data = tdb_fetch_compat(rap_tdb, key);
if ( data.dptr && data.dsize == sizeof(struct rap_jobid_key) )
{
struct rap_jobid_key *jinfo = (struct rap_jobid_key*)data.dptr;
@@ -162,7 +163,7 @@ void rap_jobid_delete(const char* sharename, uint32 jobid)
key.dptr = (uint8 *)&jinfo;
key.dsize = sizeof(jinfo);
- data = tdb_fetch(rap_tdb, key);
+ data = tdb_fetch_compat(rap_tdb, key);
if (!data.dptr || (data.dsize != sizeof(uint16))) {
DEBUG(10,("rap_jobid_delete: cannot find jobid %u\n",
(unsigned int)jobid ));
@@ -207,7 +208,7 @@ bool print_backend_init(struct messaging_context *msg_ctx)
pdb = get_print_db_byname(lp_const_servicename(snum));
if (!pdb)
continue;
- if (tdb_lock_bystring(pdb->tdb, sversion) == -1) {
+ if (tdb_lock_bystring(pdb->tdb, sversion) != 0) {
DEBUG(0,("print_backend_init: Failed to open printer %s database\n", lp_const_servicename(snum) ));
release_print_db(pdb);
return False;
@@ -440,7 +441,7 @@ static struct printjob *print_job_find(const char *sharename, uint32 jobid)
return NULL;
}
- ret = tdb_fetch(pdb->tdb, print_key(jobid, &tmp));
+ ret = tdb_fetch_compat(pdb->tdb, print_key(jobid, &tmp));
release_print_db(pdb);
if (!ret.dptr) {
@@ -604,12 +605,12 @@ static bool remove_from_jobs_changed(const char* sharename, uint32_t jobid)
key = string_tdb_data("INFO/jobs_changed");
- if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) == -1)
+ if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) != 0)
goto out;
gotlock = True;
- data = tdb_fetch(pdb->tdb, key);
+ data = tdb_fetch_compat(pdb->tdb, key);
if (data.dptr == NULL || data.dsize == 0 || (data.dsize % 4 != 0))
goto out;
@@ -623,7 +624,7 @@ static bool remove_from_jobs_changed(const char* sharename, uint32_t jobid)
if (i < job_count -1 )
memmove(data.dptr + (i*4), data.dptr + (i*4) + 4, (job_count - i - 1)*4 );
data.dsize -= 4;
- if (tdb_store(pdb->tdb, key, data, TDB_REPLACE) == -1)
+ if (tdb_store(pdb->tdb, key, data, TDB_REPLACE) != 0)
goto out;
break;
}
@@ -727,7 +728,7 @@ static bool pjob_store(struct tevent_context *ev,
/* Get old data */
- old_data = tdb_fetch(pdb->tdb, print_key(jobid, &tmp));
+ old_data = tdb_fetch_compat(pdb->tdb, print_key(jobid, &tmp));
/* Doh! Now we have to pack/unpack data since the NT_DEVICEMODE was added */
@@ -1077,7 +1078,7 @@ static pid_t get_updating_pid(const char *sharename)
slprintf(keystr, sizeof(keystr)-1, "UPDATING/%s", sharename);
key = string_tdb_data(keystr);
- data = tdb_fetch(pdb->tdb, key);
+ data = tdb_fetch_compat(pdb->tdb, key);
release_print_db(pdb);
if (!data.dptr || data.dsize != sizeof(pid_t)) {
SAFE_FREE(data.dptr);
@@ -1224,7 +1225,7 @@ static TDB_DATA get_jobs_added_data(struct tdb_print_db *pdb)
ZERO_STRUCT(data);
- data = tdb_fetch(pdb->tdb, string_tdb_data("INFO/jobs_added"));
+ data = tdb_fetch_compat(pdb->tdb, string_tdb_data("INFO/jobs_added"));
if (data.dptr == NULL || data.dsize == 0 || (data.dsize % 4 != 0)) {
SAFE_FREE(data.dptr);
ZERO_STRUCT(data);
@@ -1515,7 +1516,7 @@ static void print_queue_update_with_lock( struct tevent_context *ev,
slprintf(keystr, sizeof(keystr) - 1, "LOCK/%s", sharename);
/* Only wait 10 seconds for this. */
- if (tdb_lock_bystring_with_timeout(pdb->tdb, keystr, 10) == -1) {
+ if (tdb_lock_bystring_with_timeout(pdb->tdb, keystr, 10) != 0) {
DEBUG(0,("print_queue_update_with_lock: Failed to lock printer %s database\n", sharename));
release_print_db(pdb);
return;
@@ -1884,7 +1885,7 @@ bool print_notify_register_pid(int snum)
tdb = pdb->tdb;
}
- if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) == -1) {
+ if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) != 0) {
DEBUG(0,("print_notify_register_pid: Failed to lock printer %s\n",
printername));
if (pdb)
@@ -1918,7 +1919,7 @@ bool print_notify_register_pid(int snum)
}
/* Store back the record. */
- if (tdb_store_bystring(tdb, NOTIFY_PID_LIST_KEY, data, TDB_REPLACE) == -1) {
+ if (tdb_store_bystring(tdb, NOTIFY_PID_LIST_KEY, data, TDB_REPLACE) != 0) {
DEBUG(0,("print_notify_register_pid: Failed to update pid \
list for printer %s\n", printername));
goto done;
@@ -1974,7 +1975,7 @@ bool print_notify_deregister_pid(int snum)
tdb = pdb->tdb;
}
- if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) == -1) {
+ if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) != 0) {
DEBUG(0,("print_notify_register_pid: Failed to lock \
printer %s database\n", printername));
if (pdb)
@@ -2008,7 +2009,7 @@ printer %s database\n", printername));
SAFE_FREE(data.dptr);
/* Store back the record. */
- if (tdb_store_bystring(tdb, NOTIFY_PID_LIST_KEY, data, TDB_REPLACE) == -1) {
+ if (tdb_store_bystring(tdb, NOTIFY_PID_LIST_KEY, data, TDB_REPLACE) != 0) {
DEBUG(0,("print_notify_register_pid: Failed to update pid \
list for printer %s\n", printername));
goto done;
@@ -2133,12 +2134,12 @@ static bool remove_from_jobs_added(const char* sharename, uint32 jobid)
key = string_tdb_data("INFO/jobs_added");
- if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) == -1)
+ if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) != 0)
goto out;
gotlock = True;
- data = tdb_fetch(pdb->tdb, key);
+ data = tdb_fetch_compat(pdb->tdb, key);
if (data.dptr == NULL || data.dsize == 0 || (data.dsize % 4 != 0))
goto out;
@@ -2152,7 +2153,7 @@ static bool remove_from_jobs_added(const char* sharename, uint32 jobid)
if (i < job_count -1 )
memmove(data.dptr + (i*4), data.dptr + (i*4) + 4, (job_count - i - 1)*4 );
data.dsize -= 4;
- if (tdb_store(pdb->tdb, key, data, TDB_REPLACE) == -1)
+ if (tdb_store(pdb->tdb, key, data, TDB_REPLACE) != 0)
goto out;
break;
}
@@ -2501,7 +2502,7 @@ static int get_queue_status(const char* sharename, print_status_struct *status)
if (status) {
fstr_sprintf(keystr, "STATUS/%s", sharename);
- data = tdb_fetch(pdb->tdb, string_tdb_data(keystr));
+ data = tdb_fetch_compat(pdb->tdb, string_tdb_data(keystr));
if (data.dptr) {
if (data.dsize == sizeof(print_status_struct))
/* this memcpy is ok since the status struct was
@@ -2560,7 +2561,7 @@ static WERROR allocate_print_jobid(struct tdb_print_db *pdb, int snum,
/* Lock the database - only wait 20 seconds. */
ret = tdb_lock_bystring_with_timeout(pdb->tdb,
"INFO/nextjob", 20);
- if (ret == -1) {
+ if (ret != 0) {
DEBUG(0, ("allocate_print_jobid: "
"Failed to lock printing database %s\n",
sharename));
@@ -2588,7 +2589,7 @@ static WERROR allocate_print_jobid(struct tdb_print_db *pdb, int snum,
jobid = NEXT_JOBID(jobid);
ret = tdb_store_int32(pdb->tdb, "INFO/nextjob", jobid);
- if (ret == -1) {
+ if (ret != 0) {
terr = tdb_error(pdb->tdb);
DEBUG(3, ("allocate_print_jobid: "
"Failed to store INFO/nextjob.\n"));
@@ -2621,7 +2622,7 @@ static WERROR allocate_print_jobid(struct tdb_print_db *pdb, int snum,
dum.dptr = NULL;
dum.dsize = 0;
if (tdb_store(pdb->tdb, print_key(jobid, &tmp), dum,
- TDB_INSERT) == -1) {
+ TDB_INSERT) != 0) {
DEBUG(3, ("allocate_print_jobid: "
"jobid (%d) failed to store placeholder.\n",
jobid ));
@@ -3037,18 +3038,18 @@ static bool get_stored_queue_info(struct messaging_context *msg_ctx,
ZERO_STRUCT(cgdata);
/* Get the stored queue data. */
- data = tdb_fetch(pdb->tdb, string_tdb_data("INFO/linear_queue_array"));
+ data = tdb_fetch_compat(pdb->tdb, string_tdb_data("INFO/linear_queue_array"));
if (data.dptr && data.dsize >= sizeof(qcount))
len += tdb_unpack(data.dptr + len, data.dsize - len, "d", &qcount);
/* Get the added jobs list. */
- cgdata = tdb_fetch(pdb->tdb, string_tdb_data("INFO/jobs_added"));
+ cgdata = tdb_fetch_compat(pdb->tdb, string_tdb_data("INFO/jobs_added"));
if (cgdata.dptr != NULL && (cgdata.dsize % 4 == 0))
extra_count = cgdata.dsize/4;
/* Get the changed jobs list. */
- jcdata = tdb_fetch(pdb->tdb, string_tdb_data("INFO/jobs_changed"));
+ jcdata = tdb_fetch_compat(pdb->tdb, string_tdb_data("INFO/jobs_changed"));
if (jcdata.dptr != NULL && (jcdata.dsize % 4 == 0))
changed_count = jcdata.dsize / 4;
@@ -3215,7 +3216,7 @@ int print_queue_status(struct messaging_context *msg_ctx, int snum,
slprintf(keystr, sizeof(keystr)-1, "STATUS/%s", sharename);
key = string_tdb_data(keystr);
- data = tdb_fetch(pdb->tdb, key);
+ data = tdb_fetch_compat(pdb->tdb, key);
if (data.dptr) {
if (data.dsize == sizeof(*status)) {
/* this memcpy is ok since the status struct was
diff --git a/source3/printing/printing_db.c b/source3/printing/printing_db.c
index 70accab935..e442551b83 100644
--- a/source3/printing/printing_db.c
+++ b/source3/printing/printing_db.c
@@ -22,6 +22,7 @@
#include "includes.h"
#include "system/filesys.h"
#include "printing.h"
+#include "util_tdb.h"
static struct tdb_print_db *print_db_head;
@@ -159,7 +160,7 @@ void close_all_print_db(void)
messages. data needs freeing on exit.
****************************************************************************/
-TDB_DATA get_printer_notify_pid_list(TDB_CONTEXT *tdb, const char *printer_name, bool cleanlist)
+TDB_DATA get_printer_notify_pid_list(struct tdb_context *tdb, const char *printer_name, bool cleanlist)
{
TDB_DATA data;
size_t i;
diff --git a/source3/printing/printspoolss.c b/source3/printing/printspoolss.c
index 2f6f19c3da..3d8b0d8b1b 100644
--- a/source3/printing/printspoolss.c
+++ b/source3/printing/printspoolss.c
@@ -22,7 +22,6 @@
#include "rpc_client/rpc_client.h"
#include "../librpc/gen_ndr/ndr_spoolss_c.h"
#include "rpc_server/rpc_ncacn_np.h"
-#include "smbd/smbd.h"
#include "smbd/globals.h"
#include "../libcli/security/security.h"
diff --git a/source3/printing/spoolssd.c b/source3/printing/spoolssd.c
index 340bf0a5f1..896aee0a53 100644
--- a/source3/printing/spoolssd.c
+++ b/source3/printing/spoolssd.c
@@ -19,15 +19,16 @@
#include "includes.h"
#include "serverid.h"
#include "smbd/smbd.h"
-#include "locking/proto.h"
#include "messages.h"
#include "include/printing.h"
#include "printing/nt_printing_migrate.h"
+#include "ntdomain.h"
#include "librpc/gen_ndr/srv_winreg.h"
#include "librpc/gen_ndr/srv_spoolss.h"
#include "rpc_server/rpc_server.h"
#include "rpc_server/rpc_ep_setup.h"
+#include "rpc_server/spoolss/srv_spoolss_nt.h"
#define SPOOLSS_PIPE_NAME "spoolss"
#define DAEMON_NAME "spoolssd"
diff --git a/source3/printing/tests/vlp.c b/source3/printing/tests/vlp.c
index 4bff290e28..66860e5ada 100644
--- a/source3/printing/tests/vlp.c
+++ b/source3/printing/tests/vlp.c
@@ -23,6 +23,7 @@
#include "system/passwd.h"
#include "system/filesys.h"
#include "printing.h"
+#include "util_tdb.h"
#ifdef malloc
#undef malloc
@@ -110,10 +111,9 @@ static int next_jobnum(char *printer)
static void set_printer_status(char *printer, int status)
{
fstring keystr;
- int result;
slprintf(keystr, sizeof(keystr) - 1, "STATUS/%s", printer);
- result = tdb_store_int32(tdb, keystr, status);
+ tdb_store_int32(tdb, keystr, status);
}
static int get_printer_status(char *printer)
@@ -392,8 +392,9 @@ int main(int argc, char **argv)
return 1;
}
- if (!(tdb = tdb_open(printdb_path, 0, 0, O_RDWR | O_CREAT,
- 0666))) {
+ /* FIXME: We should *never* open a tdb without logging! */
+ if (!(tdb = tdb_open_compat(printdb_path, 0, 0, O_RDWR | O_CREAT,
+ 0666, NULL, NULL))) {
printf("%s: unable to open %s\n", argv[0], printdb_path);
return 1;
}