s4:objectclass LDB module - we should not simply ignore additional "objectClass"...
[Samba/gebeck_regimport.git] / source3 / printing / pcap.c
blob1b8f46d8e719e73170dea443880c394100d9cf4b
1 /*
2 Unix SMB/CIFS implementation.
3 printcap parsing
4 Copyright (C) Karl Auer 1993-1998
6 Re-working by Martin Kiff, 1994
8 Re-written again by Andrew Tridgell
10 Modified for SVID support by Norm Jacobs, 1997
12 Modified for CUPS support by Michael Sweet, 1999
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 * Modified to call SVID/XPG4 support if printcap name is set to "lpstat"
30 * in smb.conf under Solaris.
32 * Modified to call CUPS support if printcap name is set to "cups"
33 * in smb.conf.
35 * Modified to call iPrint support if printcap name is set to "iprint"
36 * in smb.conf.
39 #include "includes.h"
40 #include "printing/pcap.h"
41 #include "printer_list.h"
43 struct pcap_cache {
44 char *name;
45 char *comment;
46 struct pcap_cache *next;
49 bool pcap_cache_add_specific(struct pcap_cache **ppcache, const char *name, const char *comment)
51 struct pcap_cache *p;
53 if (name == NULL || ((p = SMB_MALLOC_P(struct pcap_cache)) == NULL))
54 return false;
56 p->name = SMB_STRDUP(name);
57 p->comment = (comment && *comment) ? SMB_STRDUP(comment) : NULL;
59 DEBUG(11,("pcap_cache_add_specific: Adding name %s info %s\n",
60 p->name, p->comment ? p->comment : ""));
62 p->next = *ppcache;
63 *ppcache = p;
65 return true;
68 void pcap_cache_destroy_specific(struct pcap_cache **pp_cache)
70 struct pcap_cache *p, *next;
72 for (p = *pp_cache; p != NULL; p = next) {
73 next = p->next;
75 SAFE_FREE(p->name);
76 SAFE_FREE(p->comment);
77 SAFE_FREE(p);
79 *pp_cache = NULL;
82 bool pcap_cache_add(const char *name, const char *comment)
84 NTSTATUS status;
85 time_t t = time_mono(NULL);
87 status = printer_list_set_printer(talloc_tos(), name, comment, t);
88 return NT_STATUS_IS_OK(status);
91 bool pcap_cache_loaded(void)
93 NTSTATUS status;
94 time_t last;
96 status = printer_list_get_last_refresh(&last);
97 return NT_STATUS_IS_OK(status);
100 void pcap_cache_replace(const struct pcap_cache *pcache)
102 const struct pcap_cache *p;
104 for (p = pcache; p; p = p->next) {
105 pcap_cache_add(p->name, p->comment);
109 void pcap_cache_reload(struct tevent_context *ev,
110 struct messaging_context *msg_ctx)
112 const char *pcap_name = lp_printcapname();
113 bool pcap_reloaded = False;
114 NTSTATUS status;
116 DEBUG(3, ("reloading printcap cache\n"));
118 /* only go looking if no printcap name supplied */
119 if (pcap_name == NULL || *pcap_name == 0) {
120 DEBUG(0, ("No printcap file name configured!\n"));
121 return;
124 if (!printer_list_need_refresh()) {
125 /* has been just refeshed, skip */
126 DEBUG(5, ("Refresh just happend, skipping.\n"));
127 return;
130 status = printer_list_mark_reload();
131 if (!NT_STATUS_IS_OK(status)) {
132 DEBUG(0, ("Failed to mark printer list for reload!\n"));
133 return;
136 #ifdef HAVE_CUPS
137 if (strequal(pcap_name, "cups")) {
138 pcap_reloaded = cups_cache_reload(ev, msg_ctx);
139 goto done;
141 #endif
143 #ifdef HAVE_IPRINT
144 if (strequal(pcap_name, "iprint")) {
145 pcap_reloaded = iprint_cache_reload();
146 goto done;
148 #endif
150 #if defined(SYSV) || defined(HPUX)
151 if (strequal(pcap_name, "lpstat")) {
152 pcap_reloaded = sysv_cache_reload();
153 goto done;
155 #endif
157 #ifdef AIX
158 if (strstr_m(pcap_name, "/qconfig") != NULL) {
159 pcap_reloaded = aix_cache_reload();
160 goto done;
162 #endif
164 pcap_reloaded = std_pcap_cache_reload(pcap_name);
166 done:
167 DEBUG(3, ("reload status: %s\n", (pcap_reloaded) ? "ok" : "error"));
169 if (pcap_reloaded) {
170 /* cleanup old entries only if the operation was successful,
171 * otherwise keep around the old entries until we can
172 * successfuly reaload */
173 status = printer_list_clean_old();
174 if (!NT_STATUS_IS_OK(status)) {
175 DEBUG(0, ("Failed to cleanup printer list!\n"));
179 return;
183 bool pcap_printername_ok(const char *printername)
185 NTSTATUS status;
187 status = printer_list_get_printer(talloc_tos(), printername, NULL, 0);
188 return NT_STATUS_IS_OK(status);
191 /***************************************************************************
192 run a function on each printer name in the printcap file.
193 ***************************************************************************/
195 void pcap_printer_fn_specific(const struct pcap_cache *pc,
196 void (*fn)(const char *, const char *, void *),
197 void *pdata)
199 const struct pcap_cache *p;
201 for (p = pc; p != NULL; p = p->next)
202 fn(p->name, p->comment, pdata);
204 return;
207 void pcap_printer_fn(void (*fn)(const char *, const char *, void *), void *pdata)
209 NTSTATUS status;
211 status = printer_list_run_fn(fn, pdata);
212 if (!NT_STATUS_IS_OK(status)) {
213 DEBUG(3, ("Failed to run fn for all printers!\n"));
215 return;