Fix CID 524 - reference before allocation fail null check.
[Samba/gebeck_regimport.git] / source3 / printing / print_aix.c
blobfd85ca08336ba8e7f04a2172a7ec0b073e8dc462
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"
29 #ifdef AIX
30 bool aix_cache_reload(void)
32 int iEtat;
33 XFILE *pfile;
34 char *line = NULL, *p;
35 char *name = NULL;
36 TALLOC_CTX *ctx = talloc_init("aix_cache_reload");
38 if (!ctx) {
39 return false;
42 DEBUG(5, ("reloading aix printcap cache\n"));
44 if ((pfile = x_fopen(lp_printcapname(), O_RDONLY, 0)) == NULL) {
45 DEBUG(0,( "Unable to open qconfig file %s for read!\n", lp_printcapname()));
46 TALLOC_FREE(ctx);
47 return false;
50 iEtat = 0;
51 /* scan qconfig file for searching <printername>: */
52 for (;(line = fgets_slash(NULL, 1024, pfile)); safe_free(line)) {
53 if (*line == '*' || *line == 0)
54 continue;
56 switch (iEtat) {
57 case 0: /* locate an entry */
58 if (*line == '\t' || *line == ' ')
59 continue;
61 if ((p = strchr_m(line, ':'))) {
62 *p = '\0';
63 p = strtok(line, ":");
64 if (strcmp(p, "bsh") != 0) {
65 name = talloc_strdup(ctx, p);
66 if (!name) {
67 safe_free(line);
68 x_fclose(pfile);
69 TALLOC_FREE(ctx);
70 return false;
72 iEtat = 1;
73 continue;
76 break;
78 case 1: /* scanning device stanza */
79 if (*line == '*' || *line == 0)
80 continue;
82 if (*line != '\t' && *line != ' ') {
83 /* name is found without stanza device */
84 /* probably a good printer ??? */
85 iEtat = 0;
86 if (!pcap_cache_add(name, NULL)) {
87 safe_free(line);
88 x_fclose(pfile);
89 TALLOC_FREE(ctx);
90 return false;
92 continue;
95 if (strstr_m(line, "backend")) {
96 /* it's a device, not a virtual printer */
97 iEtat = 0;
98 } else if (strstr_m(line, "device")) {
99 /* it's a good virtual printer */
100 iEtat = 0;
101 if (!pcap_cache_add(name, NULL)) {
102 safe_free(line);
103 x_fclose(pfile);
104 TALLOC_FREE(ctx);
105 return false;
107 continue;
109 break;
113 x_fclose(pfile);
114 TALLOC_FREE(ctx);
115 return true;
118 #else
119 /* this keeps fussy compilers happy */
120 void print_aix_dummy(void);
121 void print_aix_dummy(void) {}
122 #endif /* AIX */