s3:smbd: use lp_smbd_search_ask_sharemode()
[Samba.git] / source3 / printing / print_aix.c
blobd3836a435686758cd15950b93520f9b9ea4ef6d8
1 /*
2 AIX-specific printcap loading
3 Copyright (C) Jean-Pierre.Boulard@univ-rennes1.fr 1996
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * This module implements AIX-specific printcap loading. Most of the code
21 * here was originally provided by Jean-Pierre.Boulard@univ-rennes1.fr in
22 * the Samba 1.9.14 release, and was formerly contained in pcap.c. It has
23 * been moved here and condensed as part of a larger effort to clean up and
24 * simplify the printcap code. -- Rob Foehl, 2004/12/06
27 #include "includes.h"
28 #include "system/filesys.h"
29 #include "printing/pcap.h"
31 #ifdef AIX
32 bool aix_cache_reload(struct pcap_cache **_pcache)
34 int iEtat;
35 FILE *pfile;
36 char *line = NULL, *p;
37 char *name = NULL;
38 struct pcap_cache *pcache = NULL;
39 TALLOC_CTX *ctx = talloc_init("aix_cache_reload");
41 if (!ctx) {
42 return false;
45 DEBUG(5, ("reloading aix printcap cache\n"));
47 if ((pfile = fopen(lp_printcapname(), "r")) == NULL) {
48 DEBUG(0,( "Unable to open qconfig file %s for read!\n", lp_printcapname()));
49 TALLOC_FREE(ctx);
50 return false;
53 iEtat = 0;
54 /* scan qconfig file for searching <printername>: */
55 while (line = fgets_slash(ctx, NULL, 1024, pfile)) {
56 bool ok;
58 if (*line == '*' || *line == 0) {
59 TALLOC_FREE(line);
60 continue;
63 switch (iEtat) {
64 case 0: /* locate an entry */
65 if (*line == '\t' || *line == ' ') {
66 TALLOC_FREE(line);
67 continue;
70 if ((p = strchr_m(line, ':'))) {
71 char *saveptr;
72 *p = '\0';
73 p = strtok_r(line, ":", &saveptr);
74 if (strcmp(p, "bsh") != 0) {
75 name = talloc_strdup(ctx, p);
76 if (!name) {
77 pcap_cache_destroy_specific(&pcache);
78 TALLOC_FREE(line);
79 fclose(pfile);
80 TALLOC_FREE(ctx);
81 return false;
83 iEtat = 1;
84 continue;
87 break;
89 case 1: /* scanning device stanza */
90 if (*line == '*' || *line == 0)
91 continue;
93 if (*line != '\t' && *line != ' ') {
94 /* name is found without stanza device */
95 /* probably a good printer ??? */
96 iEtat = 0;
97 ok = pcap_cache_add_specific(&pcache,
98 name, NULL, NULL);
99 if (!ok) {
100 pcap_cache_destroy_specific(&pcache);
101 TALLOC_FREE(line);
102 fclose(pfile);
103 TALLOC_FREE(ctx);
104 return false;
106 continue;
109 if (strstr_m(line, "backend")) {
110 /* it's a device, not a virtual printer */
111 iEtat = 0;
112 } else if (strstr_m(line, "device")) {
113 /* it's a good virtual printer */
114 iEtat = 0;
115 ok = pcap_cache_add_specific(&pcache,
116 name, NULL, NULL);
117 if (!ok) {
118 pcap_cache_destroy_specific(&pcache);
119 SAFE_FREE(line);
120 fclose(pfile);
121 TALLOC_FREE(ctx);
122 return false;
124 continue;
126 break;
130 *_pcache = pcache;
131 fclose(pfile);
132 TALLOC_FREE(ctx);
133 return true;
136 #else
137 /* this keeps fussy compilers happy */
138 void print_aix_dummy(void);
139 void print_aix_dummy(void) {}
140 #endif /* AIX */