The branch, master has been updated
via c82d6c0 s3-spoolss: make sure to exit early and with the
appropriate error code in _spoolss_GetPrinterDriver2.
via 575ae3e spoolss: use the correct flags for spoolss_PrinterInfo1
struct.
via 3797d48 s3-spoolss: Fix servername/printername handling which turns
out to be very important to get right.
via 156ab4e s4-smbtorture: add new EnumPrinters test to test
printername/servername behaviour in EnumPrinter and GetPrinter calls.
from 1f3f75f s4-samldb: also set a password on the krbtgt_NNNN account
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit c82d6c0b96817129ab6fa23ef8f5d421fd6c7001
Author: Günther Deschner <[email protected]>
Date: Thu Sep 30 02:28:41 2010 +0200
s3-spoolss: make sure to exit early and with the appropriate error code in
_spoolss_GetPrinterDriver2.
Guenther
commit 575ae3ed728974236512b029f8217d99c6fc8526
Author: Günther Deschner <[email protected]>
Date: Thu Sep 30 02:05:36 2010 +0200
spoolss: use the correct flags for spoolss_PrinterInfo1 struct.
Guenther
commit 3797d48b76fadb988c40d056751be8671c9e6906
Author: Günther Deschner <[email protected]>
Date: Wed Sep 29 04:51:56 2010 +0200
s3-spoolss: Fix servername/printername handling which turns out to be very
important to get right.
Guenther
commit 156ab4ec104adf20257b2ef1e361382eac457ee3
Author: Günther Deschner <[email protected]>
Date: Wed Sep 29 04:49:57 2010 +0200
s4-smbtorture: add new EnumPrinters test to test printername/servername
behaviour in EnumPrinter and GetPrinter calls.
Guenther
-----------------------------------------------------------------------
Summary of changes:
librpc/idl/spoolss.idl | 2 +-
source3/include/nt_printing.h | 2 +-
source3/printing/nt_printing.c | 4 +-
source3/printing/nt_printing_ads.c | 6 +-
source3/rpc_server/srv_spoolss_nt.c | 266 +++++++++++++++++++++++----------
source3/rpc_server/srv_spoolss_util.c | 50 +------
source3/rpc_server/srv_spoolss_util.h | 6 +-
source4/torture/rpc/spoolss.c | 220 +++++++++++++++++++++++++--
8 files changed, 401 insertions(+), 155 deletions(-)
Changeset truncated at 500 lines:
diff --git a/librpc/idl/spoolss.idl b/librpc/idl/spoolss.idl
index f1b8e96..a957a54 100644
--- a/librpc/idl/spoolss.idl
+++ b/librpc/idl/spoolss.idl
@@ -766,7 +766,7 @@ cpp_quote("#define spoolss_security_descriptor
security_descriptor")
} spoolss_PrinterAttributes;
typedef [public,gensize] struct {
- spoolss_PrinterAttributes flags;
+ spoolss_EnumPrinterFlags flags;
[relative] nstring *description;
[relative] nstring *name;
[relative] nstring *comment;
diff --git a/source3/include/nt_printing.h b/source3/include/nt_printing.h
index d244b2c..6db306e 100644
--- a/source3/include/nt_printing.h
+++ b/source3/include/nt_printing.h
@@ -150,7 +150,7 @@ WERROR nt_printer_publish(TALLOC_CTX *mem_ctx,
bool is_printer_published(TALLOC_CTX *mem_ctx,
const struct auth_serversupplied_info *server_info,
struct messaging_context *msg_ctx,
- char *servername, char *printer, struct GUID *guid,
+ const char *servername, char *printer, struct GUID
*guid,
struct spoolss_PrinterInfo2 **info2);
WERROR check_published_printers(struct messaging_context *msg_ctx);
diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c
index a8c30a1..b12d2b9 100644
--- a/source3/printing/nt_printing.c
+++ b/source3/printing/nt_printing.c
@@ -1577,7 +1577,7 @@ bool printer_driver_in_use(TALLOC_CTX *mem_ctx,
}
result = winreg_get_printer(mem_ctx, server_info, msg_ctx,
- NULL, lp_servicename(snum),
+ lp_servicename(snum),
&pinfo2);
if (!W_ERROR_IS_OK(result)) {
continue; /* skip */
@@ -2178,7 +2178,7 @@ bool print_time_access_check(const struct
auth_serversupplied_info *server_info,
uint32 mins;
result = winreg_get_printer(NULL, server_info, msg_ctx,
- NULL, servicename, &pinfo2);
+ servicename, &pinfo2);
if (!W_ERROR_IS_OK(result)) {
return False;
}
diff --git a/source3/printing/nt_printing_ads.c
b/source3/printing/nt_printing_ads.c
index 56086c9..3ccaeef 100644
--- a/source3/printing/nt_printing_ads.c
+++ b/source3/printing/nt_printing_ads.c
@@ -362,7 +362,7 @@ WERROR check_published_printers(struct messaging_context
*msg_ctx)
}
result = winreg_get_printer(tmp_ctx, server_info, msg_ctx,
- NULL, lp_servicename(snum),
+ lp_servicename(snum),
&pinfo2);
if (!W_ERROR_IS_OK(result)) {
continue;
@@ -386,7 +386,7 @@ done:
bool is_printer_published(TALLOC_CTX *mem_ctx,
const struct auth_serversupplied_info *server_info,
struct messaging_context *msg_ctx,
- char *servername, char *printer, struct GUID *guid,
+ const char *servername, char *printer, struct GUID
*guid,
struct spoolss_PrinterInfo2 **info2)
{
struct spoolss_PrinterInfo2 *pinfo2 = NULL;
@@ -397,7 +397,7 @@ bool is_printer_published(TALLOC_CTX *mem_ctx,
NTSTATUS status;
result = winreg_get_printer(mem_ctx, server_info, msg_ctx,
- servername, printer, &pinfo2);
+ printer, &pinfo2);
if (!W_ERROR_IS_OK(result)) {
return false;
}
diff --git a/source3/rpc_server/srv_spoolss_nt.c
b/source3/rpc_server/srv_spoolss_nt.c
index 89a835f..889c370 100644
--- a/source3/rpc_server/srv_spoolss_nt.c
+++ b/source3/rpc_server/srv_spoolss_nt.c
@@ -73,7 +73,7 @@ struct printer_handle {
bool page_started;
uint32 jobid; /* jobid in printing backend */
int printer_type;
- fstring servername;
+ const char *servername;
fstring sharename;
uint32 type;
uint32 access_granted;
@@ -569,8 +569,10 @@ static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
if (!is_myname_or_ipaddr(servername)) {
return false;
}
-
- fstrcpy(Printer->servername, servername);
+ Printer->servername = talloc_asprintf(Printer, "\\\\%s",
servername);
+ if (Printer->servername == NULL) {
+ return false;
+ }
}
if (Printer->printer_type == SPLHND_SERVER) {
@@ -649,7 +651,6 @@ static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
result = winreg_get_printer(mem_ctx,
server_info,
msg_ctx,
- servername,
sname,
&info2);
if ( !W_ERROR_IS_OK(result) ) {
@@ -1522,7 +1523,6 @@ void do_drv_upgrade_printer(struct messaging_context *msg,
}
result = winreg_get_printer(tmp_ctx, server_info, msg,
- NULL,
lp_const_servicename(snum),
&pinfo2);
@@ -1848,7 +1848,6 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
winreg_create_printer(p->mem_ctx,
get_server_info_system(),
p->msg_ctx,
- Printer->servername,
lp_const_servicename(snum));
break;
@@ -3505,7 +3504,6 @@ static WERROR printserver_notify_info(struct pipes_struct
*p,
result = winreg_get_printer(mem_ctx,
get_server_info_system(),
p->msg_ctx,
- Printer->servername,
lp_servicename(snum),
&pinfo2);
if (!W_ERROR_IS_OK(result)) {
@@ -3592,7 +3590,6 @@ static WERROR printer_notify_info(struct pipes_struct *p,
result = winreg_get_printer(mem_ctx,
get_server_info_system(),
p->msg_ctx,
- Printer->servername,
lp_servicename(snum), &pinfo2);
if (!W_ERROR_IS_OK(result)) {
return WERR_BADFID;
@@ -3721,6 +3718,46 @@ done:
}
/********************************************************************
+ ********************************************************************/
+
+static WERROR create_printername(TALLOC_CTX *mem_ctx,
+ const char *servername,
+ const char *printername,
+ const char **printername_p)
+{
+ /* FIXME: add lp_force_printername() */
+
+ if (servername == NULL) {
+ *printername_p = talloc_strdup(mem_ctx, printername);
+ W_ERROR_HAVE_NO_MEMORY(*printername_p);
+ return WERR_OK;
+ }
+
+ if (servername[0] == '\\' && servername[1] == '\\') {
+ servername += 2;
+ }
+
+ *printername_p = talloc_asprintf(mem_ctx, "\\\\%s\\%s", servername,
printername);
+ W_ERROR_HAVE_NO_MEMORY(*printername_p);
+
+ return WERR_OK;
+}
+
+/********************************************************************
+ ********************************************************************/
+
+static void compose_devicemode_devicename(struct spoolss_DeviceMode *dm,
+ const char *printername)
+{
+ if (dm == NULL) {
+ return;
+ }
+
+ dm->devicename = talloc_strndup(dm, printername,
+ MIN(strlen(printername), 31));
+}
+
+/********************************************************************
* construct_printer_info_0
* fill a printer_info_0 struct
********************************************************************/
@@ -3729,6 +3766,7 @@ static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
const struct auth_serversupplied_info
*server_info,
struct messaging_context *msg_ctx,
struct spoolss_PrinterInfo2 *info2,
+ const char *servername,
struct spoolss_PrinterInfo0 *r,
int snum)
{
@@ -3736,12 +3774,19 @@ static WERROR construct_printer_info0(TALLOC_CTX
*mem_ctx,
struct printer_session_counter *session_counter;
struct timeval setuptime;
print_status_struct status;
+ WERROR result;
- r->printername = talloc_strdup(mem_ctx, info2->printername);
- W_ERROR_HAVE_NO_MEMORY(r->printername);
+ result = create_printername(mem_ctx, servername, info2->printername,
&r->printername);
+ if (!W_ERROR_IS_OK(result)) {
+ return result;
+ }
- r->servername = talloc_strdup(mem_ctx, info2->servername);
- W_ERROR_HAVE_NO_MEMORY(r->servername);
+ if (servername) {
+ r->servername = talloc_strdup(mem_ctx, servername);
+ W_ERROR_HAVE_NO_MEMORY(r->servername);
+ } else {
+ r->servername = NULL;
+ }
count = print_queue_length(msg_ctx, snum, &status);
@@ -3816,16 +3861,13 @@ static WERROR construct_printer_info0(TALLOC_CTX
*mem_ctx,
static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
const struct spoolss_PrinterInfo2 *info2,
uint32_t flags,
+ const char *servername,
struct spoolss_PrinterInfo1 *r,
int snum)
{
- r->flags = flags;
+ WERROR result;
- r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
- info2->printername,
- info2->drivername,
- info2->location);
- W_ERROR_HAVE_NO_MEMORY(r->description);
+ r->flags = flags;
if (info2->comment == NULL || info2->comment[0] == '\0') {
r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
@@ -3834,8 +3876,16 @@ static WERROR construct_printer_info1(TALLOC_CTX
*mem_ctx,
}
W_ERROR_HAVE_NO_MEMORY(r->comment);
- r->name = talloc_strdup(mem_ctx, info2->printername);
- W_ERROR_HAVE_NO_MEMORY(r->name);
+ result = create_printername(mem_ctx, servername, info2->printername,
&r->name);
+ if (!W_ERROR_IS_OK(result)) {
+ return result;
+ }
+
+ r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
+ r->name,
+ info2->drivername,
+ r->comment);
+ W_ERROR_HAVE_NO_MEMORY(r->description);
return WERR_OK;
}
@@ -3848,18 +3898,28 @@ static WERROR construct_printer_info1(TALLOC_CTX
*mem_ctx,
static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
struct messaging_context *msg_ctx,
const struct spoolss_PrinterInfo2 *info2,
+ const char *servername,
struct spoolss_PrinterInfo2 *r,
int snum)
{
int count;
print_status_struct status;
+ WERROR result;
count = print_queue_length(msg_ctx, snum, &status);
- r->servername = talloc_strdup(mem_ctx, info2->servername);
- W_ERROR_HAVE_NO_MEMORY(r->servername);
- r->printername = talloc_strdup(mem_ctx, info2->printername);
- W_ERROR_HAVE_NO_MEMORY(r->printername);
+ if (servername) {
+ r->servername = talloc_strdup(mem_ctx, servername);
+ W_ERROR_HAVE_NO_MEMORY(r->servername);
+ } else {
+ r->servername = NULL;
+ }
+
+ result = create_printername(mem_ctx, servername, info2->printername,
&r->printername);
+ if (!W_ERROR_IS_OK(result)) {
+ return result;
+ }
+
r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
W_ERROR_HAVE_NO_MEMORY(r->sharename);
r->portname = talloc_strdup(mem_ctx, info2->portname);
@@ -3900,6 +3960,8 @@ static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
DEBUG(8,("Returning NULL Devicemode!\n"));
}
+ compose_devicemode_devicename(r->devmode, r->printername);
+
r->secdesc = NULL;
if (info2->secdesc != NULL) {
@@ -3919,6 +3981,7 @@ static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
const struct spoolss_PrinterInfo2 *info2,
+ const char *servername,
struct spoolss_PrinterInfo3 *r,
int snum)
{
@@ -3942,13 +4005,23 @@ static WERROR construct_printer_info3(TALLOC_CTX
*mem_ctx,
static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
const struct spoolss_PrinterInfo2 *info2,
+ const char *servername,
struct spoolss_PrinterInfo4 *r,
int snum)
{
- r->printername = talloc_strdup(mem_ctx, info2->printername);
- W_ERROR_HAVE_NO_MEMORY(r->printername);
- r->servername = talloc_strdup(mem_ctx, info2->servername);
- W_ERROR_HAVE_NO_MEMORY(r->servername);
+ WERROR result;
+
+ result = create_printername(mem_ctx, servername, info2->printername,
&r->printername);
+ if (!W_ERROR_IS_OK(result)) {
+ return result;
+ }
+
+ if (servername) {
+ r->servername = talloc_strdup(mem_ctx, servername);
+ W_ERROR_HAVE_NO_MEMORY(r->servername);
+ } else {
+ r->servername = NULL;
+ }
r->attributes = info2->attributes;
@@ -3962,11 +4035,17 @@ static WERROR construct_printer_info4(TALLOC_CTX
*mem_ctx,
static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
const struct spoolss_PrinterInfo2 *info2,
+ const char *servername,
struct spoolss_PrinterInfo5 *r,
int snum)
{
- r->printername = talloc_strdup(mem_ctx, info2->printername);
- W_ERROR_HAVE_NO_MEMORY(r->printername);
+ WERROR result;
+
+ result = create_printername(mem_ctx, servername, info2->printername,
&r->printername);
+ if (!W_ERROR_IS_OK(result)) {
+ return result;
+ }
+
r->portname = talloc_strdup(mem_ctx, info2->portname);
W_ERROR_HAVE_NO_MEMORY(r->portname);
@@ -3987,6 +4066,7 @@ static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
struct messaging_context *msg_ctx,
const struct spoolss_PrinterInfo2 *info2,
+ const char *servername,
struct spoolss_PrinterInfo6 *r,
int snum)
{
@@ -4007,7 +4087,7 @@ static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
struct messaging_context *msg_ctx,
- struct printer_handle *print_hnd,
+ const char *servername,
struct spoolss_PrinterInfo7 *r,
int snum)
{
@@ -4023,7 +4103,7 @@ static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
}
if (is_printer_published(mem_ctx, server_info, msg_ctx,
- print_hnd->servername,
+ servername,
lp_servicename(snum), &guid, NULL)) {
r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx,
&guid));
r->action = DSPRINT_PUBLISH;
@@ -4044,14 +4124,25 @@ static WERROR construct_printer_info7(TALLOC_CTX
*mem_ctx,
static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
const struct spoolss_PrinterInfo2 *info2,
+ const char *servername,
struct spoolss_DeviceModeInfo *r,
int snum)
{
+ WERROR result;
+ const char *printername;
+
+ result = create_printername(mem_ctx, servername, info2->printername,
&printername);
+ if (!W_ERROR_IS_OK(result)) {
+ return result;
+ }
+
copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
if (!r->devmode) {
DEBUG(8,("Returning NULL Devicemode!\n"));
}
+ compose_devicemode_devicename(r->devmode, printername);
+
return WERR_OK;
}
@@ -4071,6 +4162,7 @@ static bool snum_is_shared_printer(int snum)
static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
const struct
auth_serversupplied_info *server_info,
struct messaging_context *msg_ctx,
+ const char *servername,
uint32_t level,
uint32_t flags,
union spoolss_PrinterInfo **info_p,
@@ -4102,7 +4194,6 @@ static WERROR enum_all_printers_info_level(TALLOC_CTX
*mem_ctx,
result = winreg_create_printer(mem_ctx,
server_info,
msg_ctx,
- NULL,
printer);
if (!W_ERROR_IS_OK(result)) {
goto out;
@@ -4117,7 +4208,7 @@ static WERROR enum_all_printers_info_level(TALLOC_CTX
*mem_ctx,
}
result = winreg_get_printer(mem_ctx, server_info, msg_ctx,
- NULL, printer, &info2);
+ printer, &info2);
if (!W_ERROR_IS_OK(result)) {
goto out;
}
@@ -4126,22 +4217,27 @@ static WERROR enum_all_printers_info_level(TALLOC_CTX
*mem_ctx,
case 0:
result = construct_printer_info0(info, server_info,
msg_ctx, info2,
+ servername,
&info[count].info0,
snum);
break;
case 1:
result = construct_printer_info1(info, info2, flags,
+ servername,
&info[count].info1,
snum);
break;
case 2:
result = construct_printer_info2(info, msg_ctx, info2,
+ servername,
&info[count].info2,
snum);
break;
case 4:
result = construct_printer_info4(info, info2,
+ servername,
&info[count].info4,
snum);
break;
case 5:
result = construct_printer_info5(info, info2,
+ servername,
&info[count].info5,
snum);
break;
@@ -4186,7 +4282,7 @@ static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
DEBUG(4,("enum_all_printers_info_0\n"));
return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
- 0, flags, info, count);
+ servername, 0, flags, info, count);
}
@@ -4196,6 +4292,7 @@ static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
const struct auth_serversupplied_info
*server_info,
struct messaging_context *msg_ctx,
+ const char *servername,
uint32_t flags,
union spoolss_PrinterInfo **info,
uint32_t *count)
@@ -4203,7 +4300,7 @@ static WERROR enum_all_printers_info_1(TALLOC_CTX
*mem_ctx,
DEBUG(4,("enum_all_printers_info_1\n"));
return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
- 1, flags, info, count);
+ servername, 1, flags, info, count);
}
/********************************************************************
@@ -4213,13 +4310,14 @@ static WERROR enum_all_printers_info_1(TALLOC_CTX
*mem_ctx,
static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
const struct
auth_serversupplied_info *server_info,
struct messaging_context *msg_ctx,
+ const char *servername,
union spoolss_PrinterInfo **info,
uint32_t *count)
{
--
Samba Shared Repository