s3-param: Rename loadparm_s3_context -> loadparm_s3_helpers
[kai/samba.git] / source3 / printing / print_aix.c
index c7150acd95be21ba43c513458b07fff8973f61fd..23d9a86fe37a7624e723e4f509ac78e9b774a7b2 100644 (file)
@@ -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