s3-param: Rename loadparm_s3_context -> loadparm_s3_helpers
[kai/samba.git] / source3 / printing / print_aix.c
index 6ed3510ee41e2dd6314db10e24f72d95432e8fb0..23d9a86fe37a7624e723e4f509ac78e9b774a7b2 100644 (file)
@@ -4,7 +4,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -13,8 +13,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /*
  */
 
 #include "includes.h"
+#include "system/filesys.h"
+#include "printing/pcap.h"
 
 #ifdef AIX
-BOOL aix_cache_reload(void)
+bool aix_cache_reload(void)
 {
        int iEtat;
        XFILE *pfile;
        char *line = NULL, *p;
-       pstring name, comment;
+       char *name = NULL;
+       TALLOC_CTX *ctx = talloc_init("aix_cache_reload");
 
-       *name = 0;
-       *comment = 0;
+       if (!ctx) {
+               return false;
+       }
 
        DEBUG(5, ("reloading aix printcap cache\n"));
 
        if ((pfile = x_fopen(lp_printcapname(), O_RDONLY, 0)) == NULL) {
                DEBUG(0,( "Unable to open qconfig file %s for read!\n", lp_printcapname()));
-               return False;
+               TALLOC_FREE(ctx);
+               return false;
        }
 
        iEtat = 0;
        /* scan qconfig file for searching <printername>:       */
-       for (;(line = fgets_slash(NULL, sizeof(pstring), pfile)); safe_free(line)) {
+       for (;(line = fgets_slash(NULL, 1024, pfile)); free(line)) {
                if (*line == '*' || *line == 0)
                        continue;
 
@@ -57,10 +61,17 @@ BOOL aix_cache_reload(void)
                                continue;
 
                        if ((p = strchr_m(line, ':'))) {
+                               char *saveptr;
                                *p = '\0';
-                               p = strtok(line, ":");
+                               p = strtok_r(line, ":", &saveptr);
                                if (strcmp(p, "bsh") != 0) {
-                                       pstrcpy(name, p);
+                                       name = talloc_strdup(ctx, p);
+                                       if (!name) {
+                                               SAFE_FREE(line);
+                                               x_fclose(pfile);
+                                               TALLOC_FREE(ctx);
+                                               return false;
+                                       }
                                        iEtat = 1;
                                        continue;
                                }
@@ -75,24 +86,26 @@ BOOL aix_cache_reload(void)
                                /* name is found without stanza device  */
                                /* probably a good printer ???          */
                                iEtat = 0;
-                               if (!pcap_cache_add(name, NULL)) {
-                                       safe_free(line);
+                               if (!pcap_cache_add(name, NULL, NULL)) {
+                                       SAFE_FREE(line);
                                        x_fclose(pfile);
-                                       return False;
+                                       TALLOC_FREE(ctx);
+                                       return false;
                                }
                                continue;
                        }
-                       
+
                        if (strstr_m(line, "backend")) {
                                /* it's a device, not a virtual printer */
                                iEtat = 0;
                        } else if (strstr_m(line, "device")) {
                                /* it's a good virtual printer */
                                iEtat = 0;
-                               if (!pcap_cache_add(name, NULL)) {
-                                       safe_free(line);
+                               if (!pcap_cache_add(name, NULL, NULL)) {
+                                       SAFE_FREE(line);
                                        x_fclose(pfile);
-                                       return False;
+                                       TALLOC_FREE(ctx);
+                                       return false;
                                }
                                continue;
                        }
@@ -101,7 +114,8 @@ BOOL aix_cache_reload(void)
        }
 
        x_fclose(pfile);
-       return True;
+       TALLOC_FREE(ctx);
+       return true;
 }
 
 #else