summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim McDonough <jmcd@samba.org>2002-11-18 19:59:58 +0000
committerJim McDonough <jmcd@samba.org>2002-11-18 19:59:58 +0000
commite4201bec142b6666a45c38532f1393270b6b0d48 (patch)
treeced55d7c45565fb89c431c53bbb9a6ab1535d89f
parent4d12794bc15e7983372476baa8b21aa71eb69a98 (diff)
downloadsamba-e4201bec142b6666a45c38532f1393270b6b0d48.tar.gz
samba-e4201bec142b6666a45c38532f1393270b6b0d48.tar.bz2
samba-e4201bec142b6666a45c38532f1393270b6b0d48.zip
Next step of printer publishing.
net ads printer publish <printername> [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)
-rw-r--r--source3/include/ads.h57
-rw-r--r--source3/libads/ldap_printer.c348
2 files changed, 243 insertions, 162 deletions
diff --git a/source3/include/ads.h b/source3/include/ads.h
index 88a90229b1..c8801789ae 100644
--- a/source3/include/ads.h
+++ b/source3/include/ads.h
@@ -38,61 +38,6 @@ typedef struct {
} config;
} ADS_STRUCT;
-typedef struct {
- char *printerName;
- char *serverName;
- char *shortServerName;
- char *versionNumber;
- char *uNCName;
- char **description;
- char *assetNumber;
- char *bytesPerMinute;
- char *defaultPriority;
- char *driverName;
- char *driverVersion;
- char *location;
- char *operatingSystem;
- char *operatingSystemHotfix;
- char *operatingSystemServicePack;
- char *operatingSystemVersion;
- char *physicalLocationObject;
- char **portName;
- char *printAttributes;
- char **printBinNames;
- char *printCollate;
- char *printColor;
- char *printDuplexSupported;
- char *printEndTime;
- char *printFOrmName;
- char *printKeepPrintedJobs;
- char **printLanguage;
- char *printMACAddress;
- char *printMaxCopies;
- char *printMaxResolutionSupported;
- char *printMaxXExtent;
- char *printMaxYExtent;
- char **printMediaReady;
- char **printMediaSupported;
- char *printMemory;
- char *printMinXExtent;
- char *printMinYExtent;
- char *printNetworkAddress;
- char *printNotify;
- char *printNumberUp;
- char **printOrientationsSupported;
- char *printOwner;
- char *printPagesPerMinute;
- char *printRate;
- char *printRateUnit;
- char *printSeparatorFile;
- char **printShareName;
- char *printSpooling;
- char *printStaplingSupported;
- char *printStartTime;
- char *printStatus;
- char *priority;
-} ADS_PRINTER_ENTRY;
-
/* there are 4 possible types of errors the ads subsystem can produce */
enum ads_error_type {ADS_ERROR_KRB5, ADS_ERROR_GSS,
ADS_ERROR_LDAP, ADS_ERROR_SYSTEM, ADS_ERROR_NT};
@@ -122,7 +67,7 @@ typedef void **ADS_MODLIST;
#define ADS_ERROR_GSS(rc, minor) ads_build_error(ADS_ERROR_GSS, rc, minor)
#define ADS_ERROR_NT(rc) ads_build_nt_error(ADS_ERROR_NT,rc)
-#define ADS_ERR_OK(status) ((status.error_type == ADS_ERROR_NT) ? NT_STATUS_IS_OK(status.err.nt_status):(status.err.rc == 0))
+#define ADS_ERR_OK(status) ({ADS_STATUS errokstat = status;(errokstat.error_type == ADS_ERROR_NT) ? NT_STATUS_IS_OK(errokstat.err.nt_status):(errokstat.err.rc == 0);})
#define ADS_SUCCESS ADS_ERROR(0)
/* time between reconnect attempts */
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
+