2 Unix SMB/CIFS implementation.
3 ads (active directory) printer utility library
4 Copyright (C) Jim McDonough 2002
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 modify an entire printer entry in the directory
28 ADS_STATUS ads_mod_printer_entry(ADS_STRUCT *ads, char *prt_dn,
29 const ADS_PRINTER_ENTRY *prt)
34 /* allocate the list */
35 mods = ads_mod_list_start(sizeof(prt) / sizeof(char *));
37 /* add the attributes to the list - required ones first */
38 ads_mod_repl(mods, "printerName", prt->printerName);
39 ads_mod_repl(mods, "serverName", prt->serverName);
40 ads_mod_repl(mods, "shortServerName", prt->shortServerName);
41 ads_mod_repl(mods, "uNCName", prt->uNCName);
42 ads_mod_repl(mods, "versionNumber", prt->versionNumber);
43 /* now the optional ones */
44 ads_mod_repl_list(mods, "description", prt->description);
45 ads_mod_repl(mods, "driverName", prt->driverName);
46 ads_mod_repl(mods, "location", prt->location);
47 ads_mod_repl_list(mods, "portName", prt->portName);
48 ads_mod_repl(mods, "printStartTime", prt->printStartTime);
49 ads_mod_repl(mods, "printEndTime", prt->printEndTime);
50 ads_mod_repl_list(mods, "printBinNames", prt->printBinNames);
54 /* do the ldap modify */
55 status = ads_gen_mod(ads, prt_dn, mods);
57 /* free mod list, mods, and values */
58 ads_mod_list_end(mods);
65 add a printer to the directory
67 static ADS_STATUS ads_add_printer_entry(ADS_STRUCT *ads, char *prt_dn,
68 const ADS_PRINTER_ENTRY *prt)
72 /* These are the fields a printQueue must contain */
73 status = ads_gen_add(ads, prt_dn,
74 "uNCName", prt->uNCName, NULL,
75 "versionNumber", prt->versionNumber, NULL,
76 "serverName", prt->serverName, NULL,
77 "shortServerName", prt->shortServerName, NULL,
78 "printerName", prt->printerName, NULL,
79 "objectClass", "printQueue", NULL,
86 publish a printer in the ADS
89 ADS_STATUS ads_add_printer(ADS_STRUCT *ads, const ADS_PRINTER_ENTRY *prt)
93 char *host_dn, *prt_dn;
94 const char *attrs[] = {"*", "nTSecurityDescriptor", NULL};
96 status = ads_find_machine_acct(ads, (void **)&res,
97 prt->shortServerName);
98 if (!ADS_ERR_OK(status)) {
99 DEBUG(1, ("ads_add_printer: cannot find host %s in ads\n",
100 prt->shortServerName));
103 host_dn = ldap_get_dn(ads->ld, res);
104 ads_msgfree(ads, res);
106 /* printer dn is cn=server-printer followed by host dn */
107 asprintf(&prt_dn, "cn=%s-%s,%s", prt->shortServerName,
108 prt->printerName, host_dn);
110 status = ads_search_dn(ads, res, prt_dn, attrs);
112 if (ADS_ERR_OK(status) && ads_count_replies(ads, res)) {
113 DEBUG(1, ("ads_add_printer: printer %s already exists\n",
115 /* nothing to do, just free results */
116 ads_msgfree(ads, res);
118 ads_msgfree(ads, res);
119 status = ads_add_printer_entry(ads, prt_dn, prt);
120 if (!ADS_ERR_OK(status)) {
121 DEBUG(0, ("ads_add_printer: ads_add_printer_entry failed\n"));
126 status = ads_mod_printer_entry(ads, prt_dn, prt);