ae76229d773eb9717a6096fa9513f59d062a3228
[jpeach/samba.git] / source / printing / load.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 3.0
4    load printer lists
5    Copyright (C) Andrew Tridgell 1992-2000
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23
24
25 /***************************************************************************
26 auto-load printer services
27 ***************************************************************************/
28 void add_all_printers(void)
29 {
30         int printers = lp_servicenumber(PRINTERS_NAME);
31
32         if (printers < 0) return;
33
34         pcap_printer_fn(lp_add_one_printer);
35 }
36
37 /***************************************************************************
38 auto-load some homes and printer services
39 ***************************************************************************/
40 static void add_auto_printers(void)
41 {
42         char *p;
43         int printers;
44         char *str = strdup(lp_auto_services());
45
46         if (!str) return;
47
48         printers = lp_servicenumber(PRINTERS_NAME);
49
50         if (printers < 0) {
51         SAFE_FREE(str);
52         return;
53     }
54         
55         for (p=strtok(str,LIST_SEP);p;p=strtok(NULL,LIST_SEP)) {
56                 if (lp_servicenumber(p) >= 0) continue;
57                 
58                 if (pcap_printername_ok(p,NULL)) {
59                         lp_add_printer(p,printers);
60                 }
61         }
62
63     SAFE_FREE(str);
64 }
65
66 /***************************************************************************
67 load automatic printer services
68 ***************************************************************************/
69 void load_printers(void)
70 {
71         add_auto_printers();
72         if (lp_load_printers())
73                 add_all_printers();
74 }