From ecc2e1e3b8981fd72217ed513f2bab1ded46006d Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 1 Feb 2002 16:15:53 +0000 Subject: Module for ADS operations on a printer object in the directory. Initially it creates and modifies a printQueue object in the directory (This used to be commit b14e638aeb80bad80cfd12ed60f5e77f24addfd5) --- source3/libads/ldap_printer.c | 133 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 source3/libads/ldap_printer.c (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c new file mode 100644 index 0000000000..eef8788909 --- /dev/null +++ b/source3/libads/ldap_printer.c @@ -0,0 +1,133 @@ +/* + Unix SMB/CIFS implementation. + ads (active directory) utility library + Copyright (C) Andrew Tridgell 2001 + Copyright (C) Remus Koos 2001 + Copyright (C) Jim McDonough 2002 + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#ifdef HAVE_ADS + +/* + modify an entire printer entry in the directory +*/ +ADS_STATUS ads_mod_printer_entry(ADS_STRUCT *ads, char *prt_dn, + const ADS_PRINTER_ENTRY *prt) +{ + LDAPMod **mods; + ADS_STATUS status; + + /* allocate the list */ + mods = ads_mod_list_start(sizeof(prt) / sizeof(char *)); + + /* add the attributes to the list - required ones first */ + ads_mod_repl(mods, "printerName", prt->printerName); + ads_mod_repl(mods, "serverName", prt->serverName); + ads_mod_repl(mods, "shortServerName", prt->shortServerName); + ads_mod_repl(mods, "uNCName", prt->uNCName); + ads_mod_repl(mods, "versionNumber", prt->versionNumber); + /* now the optional ones */ + ads_mod_repl_list(mods, "description", prt->description); + ads_mod_repl(mods, "driverName", prt->driverName); + ads_mod_repl(mods, "location", prt->location); + ads_mod_repl_list(mods, "portName", prt->portName); + ads_mod_repl(mods, "printStartTime", prt->printStartTime); + ads_mod_repl(mods, "printEndTime", prt->printEndTime); + ads_mod_repl_list(mods, "printBinNames", prt->printBinNames); + + /* and many others */ + + /* do the ldap modify */ + status = ads_gen_mod(ads, prt_dn, mods); + + /* free mod list, mods, and values */ + ads_mod_list_end(mods); + + return status; +} + + +/* + add a printer to the directory +*/ +static ADS_STATUS ads_add_printer_entry(ADS_STRUCT *ads, char *prt_dn, + const ADS_PRINTER_ENTRY *prt) +{ + ADS_STATUS status; + + /* These are the fields a printQueue must contain */ + status = ads_gen_add(ads, prt_dn, + "uNCName", prt->uNCName, NULL, + "versionNumber", prt->versionNumber, NULL, + "serverName", prt->serverName, NULL, + "shortServerName", prt->shortServerName, NULL, + "printerName", prt->printerName, NULL, + "objectClass", "printQueue", NULL, + NULL); + + return status; +} + +/* + publish a printer in the ADS +*/ + +ADS_STATUS ads_add_printer(ADS_STRUCT *ads, const ADS_PRINTER_ENTRY *prt) +{ + ADS_STATUS status; + void *res; + char *host_dn, *prt_dn; + const char *attrs[] = {"*", "nTSecurityDescriptor", NULL}; + + status = ads_find_machine_acct(ads, (void **)&res, + prt->shortServerName); + if (!ADS_ERR_OK(status)) { + DEBUG(1, ("ads_add_printer: cannot find host %s in ads\n", + prt->shortServerName)); + return status; + } + host_dn = ldap_get_dn(ads->ld, res); + ads_msgfree(ads, res); + + /* printer dn is cn=server-printer followed by host dn */ + asprintf(&prt_dn, "cn=%s-%s,%s", prt->shortServerName, + prt->printerName, host_dn); + + status = ads_search_dn(ads, res, prt_dn, attrs); + + if (ADS_ERR_OK(status) && ads_count_replies(ads, res)) { + DEBUG(1, ("ads_add_printer: printer %s already exists\n", + prt->printerName)); + /* nothing to do, just free results */ + ads_msgfree(ads, res); + } else { + ads_msgfree(ads, res); + status = ads_add_printer_entry(ads, prt_dn, prt); + if (!ADS_ERR_OK(status)) { + DEBUG(0, ("ads_add_printer: ads_add_printer_entry failed\n")); + return status; + } + } + + status = ads_mod_printer_entry(ads, prt_dn, prt); + + return status; +} + +#endif -- cgit From aa8ebe3956aaec908a808e24ed8d83073a3e9ee3 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 1 Feb 2002 16:58:01 +0000 Subject: Fix file header description and copyright (from cut-and-paste laziness) (This used to be commit 146c731c35beecd3ae8e093e52d94af0e2efcd69) --- source3/libads/ldap_printer.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index eef8788909..65fa649785 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -1,8 +1,6 @@ /* Unix SMB/CIFS implementation. - ads (active directory) utility library - Copyright (C) Andrew Tridgell 2001 - Copyright (C) Remus Koos 2001 + ads (active directory) printer utility library Copyright (C) Jim McDonough 2002 This program is free software; you can redistribute it and/or modify -- cgit From 0c63216603fa957e04688d22bf1c0321fb2ff78a Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 1 Feb 2002 17:13:39 +0000 Subject: Fix build errors on non-ldap systems...change function parms from LDAPMod ** to void ** (This used to be commit 9467792843fdd9bc55e92bfaa2f2205279074297) --- source3/libads/ldap_printer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 65fa649785..54cd7d8e94 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -28,7 +28,7 @@ ADS_STATUS ads_mod_printer_entry(ADS_STRUCT *ads, char *prt_dn, const ADS_PRINTER_ENTRY *prt) { - LDAPMod **mods; + void **mods; ADS_STATUS status; /* allocate the list */ -- cgit From bb8349735f627ba4de2012f77ee3fa6ce491f394 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Sat, 2 Feb 2002 02:04:01 +0000 Subject: Minor bug fixes, plus support to remove a printer. Commented out optional attributes until a method for checking for their existence is done. (This used to be commit 538c19a6983e0423b94f743184263cd8ef9c701e) --- source3/libads/ldap_printer.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 54cd7d8e94..74dc02397c 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -22,6 +22,35 @@ #ifdef HAVE_ADS +/* + find a printer given the name and the hostname + Note that results "res" may be allocated on return so that the + results can be used. It should be freed using ads_msgfree. +*/ +ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, + char *printer, char *servername) +{ + ADS_STATUS status; + char *srv_dn, *exp; + const char *attrs[] = {"*", "nTSecurityDescriptor", NULL}; + + status = ads_find_machine_acct(ads, res, servername); + if (!ADS_ERR_OK(status)) { + DEBUG(1, ("ads_add_printer: cannot find host %s in ads\n", + servername)); + return status; + } + srv_dn = ldap_get_dn(ads->ld, *res); + ads_msgfree(ads, *res); + + asprintf(&exp, "(printerName=%s)", printer); + status = ads_do_search(ads, srv_dn, LDAP_SCOPE_SUBTREE, + exp, &attrs, res); + + free(exp); + return status; +} + /* modify an entire printer entry in the directory */ @@ -32,7 +61,7 @@ ADS_STATUS ads_mod_printer_entry(ADS_STRUCT *ads, char *prt_dn, ADS_STATUS status; /* allocate the list */ - mods = ads_mod_list_start(sizeof(prt) / sizeof(char *)); + mods = ads_mod_list_start(sizeof(ADS_PRINTER_ENTRY) / sizeof(char *)); /* add the attributes to the list - required ones first */ ads_mod_repl(mods, "printerName", prt->printerName); @@ -40,7 +69,8 @@ ADS_STATUS ads_mod_printer_entry(ADS_STRUCT *ads, char *prt_dn, ads_mod_repl(mods, "shortServerName", prt->shortServerName); ads_mod_repl(mods, "uNCName", prt->uNCName); ads_mod_repl(mods, "versionNumber", prt->versionNumber); - /* now the optional ones */ + /* now the optional ones - not ready yet, since it will + fail if the attributes don't exist already ads_mod_repl_list(mods, "description", prt->description); ads_mod_repl(mods, "driverName", prt->driverName); ads_mod_repl(mods, "location", prt->location); @@ -49,7 +79,7 @@ ADS_STATUS ads_mod_printer_entry(ADS_STRUCT *ads, char *prt_dn, ads_mod_repl(mods, "printEndTime", prt->printEndTime); ads_mod_repl_list(mods, "printBinNames", prt->printBinNames); - /* and many others */ + ... and many others */ /* do the ldap modify */ status = ads_gen_mod(ads, prt_dn, mods); @@ -93,7 +123,7 @@ ADS_STATUS ads_add_printer(ADS_STRUCT *ads, const ADS_PRINTER_ENTRY *prt) char *host_dn, *prt_dn; const char *attrs[] = {"*", "nTSecurityDescriptor", NULL}; - status = ads_find_machine_acct(ads, (void **)&res, + status = ads_find_machine_acct(ads, (void **)&res, prt->shortServerName); if (!ADS_ERR_OK(status)) { DEBUG(1, ("ads_add_printer: cannot find host %s in ads\n", @@ -107,7 +137,7 @@ ADS_STATUS ads_add_printer(ADS_STRUCT *ads, const ADS_PRINTER_ENTRY *prt) asprintf(&prt_dn, "cn=%s-%s,%s", prt->shortServerName, prt->printerName, host_dn); - status = ads_search_dn(ads, res, prt_dn, attrs); + status = ads_search_dn(ads, &res, prt_dn, attrs); if (ADS_ERR_OK(status) && ads_count_replies(ads, res)) { DEBUG(1, ("ads_add_printer: printer %s already exists\n", -- cgit From 55b92fdebcddc14981c6eafbe98751b365a5e0ed Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Sat, 2 Feb 2002 22:07:22 +0000 Subject: Update for function name changes, plus do some of the optional attributes on printer modify, now that the ldap control is working. (This used to be commit 76afc886a89e8c0d5a169435dde42b00db522060) --- source3/libads/ldap_printer.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 74dc02397c..d337398158 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -61,7 +61,7 @@ ADS_STATUS ads_mod_printer_entry(ADS_STRUCT *ads, char *prt_dn, ADS_STATUS status; /* allocate the list */ - mods = ads_mod_list_start(sizeof(ADS_PRINTER_ENTRY) / sizeof(char *)); + mods = ads_init_mods(sizeof(ADS_PRINTER_ENTRY) / sizeof(char *)); /* add the attributes to the list - required ones first */ ads_mod_repl(mods, "printerName", prt->printerName); @@ -69,23 +69,34 @@ ADS_STATUS ads_mod_printer_entry(ADS_STRUCT *ads, char *prt_dn, ads_mod_repl(mods, "shortServerName", prt->shortServerName); ads_mod_repl(mods, "uNCName", prt->uNCName); ads_mod_repl(mods, "versionNumber", prt->versionNumber); - /* now the optional ones - not ready yet, since it will - fail if the attributes don't exist already + + /* now the optional ones */ ads_mod_repl_list(mods, "description", prt->description); + ads_mod_repl(mods, "assetNumber",prt->assetNumber); + ads_mod_repl(mods, "bytesPerMinute",prt->bytesPerMinute); + ads_mod_repl(mods, "defaultPriority",prt->defaultPriority); ads_mod_repl(mods, "driverName", prt->driverName); + ads_mod_repl(mods, "driverVersion",prt->driverVersion); ads_mod_repl(mods, "location", prt->location); + ads_mod_repl(mods, "operatingSystem",prt->operatingSystem); + ads_mod_repl(mods, "operatingSystemHotfix",prt->operatingSystemHotfix); + ads_mod_repl(mods, "operatingSystemServicePack", + prt->operatingSystemServicePack); + ads_mod_repl(mods, "operatingSystemVersion", + prt->operatingSystemVersion); + ads_mod_repl(mods, "physicalLocationObject", + prt->physicalLocationObject); ads_mod_repl_list(mods, "portName", prt->portName); ads_mod_repl(mods, "printStartTime", prt->printStartTime); ads_mod_repl(mods, "printEndTime", prt->printEndTime); ads_mod_repl_list(mods, "printBinNames", prt->printBinNames); - - ... and many others */ + /*... and many others */ /* do the ldap modify */ status = ads_gen_mod(ads, prt_dn, mods); /* free mod list, mods, and values */ - ads_mod_list_end(mods); + ads_free_mods(mods); return status; } -- cgit From ad6dfee7413756b7fe76ce1c9440105edd2fe9b2 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Mon, 11 Feb 2002 15:48:01 +0000 Subject: Update for new ads modlist structure passing (This used to be commit 6169b668fe955f298c7323c5d64f6c7b303aaac0) --- source3/libads/ldap_printer.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index d337398158..50f4302201 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -57,11 +57,11 @@ ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, ADS_STATUS ads_mod_printer_entry(ADS_STRUCT *ads, char *prt_dn, const ADS_PRINTER_ENTRY *prt) { - void **mods; + ADS_MODLIST *mods; ADS_STATUS status; /* allocate the list */ - mods = ads_init_mods(sizeof(ADS_PRINTER_ENTRY) / sizeof(char *)); + *mods = ads_init_mods(); /* add the attributes to the list - required ones first */ ads_mod_repl(mods, "printerName", prt->printerName); @@ -93,10 +93,10 @@ ADS_STATUS ads_mod_printer_entry(ADS_STRUCT *ads, char *prt_dn, /*... and many others */ /* do the ldap modify */ - status = ads_gen_mod(ads, prt_dn, mods); + status = ads_gen_mod(ads, prt_dn, *mods); /* free mod list, mods, and values */ - ads_free_mods(mods); + ads_free_mods(*mods); return status; } @@ -164,7 +164,16 @@ ADS_STATUS ads_add_printer(ADS_STRUCT *ads, const ADS_PRINTER_ENTRY *prt) } } - status = ads_mod_printer_entry(ads, prt_dn, prt); + status = ads_search_dn(ads, &res, prt_dn, attrs); + + if (ADS_ERR_OK(status) && ads_count_replies(ads, res)) { + /* need to retrieve GUID from results + prt->GUID */ + status = ads_mod_printer_entry(ads, prt_dn, prt); + } + + ads_msgfree(ads, res); + return status; } -- cgit From d6b82723a0f626c52a3cf05d3bb4f0ff5f7e0f7a Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Tue, 12 Feb 2002 18:22:47 +0000 Subject: talloc'ify ads modify functions. (This used to be commit e097666499564ffe28836876a7a191149c14f199) --- source3/libads/ldap_printer.c | 86 +++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 35 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 50f4302201..52771ba39a 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -45,7 +45,7 @@ ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, asprintf(&exp, "(printerName=%s)", printer); status = ads_do_search(ads, srv_dn, LDAP_SCOPE_SUBTREE, - exp, &attrs, res); + exp, attrs, res); free(exp); return status; @@ -57,46 +57,51 @@ ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, ADS_STATUS ads_mod_printer_entry(ADS_STRUCT *ads, char *prt_dn, const ADS_PRINTER_ENTRY *prt) { - ADS_MODLIST *mods; + ADS_MODLIST mods; ADS_STATUS status; + TALLOC_CTX *ctx; + + if (!(ctx = talloc_init_named("mod_printer_entry"))) + return ADS_ERROR(LDAP_NO_MEMORY); /* allocate the list */ - *mods = ads_init_mods(); + mods = ads_init_mods(ctx); /* add the attributes to the list - required ones first */ - ads_mod_repl(mods, "printerName", prt->printerName); - ads_mod_repl(mods, "serverName", prt->serverName); - ads_mod_repl(mods, "shortServerName", prt->shortServerName); - ads_mod_repl(mods, "uNCName", prt->uNCName); - ads_mod_repl(mods, "versionNumber", prt->versionNumber); + ads_mod_repl(ctx, &mods, "printerName", prt->printerName); + ads_mod_repl(ctx, &mods, "serverName", prt->serverName); + ads_mod_repl(ctx, &mods, "shortServerName", prt->shortServerName); + ads_mod_repl(ctx, &mods, "uNCName", prt->uNCName); + ads_mod_repl(ctx, &mods, "versionNumber", prt->versionNumber); /* now the optional ones */ - ads_mod_repl_list(mods, "description", prt->description); - ads_mod_repl(mods, "assetNumber",prt->assetNumber); - ads_mod_repl(mods, "bytesPerMinute",prt->bytesPerMinute); - ads_mod_repl(mods, "defaultPriority",prt->defaultPriority); - ads_mod_repl(mods, "driverName", prt->driverName); - ads_mod_repl(mods, "driverVersion",prt->driverVersion); - ads_mod_repl(mods, "location", prt->location); - ads_mod_repl(mods, "operatingSystem",prt->operatingSystem); - ads_mod_repl(mods, "operatingSystemHotfix",prt->operatingSystemHotfix); - ads_mod_repl(mods, "operatingSystemServicePack", + ads_mod_repl_list(ctx, &mods, "description", prt->description); + ads_mod_repl(ctx, &mods, "assetNumber",prt->assetNumber); + ads_mod_repl(ctx, &mods, "bytesPerMinute",prt->bytesPerMinute); + ads_mod_repl(ctx, &mods, "defaultPriority",prt->defaultPriority); + ads_mod_repl(ctx, &mods, "driverName", prt->driverName); + ads_mod_repl(ctx, &mods, "driverVersion",prt->driverVersion); + ads_mod_repl(ctx, &mods, "location", prt->location); + ads_mod_repl(ctx, &mods, "operatingSystem",prt->operatingSystem); + ads_mod_repl(ctx, &mods, "operatingSystemHotfix", + prt->operatingSystemHotfix); + ads_mod_repl(ctx, &mods, "operatingSystemServicePack", prt->operatingSystemServicePack); - ads_mod_repl(mods, "operatingSystemVersion", + ads_mod_repl(ctx, &mods, "operatingSystemVersion", prt->operatingSystemVersion); - ads_mod_repl(mods, "physicalLocationObject", + ads_mod_repl(ctx, &mods, "physicalLocationObject", prt->physicalLocationObject); - ads_mod_repl_list(mods, "portName", prt->portName); - ads_mod_repl(mods, "printStartTime", prt->printStartTime); - ads_mod_repl(mods, "printEndTime", prt->printEndTime); - ads_mod_repl_list(mods, "printBinNames", prt->printBinNames); + ads_mod_repl_list(ctx, &mods, "portName", prt->portName); + ads_mod_repl(ctx, &mods, "printStartTime", prt->printStartTime); + ads_mod_repl(ctx, &mods, "printEndTime", prt->printEndTime); + ads_mod_repl_list(ctx, &mods, "printBinNames", prt->printBinNames); /*... and many others */ /* do the ldap modify */ - status = ads_gen_mod(ads, prt_dn, *mods); + status = ads_gen_mod(ads, prt_dn, mods); /* free mod list, mods, and values */ - ads_free_mods(*mods); + talloc_destroy(ctx); return status; } @@ -109,16 +114,27 @@ static ADS_STATUS ads_add_printer_entry(ADS_STRUCT *ads, char *prt_dn, const ADS_PRINTER_ENTRY *prt) { ADS_STATUS status; - + TALLOC_CTX *ctx; + ADS_MODLIST mods; + + if (!(ctx = talloc_init_named("add_printer_entry"))) + return ADS_ERROR(LDAP_NO_MEMORY); + + if (!(mods = ads_init_mods(ctx))) + return ADS_ERROR(LDAP_NO_MEMORY); + /* These are the fields a printQueue must contain */ - status = ads_gen_add(ads, prt_dn, - "uNCName", prt->uNCName, NULL, - "versionNumber", prt->versionNumber, NULL, - "serverName", prt->serverName, NULL, - "shortServerName", prt->shortServerName, NULL, - "printerName", prt->printerName, NULL, - "objectClass", "printQueue", NULL, - NULL); + ads_mod_add(ctx, &mods, "uNCName", prt->uNCName); + ads_mod_add(ctx, &mods, "versionNumber", prt->versionNumber); + ads_mod_add(ctx, &mods, "serverName", prt->serverName); + ads_mod_add(ctx, &mods, "shortServerName", prt->shortServerName); + ads_mod_add(ctx, &mods, "printerName", prt->printerName); + ads_mod_add(ctx, &mods, "objectClass", "printQueue"); + + + status = ads_gen_add(ads, prt_dn, mods); + + talloc_destroy(ctx); return status; } -- cgit From e90b65284812aaa5ff9e9935ce9bbad7791cbbcd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Jul 2002 10:35:28 +0000 Subject: updated the 3.0 branch from the head branch - ready for alpha18 (This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce) --- source3/libads/ldap_printer.c | 73 +++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 37 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 52771ba39a..64ae8252c8 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -31,7 +31,7 @@ ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, char *printer, char *servername) { ADS_STATUS status; - char *srv_dn, *exp; + char *srv_dn, **srv_cn, *exp; const char *attrs[] = {"*", "nTSecurityDescriptor", NULL}; status = ads_find_machine_acct(ads, res, servername); @@ -41,12 +41,14 @@ ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, return status; } srv_dn = ldap_get_dn(ads->ld, *res); + srv_cn = ldap_explode_dn(srv_dn, 1); ads_msgfree(ads, *res); - asprintf(&exp, "(printerName=%s)", printer); - status = ads_do_search(ads, srv_dn, LDAP_SCOPE_SUBTREE, - exp, attrs, res); + asprintf(&exp, "(cn=%s-%s)", srv_cn[0], printer); + status = ads_search(ads, res, exp, attrs); + ldap_memfree(srv_dn); + ldap_value_free(srv_cn); free(exp); return status; } @@ -68,33 +70,33 @@ ADS_STATUS ads_mod_printer_entry(ADS_STRUCT *ads, char *prt_dn, mods = ads_init_mods(ctx); /* add the attributes to the list - required ones first */ - ads_mod_repl(ctx, &mods, "printerName", prt->printerName); - ads_mod_repl(ctx, &mods, "serverName", prt->serverName); - ads_mod_repl(ctx, &mods, "shortServerName", prt->shortServerName); - ads_mod_repl(ctx, &mods, "uNCName", prt->uNCName); - ads_mod_repl(ctx, &mods, "versionNumber", prt->versionNumber); + ads_mod_str(ctx, &mods, "printerName", prt->printerName); + ads_mod_str(ctx, &mods, "serverName", prt->serverName); + ads_mod_str(ctx, &mods, "shortServerName", prt->shortServerName); + ads_mod_str(ctx, &mods, "uNCName", prt->uNCName); + ads_mod_str(ctx, &mods, "versionNumber", prt->versionNumber); /* now the optional ones */ - ads_mod_repl_list(ctx, &mods, "description", prt->description); - ads_mod_repl(ctx, &mods, "assetNumber",prt->assetNumber); - ads_mod_repl(ctx, &mods, "bytesPerMinute",prt->bytesPerMinute); - ads_mod_repl(ctx, &mods, "defaultPriority",prt->defaultPriority); - ads_mod_repl(ctx, &mods, "driverName", prt->driverName); - ads_mod_repl(ctx, &mods, "driverVersion",prt->driverVersion); - ads_mod_repl(ctx, &mods, "location", prt->location); - ads_mod_repl(ctx, &mods, "operatingSystem",prt->operatingSystem); - ads_mod_repl(ctx, &mods, "operatingSystemHotfix", + ads_mod_strlist(ctx, &mods, "description", prt->description); + ads_mod_str(ctx, &mods, "assetNumber",prt->assetNumber); + ads_mod_str(ctx, &mods, "bytesPerMinute",prt->bytesPerMinute); + ads_mod_str(ctx, &mods, "defaultPriority",prt->defaultPriority); + ads_mod_str(ctx, &mods, "driverName", prt->driverName); + ads_mod_str(ctx, &mods, "driverVersion",prt->driverVersion); + ads_mod_str(ctx, &mods, "location", prt->location); + ads_mod_str(ctx, &mods, "operatingSystem",prt->operatingSystem); + ads_mod_str(ctx, &mods, "operatingSystemHotfix", prt->operatingSystemHotfix); - ads_mod_repl(ctx, &mods, "operatingSystemServicePack", + ads_mod_str(ctx, &mods, "operatingSystemServicePack", prt->operatingSystemServicePack); - ads_mod_repl(ctx, &mods, "operatingSystemVersion", + ads_mod_str(ctx, &mods, "operatingSystemVersion", prt->operatingSystemVersion); - ads_mod_repl(ctx, &mods, "physicalLocationObject", + ads_mod_str(ctx, &mods, "physicalLocationObject", prt->physicalLocationObject); - ads_mod_repl_list(ctx, &mods, "portName", prt->portName); - ads_mod_repl(ctx, &mods, "printStartTime", prt->printStartTime); - ads_mod_repl(ctx, &mods, "printEndTime", prt->printEndTime); - ads_mod_repl_list(ctx, &mods, "printBinNames", prt->printBinNames); + ads_mod_strlist(ctx, &mods, "portName", prt->portName); + ads_mod_str(ctx, &mods, "printStartTime", prt->printStartTime); + ads_mod_str(ctx, &mods, "printEndTime", prt->printEndTime); + ads_mod_strlist(ctx, &mods, "printBinNames", prt->printBinNames); /*... and many others */ /* do the ldap modify */ @@ -124,12 +126,12 @@ static ADS_STATUS ads_add_printer_entry(ADS_STRUCT *ads, char *prt_dn, return ADS_ERROR(LDAP_NO_MEMORY); /* These are the fields a printQueue must contain */ - ads_mod_add(ctx, &mods, "uNCName", prt->uNCName); - ads_mod_add(ctx, &mods, "versionNumber", prt->versionNumber); - ads_mod_add(ctx, &mods, "serverName", prt->serverName); - ads_mod_add(ctx, &mods, "shortServerName", prt->shortServerName); - ads_mod_add(ctx, &mods, "printerName", prt->printerName); - ads_mod_add(ctx, &mods, "objectClass", "printQueue"); + ads_mod_str(ctx, &mods, "uNCName", prt->uNCName); + ads_mod_str(ctx, &mods, "versionNumber", prt->versionNumber); + ads_mod_str(ctx, &mods, "serverName", prt->serverName); + ads_mod_str(ctx, &mods, "shortServerName", prt->shortServerName); + ads_mod_str(ctx, &mods, "printerName", prt->printerName); + ads_mod_str(ctx, &mods, "objectClass", "printQueue"); status = ads_gen_add(ads, prt_dn, mods); @@ -157,14 +159,11 @@ ADS_STATUS ads_add_printer(ADS_STRUCT *ads, const ADS_PRINTER_ENTRY *prt) prt->shortServerName)); return status; } - host_dn = ldap_get_dn(ads->ld, res); + host_dn = ads_get_dn(ads, res); ads_msgfree(ads, res); - /* printer dn is cn=server-printer followed by host dn */ - asprintf(&prt_dn, "cn=%s-%s,%s", prt->shortServerName, - prt->printerName, host_dn); - - status = ads_search_dn(ads, &res, prt_dn, attrs); + ads_find_printer_on_server(ads, &res, prt->printerName, + prt->shortServerName); if (ADS_ERR_OK(status) && ads_count_replies(ads, res)) { DEBUG(1, ("ads_add_printer: printer %s already exists\n", -- cgit From a834a73e341059be154426390304a42e4a011f72 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 25 Sep 2002 15:19:00 +0000 Subject: sync'ing up for 3.0alpha20 release (This used to be commit 65e7b5273bb58802bf0c389b77f7fcae0a1f6139) --- source3/libads/ldap_printer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 64ae8252c8..66984477b8 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -28,7 +28,7 @@ results can be used. It should be freed using ads_msgfree. */ ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, - char *printer, char *servername) + const char *printer, char *servername) { ADS_STATUS status; char *srv_dn, **srv_cn, *exp; -- cgit From 2f194322d419350f35a48dff750066894d68eccf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 Nov 2002 23:20:50 +0000 Subject: Removed global_myworkgroup, global_myname, global_myscope. Added liberal dashes of const. This is a rather large check-in, some things may break. It does compile though :-). Jeremy. (This used to be commit f755711df8f74f9b8e8c1a2b0d07d02a931eeb89) --- source3/libads/ldap_printer.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 66984477b8..0185bf7811 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -28,7 +28,7 @@ results can be used. It should be freed using ads_msgfree. */ ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, - const char *printer, char *servername) + const char *printer, const char *servername) { ADS_STATUS status; char *srv_dn, **srv_cn, *exp; @@ -77,7 +77,7 @@ ADS_STATUS ads_mod_printer_entry(ADS_STRUCT *ads, char *prt_dn, ads_mod_str(ctx, &mods, "versionNumber", prt->versionNumber); /* now the optional ones */ - ads_mod_strlist(ctx, &mods, "description", prt->description); + ads_mod_strlist(ctx, &mods, "description", (const char **)prt->description); ads_mod_str(ctx, &mods, "assetNumber",prt->assetNumber); ads_mod_str(ctx, &mods, "bytesPerMinute",prt->bytesPerMinute); ads_mod_str(ctx, &mods, "defaultPriority",prt->defaultPriority); @@ -93,10 +93,10 @@ ADS_STATUS ads_mod_printer_entry(ADS_STRUCT *ads, char *prt_dn, prt->operatingSystemVersion); ads_mod_str(ctx, &mods, "physicalLocationObject", prt->physicalLocationObject); - ads_mod_strlist(ctx, &mods, "portName", prt->portName); + ads_mod_strlist(ctx, &mods, "portName", (const char **)prt->portName); ads_mod_str(ctx, &mods, "printStartTime", prt->printStartTime); ads_mod_str(ctx, &mods, "printEndTime", prt->printEndTime); - ads_mod_strlist(ctx, &mods, "printBinNames", prt->printBinNames); + ads_mod_strlist(ctx, &mods, "printBinNames", (const char **)prt->printBinNames); /*... and many others */ /* do the ldap modify */ @@ -107,7 +107,6 @@ ADS_STATUS ads_mod_printer_entry(ADS_STRUCT *ads, char *prt_dn, return status; } - /* add a printer to the directory -- cgit From e4201bec142b6666a45c38532f1393270b6b0d48 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Mon, 18 Nov 2002 19:59:58 +0000 Subject: Next step of printer publishing. net ads printer publish [servername] Will retreive the DsSpooler and DsDriver info by rpc for a remote server then publish it. Next comes doing it within smbd (This used to be commit 8f047a4492f7bd66ac2afd2a2f6194d5dad4a434) --- source3/libads/ldap_printer.c | 348 +++++++++++++++++++++++++++++------------- 1 file changed, 242 insertions(+), 106 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 0185bf7811..4a983b20e3 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -54,142 +54,278 @@ ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, } /* - modify an entire printer entry in the directory + modify a printer entry in the directory */ ADS_STATUS ads_mod_printer_entry(ADS_STRUCT *ads, char *prt_dn, - const ADS_PRINTER_ENTRY *prt) + TALLOC_CTX *ctx, const ADS_MODLIST *mods) { - ADS_MODLIST mods; - ADS_STATUS status; - TALLOC_CTX *ctx; - - if (!(ctx = talloc_init_named("mod_printer_entry"))) - return ADS_ERROR(LDAP_NO_MEMORY); - - /* allocate the list */ - mods = ads_init_mods(ctx); - - /* add the attributes to the list - required ones first */ - ads_mod_str(ctx, &mods, "printerName", prt->printerName); - ads_mod_str(ctx, &mods, "serverName", prt->serverName); - ads_mod_str(ctx, &mods, "shortServerName", prt->shortServerName); - ads_mod_str(ctx, &mods, "uNCName", prt->uNCName); - ads_mod_str(ctx, &mods, "versionNumber", prt->versionNumber); - - /* now the optional ones */ - ads_mod_strlist(ctx, &mods, "description", (const char **)prt->description); - ads_mod_str(ctx, &mods, "assetNumber",prt->assetNumber); - ads_mod_str(ctx, &mods, "bytesPerMinute",prt->bytesPerMinute); - ads_mod_str(ctx, &mods, "defaultPriority",prt->defaultPriority); - ads_mod_str(ctx, &mods, "driverName", prt->driverName); - ads_mod_str(ctx, &mods, "driverVersion",prt->driverVersion); - ads_mod_str(ctx, &mods, "location", prt->location); - ads_mod_str(ctx, &mods, "operatingSystem",prt->operatingSystem); - ads_mod_str(ctx, &mods, "operatingSystemHotfix", - prt->operatingSystemHotfix); - ads_mod_str(ctx, &mods, "operatingSystemServicePack", - prt->operatingSystemServicePack); - ads_mod_str(ctx, &mods, "operatingSystemVersion", - prt->operatingSystemVersion); - ads_mod_str(ctx, &mods, "physicalLocationObject", - prt->physicalLocationObject); - ads_mod_strlist(ctx, &mods, "portName", (const char **)prt->portName); - ads_mod_str(ctx, &mods, "printStartTime", prt->printStartTime); - ads_mod_str(ctx, &mods, "printEndTime", prt->printEndTime); - ads_mod_strlist(ctx, &mods, "printBinNames", (const char **)prt->printBinNames); - /*... and many others */ - - /* do the ldap modify */ - status = ads_gen_mod(ads, prt_dn, mods); - - /* free mod list, mods, and values */ - talloc_destroy(ctx); - - return status; + return ads_gen_mod(ads, prt_dn, *mods); } /* add a printer to the directory */ -static ADS_STATUS ads_add_printer_entry(ADS_STRUCT *ads, char *prt_dn, - const ADS_PRINTER_ENTRY *prt) +ADS_STATUS ads_add_printer_entry(ADS_STRUCT *ads, char *prt_dn, + TALLOC_CTX *ctx, ADS_MODLIST *mods) { - ADS_STATUS status; - TALLOC_CTX *ctx; - ADS_MODLIST mods; + ads_mod_str(ctx, mods, "objectClass", "printQueue"); + return ads_gen_add(ads, prt_dn, *mods); +} - if (!(ctx = talloc_init_named("add_printer_entry"))) - return ADS_ERROR(LDAP_NO_MEMORY); +/* + map a REG_SZ to an ldap mod +*/ +static BOOL map_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, + const REGISTRY_VALUE *value) +{ + char *str_value = NULL; - if (!(mods = ads_init_mods(ctx))) - return ADS_ERROR(LDAP_NO_MEMORY); + if (value->type != REG_SZ) + return False; - /* These are the fields a printQueue must contain */ - ads_mod_str(ctx, &mods, "uNCName", prt->uNCName); - ads_mod_str(ctx, &mods, "versionNumber", prt->versionNumber); - ads_mod_str(ctx, &mods, "serverName", prt->serverName); - ads_mod_str(ctx, &mods, "shortServerName", prt->shortServerName); - ads_mod_str(ctx, &mods, "printerName", prt->printerName); - ads_mod_str(ctx, &mods, "objectClass", "printQueue"); + if (value->size && *((smb_ucs2_t *) value->data_p)) { + pull_ucs2_talloc(ctx, (void **) &str_value, + (const smb_ucs2_t *) value->data_p); + return ADS_ERR_OK(ads_mod_str(ctx, mods, value->valuename, + str_value)); + } + return True; + +} +/* + map a REG_DWORD to an ldap mod +*/ +static BOOL map_dword(TALLOC_CTX *ctx, ADS_MODLIST *mods, + const REGISTRY_VALUE *value) +{ + char *str_value = NULL; - status = ads_gen_add(ads, prt_dn, mods); + if (value->type != REG_DWORD) + return False; + str_value = talloc_asprintf(ctx, "%d", *((uint32 *) value->data_p)); + return ADS_ERR_OK(ads_mod_str(ctx, mods, value->valuename, str_value)); +} - talloc_destroy(ctx); +/* + map a boolean REG_BINARY to an ldap mod +*/ +static BOOL map_bool(TALLOC_CTX *ctx, ADS_MODLIST *mods, + const REGISTRY_VALUE *value) +{ + char *str_value; - return status; + if ((value->type != REG_BINARY) || (value->size != 1)) + return False; + str_value = talloc_asprintf(ctx, "%s", + *(value->data_p) ? "TRUE" : "FALSE"); + return ADS_ERR_OK(ads_mod_str(ctx, mods, value->valuename, str_value)); } /* - publish a printer in the ADS + map a REG_MULTI_SZ to an ldap mod */ - -ADS_STATUS ads_add_printer(ADS_STRUCT *ads, const ADS_PRINTER_ENTRY *prt) +static BOOL map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, + const REGISTRY_VALUE *value) { - ADS_STATUS status; - void *res; - char *host_dn, *prt_dn; - const char *attrs[] = {"*", "nTSecurityDescriptor", NULL}; + char **str_values = NULL; + smb_ucs2_t *cur_str = (smb_ucs2_t *) value->data_p; + uint32 size = 0, num_vals = 0, i=0; + + if (value->type != REG_MULTI_SZ) + return False; + + while(cur_str && *cur_str && (size < value->size)) { + size += 2 * (strlen_w(cur_str) + 1); + cur_str += strlen_w(cur_str) + 1; + num_vals++; + }; + + if (num_vals) { + str_values = talloc(ctx, + (num_vals + 1) * sizeof(smb_ucs2_t *)); + memset(str_values, '\0', + (num_vals + 1) * sizeof(smb_ucs2_t *)); + + cur_str = (smb_ucs2_t *) value->data_p; + for (i=0; i < num_vals; i++) + cur_str += pull_ucs2_talloc(ctx, + (void **) &str_values[i], + cur_str); + + return ADS_ERR_OK(ads_mod_strlist(ctx, mods, value->valuename, + (const char **) str_values)); + } + return True; +} - status = ads_find_machine_acct(ads, (void **)&res, - prt->shortServerName); - if (!ADS_ERR_OK(status)) { - DEBUG(1, ("ads_add_printer: cannot find host %s in ads\n", - prt->shortServerName)); - return status; - } - host_dn = ads_get_dn(ads, res); - ads_msgfree(ads, res); - - ads_find_printer_on_server(ads, &res, prt->printerName, - prt->shortServerName); - - if (ADS_ERR_OK(status) && ads_count_replies(ads, res)) { - DEBUG(1, ("ads_add_printer: printer %s already exists\n", - prt->printerName)); - /* nothing to do, just free results */ - ads_msgfree(ads, res); - } else { - ads_msgfree(ads, res); - status = ads_add_printer_entry(ads, prt_dn, prt); - if (!ADS_ERR_OK(status)) { - DEBUG(0, ("ads_add_printer: ads_add_printer_entry failed\n")); - return status; +struct valmap_to_ads { + char *valname; + BOOL (*fn)(TALLOC_CTX *, ADS_MODLIST *, const REGISTRY_VALUE *); +}; + +/* + map a REG_SZ to an ldap mod +*/ +static void map_regval_to_ads(TALLOC_CTX *ctx, ADS_MODLIST *mods, + REGISTRY_VALUE *value) +{ + struct valmap_to_ads map[] = { + {"assetNumber", map_sz}, + {"bytesPerMinute", map_dword}, + {"defaultPriority", map_dword}, + {"driverName", map_sz}, + {"driverVersion", map_dword}, + {"flags", map_dword}, + {"location", map_sz}, + {"operatingSystem", map_sz}, + {"operatingSystemHotfix", map_sz}, + {"operatingSystemServicePack", map_sz}, + {"operatingSystemVersion", map_sz}, + {"portName", map_multi_sz}, + {"printAttributes", map_dword}, + {"printBinNames", map_multi_sz}, + {"printCollate", map_bool}, + {"printColor", map_bool}, + {"printDuplexSupported", map_bool}, + {"printEndTime", map_dword}, + {"printFormName", map_sz}, + {"printKeepPrintedJobs", map_bool}, + {"printLanguage", map_multi_sz}, + {"printMACAddress", map_sz}, + {"printMaxCopies", map_sz}, + {"printMaxResolutionSupported", map_dword}, + {"printMaxXExtent", map_dword}, + {"printMaxYExtent", map_dword}, + {"printMediaReady", map_multi_sz}, + {"printMediaSupported", map_multi_sz}, + {"printMemory", map_dword}, + {"printMinXExtent", map_dword}, + {"printMinYExtent", map_dword}, + {"printNetworkAddress", map_sz}, + {"printNotify", map_sz}, + {"printNumberUp", map_dword}, + {"printOrientationsSupported", map_multi_sz}, + {"printOwner", map_sz}, + {"printPagesPerMinute", map_dword}, + {"printRate", map_dword}, + {"printRateUnit", map_sz}, + {"printSeparatorFile", map_sz}, + {"printShareName", map_sz}, + {"printSpooling", map_sz}, + {"printStaplingSupported", map_bool}, + {"printStartTime", map_dword}, + {"printStatus", map_sz}, + {"priority", map_dword}, + {"serverName", map_sz}, + {"shortServerName", map_sz}, + {"uNCName", map_sz}, + {"url", map_sz}, + {"versionNumber", map_dword}, + {NULL, NULL} + }; + int i; + + for (i=0; map[i].valname; i++) { + if (StrCaseCmp(map[i].valname, value->valuename) == 0) { + if (!map[i].fn(ctx, mods, value)) { + DEBUG(5, ("Add of value %s to modlist failed\n", value->valuename)); + } else { + DEBUG(7, ("Mapped value %s\n", value->valuename)); + } + } } +} + - status = ads_search_dn(ads, &res, prt_dn, attrs); +WERROR get_remote_printer_publishing_data(struct cli_state *cli, + TALLOC_CTX *mem_ctx, + ADS_MODLIST *mods, + char *printer) +{ + WERROR result; + char *printername, *servername; + REGVAL_CTR dsdriver_ctr, dsspooler_ctr; + uint32 needed, i; + POLICY_HND pol; + + asprintf(&servername, "\\\\%s", cli->desthost); + asprintf(&printername, "%s\\%s", servername, printer); + if (!servername || !printername) { + DEBUG(3, ("Insufficient memory\n")); + return WERR_NOMEM; + } + + result = cli_spoolss_open_printer_ex(cli, mem_ctx, printername, + "", MAXIMUM_ALLOWED_ACCESS, + servername, cli->user_name, &pol); + if (!W_ERROR_IS_OK(result)) { + DEBUG(3, ("Unable to open printer %s, error is %s.\n", + printername, dos_errstr(result))); + return result; + } + + result = cli_spoolss_enumprinterdataex(cli, mem_ctx, 0, &needed, + &pol, "DsDriver", NULL); + + if (W_ERROR_V(result) == ERRmoredata) + result = cli_spoolss_enumprinterdataex(cli, mem_ctx, needed, + NULL, &pol, "DsDriver", + &dsdriver_ctr); + + if (!W_ERROR_IS_OK(result)) { + DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n", + printername, dos_errstr(result))); + cli_spoolss_close_printer(cli, mem_ctx, &pol); + return result; + } - if (ADS_ERR_OK(status) && ads_count_replies(ads, res)) { - /* need to retrieve GUID from results - prt->GUID */ - status = ads_mod_printer_entry(ads, prt_dn, prt); + /* Have the data we need now, so start building */ + + for (i=0; i < dsdriver_ctr.num_values; i++) + map_regval_to_ads(mem_ctx, mods, dsdriver_ctr.values[i]); + + result = cli_spoolss_enumprinterdataex(cli, mem_ctx, 0, &needed, + &pol, "DsSpooler", NULL); + + if (W_ERROR_V(result) == ERRmoredata) + result = cli_spoolss_enumprinterdataex(cli, mem_ctx, needed, + NULL, &pol, "DsSpooler", + &dsspooler_ctr); + + if (!W_ERROR_IS_OK(result)) { + DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n", + printername, dos_errstr(result))); + regval_ctr_destroy(&dsdriver_ctr); + cli_spoolss_close_printer(cli, mem_ctx, &pol); + return result; } + for (i=0; i < dsspooler_ctr.num_values; i++) + map_regval_to_ads(mem_ctx, mods, dsspooler_ctr.values[i]); + + ads_mod_str(mem_ctx, mods, "printerName", printername); - ads_msgfree(ads, res); + regval_ctr_destroy(&dsdriver_ctr); + regval_ctr_destroy(&dsspooler_ctr); + cli_spoolss_close_printer(cli, mem_ctx, &pol); + return result; +} - return status; +BOOL get_local_printer_publishing_data(TALLOC_CTX *mem_ctx, + ADS_MODLIST *mods, + NT_PRINTER_DATA *data) +{ + uint32 key,val; + + for (key=0; key < data->num_keys; key++) { + REGVAL_CTR ctr = data->keys[key].values; + for (val=0; val < ctr.num_values; val++) + map_regval_to_ads(mem_ctx, mods, ctr.values[val]); + } + return True; } #endif + -- cgit From bf909c0c368adcd92d9cffa637257f82c950413b Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Mon, 18 Nov 2002 20:45:46 +0000 Subject: Don't pass a function to ADS_ERR_OK(). (This used to be commit dff4c93d85717ba29799a0ebaaba8b8539c8d68d) --- source3/libads/ldap_printer.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 4a983b20e3..1edc933683 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -79,6 +79,7 @@ static BOOL map_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, const REGISTRY_VALUE *value) { char *str_value = NULL; + ADS_STATUS status; if (value->type != REG_SZ) return False; @@ -86,8 +87,8 @@ static BOOL map_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, if (value->size && *((smb_ucs2_t *) value->data_p)) { pull_ucs2_talloc(ctx, (void **) &str_value, (const smb_ucs2_t *) value->data_p); - return ADS_ERR_OK(ads_mod_str(ctx, mods, value->valuename, - str_value)); + status = ads_mod_str(ctx, mods, value->valuename, str_value); + return ADS_ERR_OK(status); } return True; @@ -100,11 +101,13 @@ static BOOL map_dword(TALLOC_CTX *ctx, ADS_MODLIST *mods, const REGISTRY_VALUE *value) { char *str_value = NULL; + ADS_STATUS status; if (value->type != REG_DWORD) return False; str_value = talloc_asprintf(ctx, "%d", *((uint32 *) value->data_p)); - return ADS_ERR_OK(ads_mod_str(ctx, mods, value->valuename, str_value)); + status = ads_mod_str(ctx, mods, value->valuename, str_value); + return ADS_ERR_OK(status); } /* @@ -114,12 +117,14 @@ static BOOL map_bool(TALLOC_CTX *ctx, ADS_MODLIST *mods, const REGISTRY_VALUE *value) { char *str_value; + ADS_STATUS status; if ((value->type != REG_BINARY) || (value->size != 1)) return False; str_value = talloc_asprintf(ctx, "%s", *(value->data_p) ? "TRUE" : "FALSE"); - return ADS_ERR_OK(ads_mod_str(ctx, mods, value->valuename, str_value)); + status = ads_mod_str(ctx, mods, value->valuename, str_value); + return ADS_ERR_OK(status); } /* @@ -131,6 +136,7 @@ static BOOL map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, char **str_values = NULL; smb_ucs2_t *cur_str = (smb_ucs2_t *) value->data_p; uint32 size = 0, num_vals = 0, i=0; + ADS_STATUS status; if (value->type != REG_MULTI_SZ) return False; @@ -153,8 +159,9 @@ static BOOL map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, (void **) &str_values[i], cur_str); - return ADS_ERR_OK(ads_mod_strlist(ctx, mods, value->valuename, - (const char **) str_values)); + status = ads_mod_strlist(ctx, mods, value->valuename, + (const char **) str_values); + return ADS_ERR_OK(status); } return True; } -- cgit From 2e2f58fded84099f5d65ce0d0d53899a27557895 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Tue, 3 Dec 2002 19:42:39 +0000 Subject: Stop using hardcoded key/value strings, be more forgiving of dsspooler/dsdriver info existence. (This used to be commit 59ced15a1b0d88a24a89b3aa9717599aa110272b) --- source3/libads/ldap_printer.c | 144 ++++++++++++++++++++++-------------------- 1 file changed, 74 insertions(+), 70 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 1edc933683..a8c1148093 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -178,57 +178,57 @@ static void map_regval_to_ads(TALLOC_CTX *ctx, ADS_MODLIST *mods, REGISTRY_VALUE *value) { struct valmap_to_ads map[] = { - {"assetNumber", map_sz}, - {"bytesPerMinute", map_dword}, - {"defaultPriority", map_dword}, - {"driverName", map_sz}, - {"driverVersion", map_dword}, - {"flags", map_dword}, - {"location", map_sz}, - {"operatingSystem", map_sz}, - {"operatingSystemHotfix", map_sz}, - {"operatingSystemServicePack", map_sz}, - {"operatingSystemVersion", map_sz}, - {"portName", map_multi_sz}, - {"printAttributes", map_dword}, - {"printBinNames", map_multi_sz}, - {"printCollate", map_bool}, - {"printColor", map_bool}, - {"printDuplexSupported", map_bool}, - {"printEndTime", map_dword}, - {"printFormName", map_sz}, - {"printKeepPrintedJobs", map_bool}, - {"printLanguage", map_multi_sz}, - {"printMACAddress", map_sz}, - {"printMaxCopies", map_sz}, - {"printMaxResolutionSupported", map_dword}, - {"printMaxXExtent", map_dword}, - {"printMaxYExtent", map_dword}, - {"printMediaReady", map_multi_sz}, - {"printMediaSupported", map_multi_sz}, - {"printMemory", map_dword}, - {"printMinXExtent", map_dword}, - {"printMinYExtent", map_dword}, - {"printNetworkAddress", map_sz}, - {"printNotify", map_sz}, - {"printNumberUp", map_dword}, - {"printOrientationsSupported", map_multi_sz}, - {"printOwner", map_sz}, - {"printPagesPerMinute", map_dword}, - {"printRate", map_dword}, - {"printRateUnit", map_sz}, - {"printSeparatorFile", map_sz}, - {"printShareName", map_sz}, - {"printSpooling", map_sz}, - {"printStaplingSupported", map_bool}, - {"printStartTime", map_dword}, - {"printStatus", map_sz}, - {"priority", map_dword}, - {"serverName", map_sz}, - {"shortServerName", map_sz}, - {"uNCName", map_sz}, - {"url", map_sz}, - {"versionNumber", map_dword}, + {SPOOL_REG_ASSETNUMBER, map_sz}, + {SPOOL_REG_BYTESPERMINUTE, map_dword}, + {SPOOL_REG_DEFAULTPRIORITY, map_dword}, + {SPOOL_REG_DRIVERNAME, map_sz}, + {SPOOL_REG_DRIVERVERSION, map_dword}, + {SPOOL_REG_FLAGS, map_dword}, + {SPOOL_REG_LOCATION, map_sz}, + {SPOOL_REG_OPERATINGSYSTEM, map_sz}, + {SPOOL_REG_OPERATINGSYSTEMHOTFIX, map_sz}, + {SPOOL_REG_OPERATINGSYSTEMSERVICEPACK, map_sz}, + {SPOOL_REG_OPERATINGSYSTEMVERSION, map_sz}, + {SPOOL_REG_PORTNAME, map_multi_sz}, + {SPOOL_REG_PRINTATTRIBUTES, map_dword}, + {SPOOL_REG_PRINTBINNAMES, map_multi_sz}, + {SPOOL_REG_PRINTCOLLATE, map_bool}, + {SPOOL_REG_PRINTCOLOR, map_bool}, + {SPOOL_REG_PRINTDUPLEXSUPPORTED, map_bool}, + {SPOOL_REG_PRINTENDTIME, map_dword}, + {SPOOL_REG_PRINTFORMNAME, map_sz}, + {SPOOL_REG_PRINTKEEPPRINTEDJOBS, map_bool}, + {SPOOL_REG_PRINTLANGUAGE, map_multi_sz}, + {SPOOL_REG_PRINTMACADDRESS, map_sz}, + {SPOOL_REG_PRINTMAXCOPIES, map_sz}, + {SPOOL_REG_PRINTMAXRESOLUTIONSUPPORTED, map_dword}, + {SPOOL_REG_PRINTMAXXEXTENT, map_dword}, + {SPOOL_REG_PRINTMAXYEXTENT, map_dword}, + {SPOOL_REG_PRINTMEDIAREADY, map_multi_sz}, + {SPOOL_REG_PRINTMEDIASUPPORTED, map_multi_sz}, + {SPOOL_REG_PRINTMEMORY, map_dword}, + {SPOOL_REG_PRINTMINXEXTENT, map_dword}, + {SPOOL_REG_PRINTMINYEXTENT, map_dword}, + {SPOOL_REG_PRINTNETWORKADDRESS, map_sz}, + {SPOOL_REG_PRINTNOTIFY, map_sz}, + {SPOOL_REG_PRINTNUMBERUP, map_dword}, + {SPOOL_REG_PRINTORIENTATIONSSUPPORTED, map_multi_sz}, + {SPOOL_REG_PRINTOWNER, map_sz}, + {SPOOL_REG_PRINTPAGESPERMINUTE, map_dword}, + {SPOOL_REG_PRINTRATE, map_dword}, + {SPOOL_REG_PRINTRATEUNIT, map_sz}, + {SPOOL_REG_PRINTSEPARATORFILE, map_sz}, + {SPOOL_REG_PRINTSHARENAME, map_sz}, + {SPOOL_REG_PRINTSPOOLING, map_sz}, + {SPOOL_REG_PRINTSTAPLINGSUPPORTED, map_bool}, + {SPOOL_REG_PRINTSTARTTIME, map_dword}, + {SPOOL_REG_PRINTSTATUS, map_sz}, + {SPOOL_REG_PRIORITY, map_dword}, + {SPOOL_REG_SERVERNAME, map_sz}, + {SPOOL_REG_SHORTSERVERNAME, map_sz}, + {SPOOL_REG_UNCNAME, map_sz}, + {SPOOL_REG_URL, map_sz}, + {SPOOL_REG_VERSIONNUMBER, map_dword}, {NULL, NULL} }; int i; @@ -254,6 +254,7 @@ WERROR get_remote_printer_publishing_data(struct cli_state *cli, WERROR result; char *printername, *servername; REGVAL_CTR dsdriver_ctr, dsspooler_ctr; + BOOL got_dsdriver = False, got_dsspooler = False; uint32 needed, i; POLICY_HND pol; @@ -274,47 +275,50 @@ WERROR get_remote_printer_publishing_data(struct cli_state *cli, } result = cli_spoolss_enumprinterdataex(cli, mem_ctx, 0, &needed, - &pol, "DsDriver", NULL); + &pol, SPOOL_DSDRIVER_KEY, NULL); if (W_ERROR_V(result) == ERRmoredata) result = cli_spoolss_enumprinterdataex(cli, mem_ctx, needed, - NULL, &pol, "DsDriver", + NULL, &pol, + SPOOL_DSDRIVER_KEY, &dsdriver_ctr); if (!W_ERROR_IS_OK(result)) { DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n", printername, dos_errstr(result))); - cli_spoolss_close_printer(cli, mem_ctx, &pol); - return result; - } - - /* Have the data we need now, so start building */ + } else { - for (i=0; i < dsdriver_ctr.num_values; i++) - map_regval_to_ads(mem_ctx, mods, dsdriver_ctr.values[i]); + /* Have the data we need now, so start building */ + got_dsdriver = True; + for (i=0; i < dsdriver_ctr.num_values; i++) + map_regval_to_ads(mem_ctx, mods, + dsdriver_ctr.values[i]); + } result = cli_spoolss_enumprinterdataex(cli, mem_ctx, 0, &needed, - &pol, "DsSpooler", NULL); + &pol, SPOOL_DSSPOOLER_KEY, + NULL); if (W_ERROR_V(result) == ERRmoredata) result = cli_spoolss_enumprinterdataex(cli, mem_ctx, needed, - NULL, &pol, "DsSpooler", + NULL, &pol, + SPOOL_DSSPOOLER_KEY, &dsspooler_ctr); if (!W_ERROR_IS_OK(result)) { DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n", printername, dos_errstr(result))); - regval_ctr_destroy(&dsdriver_ctr); - cli_spoolss_close_printer(cli, mem_ctx, &pol); - return result; + } else { + got_dsspooler = True; + for (i=0; i < dsspooler_ctr.num_values; i++) + map_regval_to_ads(mem_ctx, mods, + dsspooler_ctr.values[i]); } - for (i=0; i < dsspooler_ctr.num_values; i++) - map_regval_to_ads(mem_ctx, mods, dsspooler_ctr.values[i]); - ads_mod_str(mem_ctx, mods, "printerName", printername); + ads_mod_str(mem_ctx, mods, SPOOL_REG_PRINTERNAME, printer); - regval_ctr_destroy(&dsdriver_ctr); - regval_ctr_destroy(&dsspooler_ctr); + if (got_dsdriver) regval_ctr_destroy(&dsdriver_ctr); + if (got_dsspooler) regval_ctr_destroy(&dsspooler_ctr); cli_spoolss_close_printer(cli, mem_ctx, &pol); return result; -- cgit From 26236b30d09ebf31e43911f2d7cbec80df519b71 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Thu, 5 Dec 2002 19:13:40 +0000 Subject: More printer data to publish (This used to be commit 6e2f0c4e304a09313f933a3c9c2a7b3a0219006d) --- source3/libads/ldap_printer.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index a8c1148093..b2ee5f2265 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -181,6 +181,7 @@ static void map_regval_to_ads(TALLOC_CTX *ctx, ADS_MODLIST *mods, {SPOOL_REG_ASSETNUMBER, map_sz}, {SPOOL_REG_BYTESPERMINUTE, map_dword}, {SPOOL_REG_DEFAULTPRIORITY, map_dword}, + {SPOOL_REG_DESCRIPTION, map_sz}, {SPOOL_REG_DRIVERNAME, map_sz}, {SPOOL_REG_DRIVERVERSION, map_dword}, {SPOOL_REG_FLAGS, map_dword}, -- cgit From 634c54310c92c48dd4eceec602e230a021bdcfc5 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 3 Jan 2003 08:28:12 +0000 Subject: Merge from HEAD - make Samba compile with -Wwrite-strings without additional warnings. (Adds a lot of const). Andrew Bartlett (This used to be commit 3a7458f9472432ef12c43008414925fd1ce8ea0c) --- source3/libads/ldap_printer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index b2ee5f2265..87ea058896 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -167,7 +167,7 @@ static BOOL map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, } struct valmap_to_ads { - char *valname; + const char *valname; BOOL (*fn)(TALLOC_CTX *, ADS_MODLIST *, const REGISTRY_VALUE *); }; @@ -177,7 +177,7 @@ struct valmap_to_ads { static void map_regval_to_ads(TALLOC_CTX *ctx, ADS_MODLIST *mods, REGISTRY_VALUE *value) { - struct valmap_to_ads map[] = { + const struct valmap_to_ads map[] = { {SPOOL_REG_ASSETNUMBER, map_sz}, {SPOOL_REG_BYTESPERMINUTE, map_dword}, {SPOOL_REG_DEFAULTPRIORITY, map_dword}, @@ -250,7 +250,7 @@ static void map_regval_to_ads(TALLOC_CTX *ctx, ADS_MODLIST *mods, WERROR get_remote_printer_publishing_data(struct cli_state *cli, TALLOC_CTX *mem_ctx, ADS_MODLIST *mods, - char *printer) + const char *printer) { WERROR result; char *printername, *servername; -- cgit From 251ea1e6776401005e302addd56a689c01924426 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 19 Feb 2003 12:31:16 +0000 Subject: Merge minor library fixes from HEAD to 3.0. - setenv() replacement - mimir's ASN1/SPNEGO typo fixes - (size_t)-1 fixes for push_* returns - function argument signed/unsigned correction - ASN1 error handling (ensure we don't use initiailsed data) - extra net ads join error checking - allow 'set security discriptor' to fail - escape ldap strings in libads. - getgrouplist() correctness fixes (include primary gid) Andrew Bartlett (This used to be commit e9d6e2ea9a3dc01d3849b925c50702cda6ddf225) --- source3/libads/ldap_printer.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 87ea058896..f5cd4f2885 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -85,8 +85,7 @@ static BOOL map_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, return False; if (value->size && *((smb_ucs2_t *) value->data_p)) { - pull_ucs2_talloc(ctx, (void **) &str_value, - (const smb_ucs2_t *) value->data_p); + pull_ucs2_talloc(ctx, &str_value, (const smb_ucs2_t *) value->data_p); status = ads_mod_str(ctx, mods, value->valuename, str_value); return ADS_ERR_OK(status); } @@ -155,9 +154,8 @@ static BOOL map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, cur_str = (smb_ucs2_t *) value->data_p; for (i=0; i < num_vals; i++) - cur_str += pull_ucs2_talloc(ctx, - (void **) &str_values[i], - cur_str); + cur_str += pull_ucs2_talloc(ctx, &str_values[i], + cur_str); status = ads_mod_strlist(ctx, mods, value->valuename, (const char **) str_values); -- cgit From 61742d1117e12cbb131f9c55ab0a9acbcc1f4d3a Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 13 Jun 2003 04:29:20 +0000 Subject: Fix shadow variable warning. (This used to be commit c22a4074bd2b998339826ba629fe48153639ec18) --- source3/libads/ldap_printer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index f5cd4f2885..aa5ac15b5d 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -31,7 +31,7 @@ ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, const char *printer, const char *servername) { ADS_STATUS status; - char *srv_dn, **srv_cn, *exp; + char *srv_dn, **srv_cn, *s; const char *attrs[] = {"*", "nTSecurityDescriptor", NULL}; status = ads_find_machine_acct(ads, res, servername); @@ -44,12 +44,12 @@ ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, srv_cn = ldap_explode_dn(srv_dn, 1); ads_msgfree(ads, *res); - asprintf(&exp, "(cn=%s-%s)", srv_cn[0], printer); - status = ads_search(ads, res, exp, attrs); + asprintf(&s, "(cn=%s-%s)", srv_cn[0], printer); + status = ads_search(ads, res, s, attrs); ldap_memfree(srv_dn); ldap_value_free(srv_cn); - free(exp); + free(s); return status; } -- cgit From baf439cd55d79133e2fca598834e362a81a911a4 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 3 Jul 2003 05:08:51 +0000 Subject: Implemented 'net ads printer search' which searches the directory for published printers. At the moment we don't search using any parameters but this can be fixed by changing the LDAP search string. Also we should contact the global catalog at SRV _gc._tcp instead of the ldap server we get back from ads_startup(). (This used to be commit 814519c5de7f962623163b732c8589abd355d845) --- source3/libads/ldap_printer.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index aa5ac15b5d..b650a5eb38 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -53,6 +53,20 @@ ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, return status; } +ADS_STATUS ads_find_printers(ADS_STRUCT *ads, void **res) +{ + char *ldap_expr; + const char *attrs[] = { "objectClass", "printerName", "location", "driverName", + "serverName", "description", NULL }; + + /* For the moment only display all printers */ + + ldap_expr = "(&(!(showInAdvancedViewOnly=TRUE))(uncName=*)" + "(objectCategory=printQueue))"; + + return ads_search(ads, res, ldap_expr, attrs); +} + /* modify a printer entry in the directory */ @@ -338,4 +352,3 @@ BOOL get_local_printer_publishing_data(TALLOC_CTX *mem_ctx, } #endif - -- cgit From 9f2e6167d22cc06fa94495574fc29d6bcbb1dd8a Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 1 Aug 2003 15:21:20 +0000 Subject: Update my copyrights according to my agreement with IBM (This used to be commit c9b209be2b17c2e4677cc30b46b1074f48878f43) --- source3/libads/ldap_printer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index b650a5eb38..1448074ea0 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -1,7 +1,7 @@ /* Unix SMB/CIFS implementation. ads (active directory) printer utility library - Copyright (C) Jim McDonough 2002 + Copyright (C) Jim McDonough 2002 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 -- cgit From 5a8effaaae3c3037ae0f96a942734298950169c6 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 23 Sep 2004 19:24:02 +0000 Subject: r2569: Patch from Rob Foehl : - fix typo in libads/ldap_printer.c:39, ads_find_printer_on_server() (originally libads-typo.patch) - fix leak in printing/nt_printing.c, is_printer_published() (originally is_printer_published-leak.patch) - fix double print_backend_init() calls, now only called from main() - restructuring in printing/nt_printing.c - replaced (un)publish_it() with ads-specific functions - moved common code to nt_printer_publish() - improved error handling in several places - added check_published_printers() in printing/nt_printing.c, to verify that each published printer is actually in the directory at startup - changed calling semantics of mod_a_printer, dump_a_printer, and update_driver_init to be more consistent with the rest of the api and reduce some copying (This used to be commit 50a5a3dbd02acb0d09133b6e42cc37d091ea901d) --- source3/libads/ldap_printer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 1448074ea0..d8e4cefcfa 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -36,7 +36,7 @@ ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, status = ads_find_machine_acct(ads, res, servername); if (!ADS_ERR_OK(status)) { - DEBUG(1, ("ads_add_printer: cannot find host %s in ads\n", + DEBUG(1, ("ads_find_printer_on_server: cannot find host %s in ads\n", servername)); return status; } -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/libads/ldap_printer.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index d8e4cefcfa..68e6735891 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -161,10 +161,9 @@ static BOOL map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, }; if (num_vals) { - str_values = talloc(ctx, - (num_vals + 1) * sizeof(smb_ucs2_t *)); + str_values = TALLOC_ARRAY(ctx, char *, num_vals + 1); memset(str_values, '\0', - (num_vals + 1) * sizeof(smb_ucs2_t *)); + (num_vals + 1) * sizeof(char *)); cur_str = (smb_ucs2_t *) value->data_p; for (i=0; i < num_vals; i++) -- cgit From 9840db418bad5a39edc4a32a1786f5e2d2c9dff8 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 31 Mar 2005 05:06:04 +0000 Subject: r6149: Fixes bugs #2498 and 2484. 1. using smbc_getxattr() et al, one may now request all access control entities in the ACL without getting all other NT attributes. 2. added the ability to exclude specified attributes from the result set provided by smbc_getxattr() et al, when requesting all attributes, all NT attributes, or all DOS attributes. 3. eliminated all compiler warnings, including when --enable-developer compiler flags are in use. removed -Wcast-qual flag from list, as that is specifically to force warnings in the case of casting away qualifiers. Note: In the process of eliminating compiler warnings, a few nasties were discovered. In the file libads/sasl.c, PRIVATE kerberos interfaces are being used; and in libsmb/clikrb5.c, both PRIAVE and DEPRECATED kerberos interfaces are being used. Someone who knows kerberos should look at these and determine if there is an alternate method of accomplishing the task. (This used to be commit 994694f7f26da5099f071e1381271a70407f33bb) --- source3/libads/ldap_printer.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 68e6735891..61275e40d1 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -61,8 +61,10 @@ ADS_STATUS ads_find_printers(ADS_STRUCT *ads, void **res) /* For the moment only display all printers */ - ldap_expr = "(&(!(showInAdvancedViewOnly=TRUE))(uncName=*)" - "(objectCategory=printQueue))"; + ldap_expr = + CONST_DISCARD(char *, + "(&(!(showInAdvancedViewOnly=TRUE))(uncName=*)" + "(objectCategory=printQueue))"); return ads_search(ads, res, ldap_expr, attrs); } -- cgit From f24d88cf9da46680d52b42b92bd484e7b09ce99b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 31 May 2005 13:46:45 +0000 Subject: r7139: trying to reduce the number of diffs between trunk and 3.0; changing version to 3.0.20pre1 (This used to be commit 9727d05241574042dd3aa8844ae5c701d22e2da1) --- source3/libads/ldap_printer.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 61275e40d1..68e6735891 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -61,10 +61,8 @@ ADS_STATUS ads_find_printers(ADS_STRUCT *ads, void **res) /* For the moment only display all printers */ - ldap_expr = - CONST_DISCARD(char *, - "(&(!(showInAdvancedViewOnly=TRUE))(uncName=*)" - "(objectCategory=printQueue))"); + ldap_expr = "(&(!(showInAdvancedViewOnly=TRUE))(uncName=*)" + "(objectCategory=printQueue))"; return ads_search(ads, res, ldap_expr, attrs); } -- cgit From ecafd3754f35a2109a3a1eecbbdd72ade06b8502 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 20 Jul 2005 15:35:29 +0000 Subject: r8654: merging cli_spoolss_XX() updates from trunk (This used to be commit cd961e50a3029898868d21263ccacb7d5f1f07b9) --- source3/libads/ldap_printer.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 68e6735891..6b053f8b4a 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -267,7 +267,7 @@ WERROR get_remote_printer_publishing_data(struct cli_state *cli, char *printername, *servername; REGVAL_CTR dsdriver_ctr, dsspooler_ctr; BOOL got_dsdriver = False, got_dsspooler = False; - uint32 needed, i; + uint32 i; POLICY_HND pol; asprintf(&servername, "\\\\%s", cli->desthost); @@ -286,14 +286,7 @@ WERROR get_remote_printer_publishing_data(struct cli_state *cli, return result; } - result = cli_spoolss_enumprinterdataex(cli, mem_ctx, 0, &needed, - &pol, SPOOL_DSDRIVER_KEY, NULL); - - if (W_ERROR_V(result) == ERRmoredata) - result = cli_spoolss_enumprinterdataex(cli, mem_ctx, needed, - NULL, &pol, - SPOOL_DSDRIVER_KEY, - &dsdriver_ctr); + result = cli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSDRIVER_KEY, NULL); if (!W_ERROR_IS_OK(result)) { DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n", @@ -307,15 +300,7 @@ WERROR get_remote_printer_publishing_data(struct cli_state *cli, dsdriver_ctr.values[i]); } - result = cli_spoolss_enumprinterdataex(cli, mem_ctx, 0, &needed, - &pol, SPOOL_DSSPOOLER_KEY, - NULL); - - if (W_ERROR_V(result) == ERRmoredata) - result = cli_spoolss_enumprinterdataex(cli, mem_ctx, needed, - NULL, &pol, - SPOOL_DSSPOOLER_KEY, - &dsspooler_ctr); + result = cli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSSPOOLER_KEY, NULL); if (!W_ERROR_IS_OK(result)) { DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n", -- cgit From 63546f1c79db09c1d7032af8d941d6d9497280e7 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 21 Jul 2005 09:28:12 +0000 Subject: r8675: fix some compile warnings. Guenther (This used to be commit afa8ae831a8d9cde8c6474c5fc807a9ca8155273) --- source3/libads/ldap_printer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 6b053f8b4a..9773296ae0 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -55,7 +55,7 @@ ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, ADS_STATUS ads_find_printers(ADS_STRUCT *ads, void **res) { - char *ldap_expr; + const char *ldap_expr; const char *attrs[] = { "objectClass", "printerName", "location", "driverName", "serverName", "description", NULL }; -- cgit From 14a9d52832b19a698968900da6378d542d6a21ce Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 1 Aug 2005 20:54:31 +0000 Subject: r8899: various compiler warning fixes reported by Jason Mader (This used to be commit d8ae9f2b3e5387ef2c4e84cd9c33f4a7c795b0d3) --- source3/libads/ldap_printer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 9773296ae0..f4ecbdd93c 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -286,7 +286,7 @@ WERROR get_remote_printer_publishing_data(struct cli_state *cli, return result; } - result = cli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSDRIVER_KEY, NULL); + result = cli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSDRIVER_KEY, &dsdriver_ctr); if (!W_ERROR_IS_OK(result)) { DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n", @@ -300,7 +300,7 @@ WERROR get_remote_printer_publishing_data(struct cli_state *cli, dsdriver_ctr.values[i]); } - result = cli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSSPOOLER_KEY, NULL); + result = cli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSSPOOLER_KEY, &dsspooler_ctr); if (!W_ERROR_IS_OK(result)) { DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n", -- cgit From 44707ad2e00a91f459e80efbe8f362b5853b0a62 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 29 Aug 2005 14:55:40 +0000 Subject: r9739: conver the reg_objects (REGSUBKEY_CTR & REGVAL_CTR) to use the new talloc() features: Note that the REGSUB_CTR and REGVAL_CTR objects *must* be talloc()'d since the methods use the object pointer as the talloc context for internal private data. There is no longer a regXXX_ctr_intit() and regXXX_ctr_destroy() pair of functions. Simply TALLOC_ZERO_P() and TALLOC_FREE() the object. Also had to convert the printer_info_2->NT_PRINTER_DATA field to be talloc()'d as well. This is just a stop on the road to cleaning up the printer memory management. (This used to be commit ef721333ab9639cb5346067497e99fbd0d4425dd) --- source3/libads/ldap_printer.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index f4ecbdd93c..db544fe209 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -265,8 +265,7 @@ WERROR get_remote_printer_publishing_data(struct cli_state *cli, { WERROR result; char *printername, *servername; - REGVAL_CTR dsdriver_ctr, dsspooler_ctr; - BOOL got_dsdriver = False, got_dsspooler = False; + REGVAL_CTR *dsdriver_ctr, *dsspooler_ctr; uint32 i; POLICY_HND pol; @@ -286,36 +285,44 @@ WERROR get_remote_printer_publishing_data(struct cli_state *cli, return result; } - result = cli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSDRIVER_KEY, &dsdriver_ctr); + if ( !(dsdriver_ctr = TALLOC_ZERO_P( mem_ctx, REGVAL_CTR )) ) + return WERR_NOMEM; + + result = cli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSDRIVER_KEY, dsdriver_ctr); if (!W_ERROR_IS_OK(result)) { DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n", printername, dos_errstr(result))); } else { + uint32 num_values = regval_ctr_numvals( dsdriver_ctr ); /* Have the data we need now, so start building */ - got_dsdriver = True; - for (i=0; i < dsdriver_ctr.num_values; i++) - map_regval_to_ads(mem_ctx, mods, - dsdriver_ctr.values[i]); + for (i=0; i < num_values; i++) { + map_regval_to_ads(mem_ctx, mods, dsdriver_ctr->values[i]); + } } - result = cli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSSPOOLER_KEY, &dsspooler_ctr); + if ( !(dsspooler_ctr = TALLOC_ZERO_P( mem_ctx, REGVAL_CTR )) ) + return WERR_NOMEM; + + result = cli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSSPOOLER_KEY, dsspooler_ctr); if (!W_ERROR_IS_OK(result)) { DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n", printername, dos_errstr(result))); } else { - got_dsspooler = True; - for (i=0; i < dsspooler_ctr.num_values; i++) - map_regval_to_ads(mem_ctx, mods, - dsspooler_ctr.values[i]); + uint32 num_values = regval_ctr_numvals( dsspooler_ctr ); + + for (i=0; ivalues[i]); + } } ads_mod_str(mem_ctx, mods, SPOOL_REG_PRINTERNAME, printer); - if (got_dsdriver) regval_ctr_destroy(&dsdriver_ctr); - if (got_dsspooler) regval_ctr_destroy(&dsspooler_ctr); + TALLOC_FREE( dsdriver_ctr ); + TALLOC_FREE( dsspooler_ctr ); + cli_spoolss_close_printer(cli, mem_ctx, &pol); return result; @@ -328,9 +335,9 @@ BOOL get_local_printer_publishing_data(TALLOC_CTX *mem_ctx, uint32 key,val; for (key=0; key < data->num_keys; key++) { - REGVAL_CTR ctr = data->keys[key].values; - for (val=0; val < ctr.num_values; val++) - map_regval_to_ads(mem_ctx, mods, ctr.values[val]); + REGVAL_CTR *ctr = data->keys[key].values; + for (val=0; val < ctr->num_values; val++) + map_regval_to_ads(mem_ctx, mods, ctr->values[val]); } return True; } -- cgit From 54abd2aa66069e6baf7769c496f46d9dba18db39 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 30 Sep 2005 17:13:37 +0000 Subject: r10656: BIG merge from trunk. Features not copied over * \PIPE\unixinfo * winbindd's {group,alias}membership new functions * winbindd's lookupsids() functionality * swat (trunk changes to be reverted as per discussion with Deryck) (This used to be commit 939c3cb5d78e3a2236209b296aa8aba8bdce32d3) --- source3/libads/ldap_printer.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index db544fe209..d6ac09d22b 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -258,7 +258,7 @@ static void map_regval_to_ads(TALLOC_CTX *ctx, ADS_MODLIST *mods, } -WERROR get_remote_printer_publishing_data(struct cli_state *cli, +WERROR get_remote_printer_publishing_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, ADS_MODLIST *mods, const char *printer) @@ -269,16 +269,16 @@ WERROR get_remote_printer_publishing_data(struct cli_state *cli, uint32 i; POLICY_HND pol; - asprintf(&servername, "\\\\%s", cli->desthost); + asprintf(&servername, "\\\\%s", cli->cli->desthost); asprintf(&printername, "%s\\%s", servername, printer); if (!servername || !printername) { DEBUG(3, ("Insufficient memory\n")); return WERR_NOMEM; } - result = cli_spoolss_open_printer_ex(cli, mem_ctx, printername, + result = rpccli_spoolss_open_printer_ex(cli, mem_ctx, printername, "", MAXIMUM_ALLOWED_ACCESS, - servername, cli->user_name, &pol); + servername, cli->cli->user_name, &pol); if (!W_ERROR_IS_OK(result)) { DEBUG(3, ("Unable to open printer %s, error is %s.\n", printername, dos_errstr(result))); @@ -288,7 +288,7 @@ WERROR get_remote_printer_publishing_data(struct cli_state *cli, if ( !(dsdriver_ctr = TALLOC_ZERO_P( mem_ctx, REGVAL_CTR )) ) return WERR_NOMEM; - result = cli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSDRIVER_KEY, dsdriver_ctr); + result = rpccli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSDRIVER_KEY, dsdriver_ctr); if (!W_ERROR_IS_OK(result)) { DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n", @@ -305,7 +305,7 @@ WERROR get_remote_printer_publishing_data(struct cli_state *cli, if ( !(dsspooler_ctr = TALLOC_ZERO_P( mem_ctx, REGVAL_CTR )) ) return WERR_NOMEM; - result = cli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSSPOOLER_KEY, dsspooler_ctr); + result = rpccli_spoolss_enumprinterdataex(cli, mem_ctx, &pol, SPOOL_DSSPOOLER_KEY, dsspooler_ctr); if (!W_ERROR_IS_OK(result)) { DEBUG(3, ("Unable to do enumdataex on %s, error is %s.\n", @@ -323,7 +323,7 @@ WERROR get_remote_printer_publishing_data(struct cli_state *cli, TALLOC_FREE( dsdriver_ctr ); TALLOC_FREE( dsspooler_ctr ); - cli_spoolss_close_printer(cli, mem_ctx, &pol); + rpccli_spoolss_close_printer(cli, mem_ctx, &pol); return result; } -- cgit From 86a13b97e418a9b06dace463b296f22600ed8b2c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 16 Jun 2006 23:26:48 +0000 Subject: r16326: Klocwork #509. Always check return allocs. Jeremy. (This used to be commit 7e397b534a5ca5809facf5aa84acbfb0b8c9a5b4) --- source3/libads/ldap_printer.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index d6ac09d22b..12bf6eec1d 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -119,6 +119,9 @@ static BOOL map_dword(TALLOC_CTX *ctx, ADS_MODLIST *mods, if (value->type != REG_DWORD) return False; str_value = talloc_asprintf(ctx, "%d", *((uint32 *) value->data_p)); + if (!str_value) { + return False; + } status = ads_mod_str(ctx, mods, value->valuename, str_value); return ADS_ERR_OK(status); } @@ -136,6 +139,9 @@ static BOOL map_bool(TALLOC_CTX *ctx, ADS_MODLIST *mods, return False; str_value = talloc_asprintf(ctx, "%s", *(value->data_p) ? "TRUE" : "FALSE"); + if (!str_value) { + return False; + } status = ads_mod_str(ctx, mods, value->valuename, str_value); return ADS_ERR_OK(status); } @@ -162,6 +168,9 @@ static BOOL map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, if (num_vals) { str_values = TALLOC_ARRAY(ctx, char *, num_vals + 1); + if (!str_values) { + return False; + } memset(str_values, '\0', (num_vals + 1) * sizeof(char *)); -- cgit From ee0e397d6f003c583768803aa27716b2b7a23981 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 3 Sep 2006 21:07:16 +0000 Subject: r18019: Fix a C++ warnings: Don't use void * in libads/ for LDAPMessage anymore. Compiled it on systems with and without LDAP, I hope it does not break the build farm too badly. If it does, I'll fix it tomorrow. Volker (This used to be commit b2ff9680ebe0979fbeef7f2dabc2e3f27c959d11) --- source3/libads/ldap_printer.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 12bf6eec1d..50233140f0 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -27,8 +27,9 @@ Note that results "res" may be allocated on return so that the results can be used. It should be freed using ads_msgfree. */ -ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, - const char *printer, const char *servername) + ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, LDAPMessage **res, + const char *printer, + const char *servername) { ADS_STATUS status; char *srv_dn, **srv_cn, *s; @@ -53,7 +54,7 @@ ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, return status; } -ADS_STATUS ads_find_printers(ADS_STRUCT *ads, void **res) + ADS_STATUS ads_find_printers(ADS_STRUCT *ads, LDAPMessage **res) { const char *ldap_expr; const char *attrs[] = { "objectClass", "printerName", "location", "driverName", -- cgit From ac080e3184abcc177f9f8e8bf2f3537739b9e8ad Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 2 Oct 2006 12:06:49 +0000 Subject: r19039: Do not segfault in "net ads printer info" when a requested printserver does not exist. Guenther (This used to be commit 359315021df3a4dbfe5142e529e3efdbc49e405c) --- source3/libads/ldap_printer.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 50233140f0..f5168b05af 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -41,8 +41,18 @@ servername)); return status; } + if (ads_count_replies(ads, *res) != 1) { + return ADS_ERROR(LDAP_NO_SUCH_OBJECT); + } srv_dn = ldap_get_dn(ads->ld, *res); + if (srv_dn == NULL) { + return ADS_ERROR(LDAP_NO_MEMORY); + } srv_cn = ldap_explode_dn(srv_dn, 1); + if (srv_cn == NULL) { + ldap_memfree(srv_dn); + return ADS_ERROR(LDAP_INVALID_DN_SYNTAX); + } ads_msgfree(ads, *res); asprintf(&s, "(cn=%s-%s)", srv_cn[0], printer); -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/libads/ldap_printer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index f5168b05af..cf6e1e08b0 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -5,7 +5,7 @@ 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 2 of the License, or + 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, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/libads/ldap_printer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index cf6e1e08b0..cfddd4cc8a 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -14,8 +14,7 @@ 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 809c9d4d3136cc46dc228107918ca19d5a008a0a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 16 Jul 2007 11:08:00 +0000 Subject: r23888: move elements belonging to the current ldap connection to a substructure. metze (This used to be commit 00909194a6c1ed193dfdb296f50f58a53450583c) --- source3/libads/ldap_printer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index cfddd4cc8a..0c6a280c36 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -43,7 +43,7 @@ if (ads_count_replies(ads, *res) != 1) { return ADS_ERROR(LDAP_NO_SUCH_OBJECT); } - srv_dn = ldap_get_dn(ads->ld, *res); + srv_dn = ldap_get_dn(ads->ldap.ld, *res); if (srv_dn == NULL) { return ADS_ERROR(LDAP_NO_MEMORY); } -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/libads/ldap_printer.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 0c6a280c36..05fbc071d8 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -99,7 +99,7 @@ ADS_STATUS ads_add_printer_entry(ADS_STRUCT *ads, char *prt_dn, /* map a REG_SZ to an ldap mod */ -static BOOL map_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, +static bool map_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, const REGISTRY_VALUE *value) { char *str_value = NULL; @@ -120,7 +120,7 @@ static BOOL map_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, /* map a REG_DWORD to an ldap mod */ -static BOOL map_dword(TALLOC_CTX *ctx, ADS_MODLIST *mods, +static bool map_dword(TALLOC_CTX *ctx, ADS_MODLIST *mods, const REGISTRY_VALUE *value) { char *str_value = NULL; @@ -139,7 +139,7 @@ static BOOL map_dword(TALLOC_CTX *ctx, ADS_MODLIST *mods, /* map a boolean REG_BINARY to an ldap mod */ -static BOOL map_bool(TALLOC_CTX *ctx, ADS_MODLIST *mods, +static bool map_bool(TALLOC_CTX *ctx, ADS_MODLIST *mods, const REGISTRY_VALUE *value) { char *str_value; @@ -159,7 +159,7 @@ static BOOL map_bool(TALLOC_CTX *ctx, ADS_MODLIST *mods, /* map a REG_MULTI_SZ to an ldap mod */ -static BOOL map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, +static bool map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, const REGISTRY_VALUE *value) { char **str_values = NULL; @@ -198,7 +198,7 @@ static BOOL map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, struct valmap_to_ads { const char *valname; - BOOL (*fn)(TALLOC_CTX *, ADS_MODLIST *, const REGISTRY_VALUE *); + bool (*fn)(TALLOC_CTX *, ADS_MODLIST *, const REGISTRY_VALUE *); }; /* @@ -347,7 +347,7 @@ WERROR get_remote_printer_publishing_data(struct rpc_pipe_client *cli, return result; } -BOOL get_local_printer_publishing_data(TALLOC_CTX *mem_ctx, +bool get_local_printer_publishing_data(TALLOC_CTX *mem_ctx, ADS_MODLIST *mods, NT_PRINTER_DATA *data) { -- cgit From 2a2188591b5ed922d09dc723adcf10f8b8f5e5a0 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 19 Apr 2008 21:56:43 +0200 Subject: Add "desthost" to rpc_pipe_client This reduces the dependency on cli_state (This used to be commit 783afab9c891dd7bcb78895b2a639b6f3a0edf5b) --- source3/libads/ldap_printer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 05fbc071d8..e2396ce4cf 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -288,7 +288,7 @@ WERROR get_remote_printer_publishing_data(struct rpc_pipe_client *cli, uint32 i; POLICY_HND pol; - asprintf(&servername, "\\\\%s", cli->cli->desthost); + asprintf(&servername, "\\\\%s", cli->desthost); asprintf(&printername, "%s\\%s", servername, printer); if (!servername || !printername) { DEBUG(3, ("Insufficient memory\n")); -- cgit From 4c857010e7113d99028cf8d7fac5e5b95c400fb3 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 19 Apr 2008 22:05:13 +0200 Subject: Fix two "ignoring asprintf result" warnings (This used to be commit 1d261e78b38e8080ca7122037d33c8ef913a4558) --- source3/libads/ldap_printer.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index e2396ce4cf..440f979781 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -288,9 +288,8 @@ WERROR get_remote_printer_publishing_data(struct rpc_pipe_client *cli, uint32 i; POLICY_HND pol; - asprintf(&servername, "\\\\%s", cli->desthost); - asprintf(&printername, "%s\\%s", servername, printer); - if (!servername || !printername) { + if ((asprintf(&servername, "\\\\%s", cli->desthost) == -1) + || (asprintf(&printername, "%s\\%s", servername, printer) == -1)) { DEBUG(3, ("Insufficient memory\n")); return WERR_NOMEM; } -- cgit From cf2442bdcb68d75582da98ba15da8928c37fb058 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 20 Apr 2008 00:01:52 +0200 Subject: Use rpc_pipe_client->user_name instead of rpc_pipe_client->cli->user_name Also make sure that rpc_pipe_client->user_name is always talloced. (This used to be commit 3f6c5b99664a75a6f490ee3b6980b89cacf7f579) --- source3/libads/ldap_printer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 440f979781..6682ec24d0 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -296,7 +296,7 @@ WERROR get_remote_printer_publishing_data(struct rpc_pipe_client *cli, result = rpccli_spoolss_open_printer_ex(cli, mem_ctx, printername, "", MAXIMUM_ALLOWED_ACCESS, - servername, cli->cli->user_name, &pol); + servername, cli->user_name, &pol); if (!W_ERROR_IS_OK(result)) { DEBUG(3, ("Unable to open printer %s, error is %s.\n", printername, dos_errstr(result))); -- cgit From 862d7e32b90f7020d46e025de918f6338f40441b Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 21 Apr 2008 22:27:29 +0200 Subject: Move user/domain from rpc_pipe_client to cli_pipe_auth_data (This used to be commit 42de50d2cd43e760d776694f7b5f003ba51d7f84) --- source3/libads/ldap_printer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 6682ec24d0..41f23b06a7 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -296,7 +296,8 @@ WERROR get_remote_printer_publishing_data(struct rpc_pipe_client *cli, result = rpccli_spoolss_open_printer_ex(cli, mem_ctx, printername, "", MAXIMUM_ALLOWED_ACCESS, - servername, cli->user_name, &pol); + servername, cli->auth->user_name, + &pol); if (!W_ERROR_IS_OK(result)) { DEBUG(3, ("Unable to open printer %s, error is %s.\n", printername, dos_errstr(result))); -- cgit From fb37f156009611af0dd454a0fb0829a09cd638ac Mon Sep 17 00:00:00 2001 From: Tim Prouty Date: Tue, 29 Apr 2008 14:36:24 -0700 Subject: Cleanup size_t return values in callers of convert_string_allocate This patch is the second iteration of an inside-out conversion to cleanup functions in charcnv.c returning size_t == -1 to indicate failure. (This used to be commit 6b189dabc562d86dcaa685419d0cb6ea276f100d) --- source3/libads/ldap_printer.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'source3/libads/ldap_printer.c') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 41f23b06a7..9935e2311a 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -103,17 +103,23 @@ static bool map_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, const REGISTRY_VALUE *value) { char *str_value = NULL; + size_t converted_size; ADS_STATUS status; if (value->type != REG_SZ) - return False; + return false; if (value->size && *((smb_ucs2_t *) value->data_p)) { - pull_ucs2_talloc(ctx, &str_value, (const smb_ucs2_t *) value->data_p); + if (!pull_ucs2_talloc(ctx, &str_value, + (const smb_ucs2_t *) value->data_p, + &converted_size)) + { + return false; + } status = ads_mod_str(ctx, mods, value->valuename, str_value); return ADS_ERR_OK(status); } - return True; + return true; } @@ -163,6 +169,7 @@ static bool map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, const REGISTRY_VALUE *value) { char **str_values = NULL; + size_t converted_size; smb_ucs2_t *cur_str = (smb_ucs2_t *) value->data_p; uint32 size = 0, num_vals = 0, i=0; ADS_STATUS status; @@ -185,9 +192,11 @@ static bool map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, (num_vals + 1) * sizeof(char *)); cur_str = (smb_ucs2_t *) value->data_p; - for (i=0; i < num_vals; i++) + for (i=0; i < num_vals; i++) { cur_str += pull_ucs2_talloc(ctx, &str_values[i], - cur_str); + cur_str, &converted_size) ? + converted_size : (size_t)-1; + } status = ads_mod_strlist(ctx, mods, value->valuename, (const char **) str_values); -- cgit