Use common util_file code.
authorJelmer Vernooij <jelmer@samba.org>
Sun, 12 Oct 2008 15:34:43 +0000 (17:34 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sun, 12 Oct 2008 15:34:43 +0000 (17:34 +0200)
26 files changed:
lib/util/params.c
lib/util/util.h
lib/util/util_file.c
lib/util/util_tdb.c
source3/Makefile.in
source3/include/proto.h
source3/intl/lang_tdb.c
source3/lib/sysquotas.c
source3/lib/util_file.c
source3/libgpo/gpo_ini.c
source3/param/loadparm.c
source3/param/params.c
source3/passdb/machine_sid.c
source3/printing/nt_printing.c
source3/printing/print_generic.c
source3/printing/print_svid.c
source3/rpc_server/srv_spoolss_nt.c
source3/smbd/dfree.c
source3/smbd/lanman.c
source3/smbd/map_username.c
source3/utils/net_usershare.c
source4/auth/credentials/credentials_files.c
source4/lib/registry/dir.c
source4/lib/registry/regf.c
source4/lib/tls/tls.c
source4/torture/gentest.c

index 3a9e2b95051123fd7315072999b9e234a5cfeb5c..c03edec272cdfbc4aefb673358be754e82b38ffd 100644 (file)
@@ -510,7 +510,7 @@ static myFILE *OpenConfFile( const char *FileName )
   ret = talloc(talloc_autofree_context(), myFILE);
   if (!ret) return NULL;
 
-  ret->buf = file_load(FileName, &ret->size, ret);
+  ret->buf = file_load(FileName, &ret->size, 0, ret);
   if( NULL == ret->buf )
     {
     DEBUG( 1,
index 5cecad7350187ed5bdb1d7163453824c5d8d60b1..720aa537a7dc34ea2b95c4e55dc0b8f976f35a75 100644 (file)
@@ -522,12 +522,12 @@ _PUBLIC_ char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint);
 /**
 load a file into memory from a fd.
 **/
-_PUBLIC_ char *fd_load(int fd, size_t *size, TALLOC_CTX *mem_ctx);
+_PUBLIC_ char *fd_load(int fd, size_t *size, size_t maxsize, TALLOC_CTX *mem_ctx);
 
 /**
 load a file into memory
 **/
-_PUBLIC_ char *file_load(const char *fname, size_t *size, TALLOC_CTX *mem_ctx);
+_PUBLIC_ char *file_load(const char *fname, size_t *size, size_t maxsize, TALLOC_CTX *mem_ctx);
 
 /**
 mmap (if possible) or read a file
@@ -538,14 +538,14 @@ _PUBLIC_ void *map_file(const char *fname, size_t size);
 load a file into memory and return an array of pointers to lines in the file
 must be freed with talloc_free(). 
 **/
-_PUBLIC_ char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX *mem_ctx);
+_PUBLIC_ char **file_lines_load(const char *fname, int *numlines, size_t maxsize, TALLOC_CTX *mem_ctx);
 
 /**
 load a fd into memory and return an array of pointers to lines in the file
 must be freed with talloc_free(). If convert is true calls unix_to_dos on
 the list.
 **/
-_PUBLIC_ char **fd_lines_load(int fd, int *numlines, TALLOC_CTX *mem_ctx);
+_PUBLIC_ char **fd_lines_load(int fd, int *numlines, size_t maxsize, TALLOC_CTX *mem_ctx);
 
 /**
 take a list of lines and modify them to produce a list where \ continues
index c3e22196c0cb69cc95fb6a1b86936e4042dc1d99..176ff75e02610f59fb7829ca7ded00462d0ee19e 100644 (file)
 #include "includes.h"
 #include "system/shmem.h"
 #include "system/filesys.h"
+#if _SAMBA_BUILD_ == 3
+#undef malloc
+#undef realloc
+#define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count, false)
+#endif
 
 /**
  * @file
@@ -160,23 +165,30 @@ _PUBLIC_ char *afdgets(int fd, TALLOC_CTX *mem_ctx, size_t hint)
 /**
 load a file into memory from a fd.
 **/
-_PUBLIC_ char *fd_load(int fd, size_t *size, TALLOC_CTX *mem_ctx)
+_PUBLIC_ char *fd_load(int fd, size_t *psize, size_t maxsize, TALLOC_CTX *mem_ctx)
 {
        struct stat sbuf;
        char *p;
+       size_t size;
 
        if (fstat(fd, &sbuf) != 0) return NULL;
 
-       p = (char *)talloc_size(mem_ctx, sbuf.st_size+1);
+       size = sbuf.st_size;
+
+       if (maxsize) {
+               size = MIN(size, maxsize);
+       }
+
+       p = (char *)talloc_size(mem_ctx, size+1);
        if (!p) return NULL;
 
-       if (read(fd, p, sbuf.st_size) != sbuf.st_size) {
+       if (read(fd, p, size) != size) {
                talloc_free(p);
                return NULL;
        }
-       p[sbuf.st_size] = 0;
+       p[size] = 0;
 
-       if (size) *size = sbuf.st_size;
+       if (psize) *psize = size;
 
        return p;
 }
@@ -184,7 +196,7 @@ _PUBLIC_ char *fd_load(int fd, size_t *size, TALLOC_CTX *mem_ctx)
 /**
 load a file into memory
 **/
-_PUBLIC_ char *file_load(const char *fname, size_t *size, TALLOC_CTX *mem_ctx)
+_PUBLIC_ char *file_load(const char *fname, size_t *size, size_t maxsize, TALLOC_CTX *mem_ctx)
 {
        int fd;
        char *p;
@@ -194,7 +206,7 @@ _PUBLIC_ char *file_load(const char *fname, size_t *size, TALLOC_CTX *mem_ctx)
        fd = open(fname,O_RDONLY);
        if (fd == -1) return NULL;
 
-       p = fd_load(fd, size, mem_ctx);
+       p = fd_load(fd, size, maxsize, mem_ctx);
 
        close(fd);
 
@@ -224,7 +236,7 @@ _PUBLIC_ void *map_file(const char *fname, size_t size)
        }
 #endif
        if (!p) {
-               p = file_load(fname, &s2, talloc_autofree_context());
+               p = file_load(fname, &s2, 0, talloc_autofree_context());
                if (!p) return NULL;
                if (s2 != size) {
                        DEBUG(1,("incorrect size for %s - got %d expected %d\n",
@@ -237,12 +249,31 @@ _PUBLIC_ void *map_file(const char *fname, size_t size)
        return p;
 }
 
+/**
+ unmap or free memory
+**/
+
+bool unmap_file(void *start, size_t size)
+{
+#ifdef HAVE_MMAP
+       if (munmap( start, size ) != 0) {
+               DEBUG( 1, ("map_file: Failed to unmap address %p "
+                       "of size %u - %s\n", 
+                       start, (unsigned int)size, strerror(errno) ));
+               return false;
+       }
+       return true;
+#else
+       talloc_free(start);
+       return true;
+#endif
+}
 
 /**
 parse a buffer into lines
 'p' will be freed on error, and otherwise will be made a child of the returned array
 **/
-static char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX *mem_ctx)
+char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX *mem_ctx)
 {
        int i;
        char *s, **ret;
@@ -288,12 +319,12 @@ static char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX *
 load a file into memory and return an array of pointers to lines in the file
 must be freed with talloc_free(). 
 **/
-_PUBLIC_ char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX *mem_ctx)
+_PUBLIC_ char **file_lines_load(const char *fname, int *numlines, size_t maxsize, TALLOC_CTX *mem_ctx)
 {
        char *p;
        size_t size;
 
-       p = file_load(fname, &size, mem_ctx);
+       p = file_load(fname, &size, maxsize, mem_ctx);
        if (!p) return NULL;
 
        return file_lines_parse(p, size, numlines, mem_ctx);
@@ -304,12 +335,12 @@ load a fd into memory and return an array of pointers to lines in the file
 must be freed with talloc_free(). If convert is true calls unix_to_dos on
 the list.
 **/
-_PUBLIC_ char **fd_lines_load(int fd, int *numlines, TALLOC_CTX *mem_ctx)
+_PUBLIC_ char **fd_lines_load(int fd, int *numlines, size_t maxsize, TALLOC_CTX *mem_ctx)
 {
        char *p;
        size_t size;
 
-       p = fd_load(fd, &size, mem_ctx);
+       p = fd_load(fd, &size, maxsize, mem_ctx);
        if (!p) return NULL;
 
        return file_lines_parse(p, size, numlines, mem_ctx);
@@ -402,3 +433,5 @@ _PUBLIC_ bool large_file_support(const char *path)
        close(fd);
        return ret == 0;
 }
+
+
index 299f5f7c6a2c67f851db8458bfa590d770276c0c..2d6012c9f42b5827f8fdf8e2c6515ce684d8b54d 100644 (file)
@@ -40,12 +40,12 @@ TDB_DATA make_tdb_data(const uint8_t *dptr, size_t dsize)
 
 TDB_DATA string_tdb_data(const char *string)
 {
-       return make_tdb_data((const uint8 *)string, string ? strlen(string) : 0 );
+       return make_tdb_data((const uint8_t *)string, string ? strlen(string) : 0 );
 }
 
 TDB_DATA string_term_tdb_data(const char *string)
 {
-       return make_tdb_data((const uint8 *)string, string ? strlen(string) + 1 : 0);
+       return make_tdb_data((const uint8_t *)string, string ? strlen(string) + 1 : 0);
 }
 
 /****************************************************************************
index a72d673b1be508054dcf067a361f9c784a2cdc56..3297278d87ed8a68ea3d6d1639fb9caeff52c26e 100644 (file)
@@ -326,7 +326,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) \
          lib/bitmap.o ../lib/crypto/crc32.o lib/dprintf.o $(UTIL_REG_OBJ) \
          ../lib/util/xfile.o ../lib/util/util_strlist.o lib/wins_srv.o \
          lib/util_str.o lib/clobber.o lib/util_sid.o lib/util_uuid.o \
-         lib/util_unistr.o lib/util_file.o ../lib/util/data_blob.o \
+         lib/util_unistr.o ../lib/util/util_file.o lib/util_file.o ../lib/util/data_blob.o \
          lib/util.o lib/util_sock.o lib/sock_exec.o lib/util_sec.o \
          lib/substitute.o lib/fsusage.o lib/dbwrap_util.o \
          lib/ms_fnmatch.o lib/select.o lib/errmap_unix.o \
index 08c1e2c81043b28b6f5260b041f2a1a0c09645b5..0a5c4019526099e5d79d1b4a22083ae5740e53d8 100644 (file)
@@ -1362,16 +1362,16 @@ const char *strip_hostname(const char *s);
 /* The following definitions come from lib/util_file.c  */
 
 char *fgets_slash(char *s2,int maxlen,XFILE *f);
-char *fd_load(int fd, size_t *psize, size_t maxsize);
-char *file_load(const char *fname, size_t *size, size_t maxsize);
+char *file_load(const char *fname, size_t *size, size_t maxsize, TALLOC_CTX *mem_ctx);
+char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX *mem_ctx);
 bool unmap_file(void* start, size_t size);
-void *map_file(char *fname, size_t size);
-char **file_lines_load(const char *fname, int *numlines, size_t maxsize);
-char **fd_lines_load(int fd, int *numlines, size_t maxsize);
-char **file_lines_pload(char *syscmd, int *numlines);
+void *map_file(const char *fname, size_t size);
+char **file_lines_load(const char *fname, int *numlines, size_t maxsize, TALLOC_CTX *mem_ctx);
+char **fd_lines_load(int fd, int *numlines, size_t maxsize, TALLOC_CTX *mem_ctx);
+char **file_lines_pload(const char *syscmd, int *numlines);
 void file_lines_free(char **lines);
 void file_lines_slashcont(char **lines);
-bool file_save(const char *fname, void *packet, size_t length);
+bool file_save(const char *fname, const void *packet, size_t length);
 
 /* The following definitions come from lib/util_nscd.c  */
 
index 499b9eb87daa319248757da884a5ba68f6e6318f..ac7e9dda4042133362917f7b6c65a095f0998539 100644 (file)
@@ -33,14 +33,14 @@ static bool load_msg(const char *msg_file)
        char *msgid, *msgstr;
        TDB_DATA data;
 
-       lines = file_lines_load(msg_file, &num_lines,0);
+       lines = file_lines_load(msg_file, &num_lines, 0, NULL);
 
        if (!lines) {
                return False;
        }
 
        if (tdb_lockall(tdb) != 0) {
-               file_lines_free(lines);
+               TALLOC_FREE(lines);
                return False;
        }
 
@@ -68,7 +68,7 @@ static bool load_msg(const char *msg_file)
                }
        }
 
-       file_lines_free(lines);
+       TALLOC_FREE(lines);
        tdb_unlockall(tdb);
 
        return True;
index 4a2d88abdf5ee58d2394cd0657ed6d8da779f9fa..5ee199de22dd60548afcaed37490aedc6c51c9b5 100644 (file)
@@ -295,7 +295,7 @@ static int command_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t
                                dp->bsize = 1024;
                        }
 
-                       file_lines_free(lines);
+                       TALLOC_FREE(lines);
                        lines = NULL;
 
                        DEBUG (3, ("Parsed output of get_quota, ...\n"));
@@ -331,7 +331,7 @@ static int command_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t
 
 invalid_param:
 
-       file_lines_free(lines);
+       TALLOC_FREE(lines);
        DEBUG(0,("The output of get_quota_command is invalid!\n"));
        return -1;
 }
@@ -392,7 +392,7 @@ static int command_set_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t
 
                        DEBUG (3, ("Read output from set_quota, \"%s\"\n", line));
 
-                       file_lines_free(lines);
+                       TALLOC_FREE(lines);
 
                        return 0;
                }
index b628b06cc6aafd37f89ed4dbbc3b86a697a7e9eb..c5a9b7c29afdf59a52ddb711f5ee5f676ee79e99 100644 (file)
 
 #include "includes.h"
 
-#ifndef MAP_FAILED
-#define MAP_FAILED ((void *)-1)
-#endif
-
-/****************************************************************************
- Read a line from a file with possible \ continuation chars. 
- Blanks at the start or end of a line are stripped.
- The string will be allocated if s2 is NULL.
-****************************************************************************/
-
-char *fgets_slash(char *s2,int maxlen,XFILE *f)
-{
-       char *s=s2;
-       int len = 0;
-       int c;
-       bool start_of_line = True;
-
-       if (x_feof(f)) {
-               return(NULL);
-       }
-
-       if (maxlen <2) {
-               return(NULL);
-       }
-
-       if (!s2) {
-               maxlen = MIN(maxlen,8);
-               s = (char *)SMB_MALLOC(maxlen);
-       }
-
-       if (!s) {
-               return(NULL);
-       }
-
-       *s = 0;
-
-       while (len < maxlen-1) {
-               c = x_getc(f);
-               switch (c) {
-                       case '\r':
-                               break;
-                       case '\n':
-                               while (len > 0 && s[len-1] == ' ') {
-                                       s[--len] = 0;
-                               }
-                               if (len > 0 && s[len-1] == '\\') {
-                                       s[--len] = 0;
-                                       start_of_line = True;
-                                       break;
-                               }
-                               return(s);
-                       case EOF:
-                               if (len <= 0 && !s2)  {
-                                       SAFE_FREE(s);
-                               }
-                               return(len>0?s:NULL);
-                       case ' ':
-                               if (start_of_line) {
-                                       break;
-                               }
-                       default:
-                               start_of_line = False;
-                               s[len++] = c;
-                               s[len] = 0;
-               }
-
-               if (!s2 && len > maxlen-3) {
-                       maxlen *= 2;
-                       s = (char *)SMB_REALLOC(s,maxlen);
-                       if (!s) {
-                               DEBUG(0,("fgets_slash: failed to expand buffer!\n"));
-                               return(NULL);
-                       }
-               }
-       }
-       return(s);
-}
-
-/****************************************************************************
+/**
  Load from a pipe into memory.
-****************************************************************************/
+**/
 
-static char *file_pload(char *syscmd, size_t *size)
+static char *file_pload(const char *syscmd, size_t *size)
 {
        int fd, n;
        char *p;
@@ -143,215 +65,14 @@ static char *file_pload(char *syscmd, size_t *size)
        return p;
 }
 
-/****************************************************************************
- Load a file into memory from a fd.
- Truncate at maxsize. If maxsize == 0 - no limit.
-****************************************************************************/ 
-
-char *fd_load(int fd, size_t *psize, size_t maxsize)
-{
-       SMB_STRUCT_STAT sbuf;
-       size_t size;
-       char *p;
-
-       if (sys_fstat(fd, &sbuf) != 0) {
-               return NULL;
-       }
-
-       size = sbuf.st_size;
-       if (maxsize) {
-               size = MIN(size, maxsize);
-       }
-
-       p = (char *)SMB_MALLOC(size+1);
-       if (!p) {
-               return NULL;
-       }
-
-       if (read(fd, p, size) != size) {
-               SAFE_FREE(p);
-               return NULL;
-       }
-       p[size] = 0;
-
-       if (psize) {
-               *psize = size;
-       }
-
-       return p;
-}
-
-/****************************************************************************
- Load a file into memory.
-****************************************************************************/
-
-char *file_load(const char *fname, size_t *size, size_t maxsize)
-{
-       int fd;
-       char *p;
-
-       if (!fname || !*fname) {
-               return NULL;
-       }
-       
-       fd = open(fname,O_RDONLY);
-       if (fd == -1) {
-               return NULL;
-       }
-
-       p = fd_load(fd, size, maxsize);
-       close(fd);
-       return p;
-}
-
-/*******************************************************************
- unmap or free memory
-*******************************************************************/
-
-bool unmap_file(void* start, size_t size)
-{
-#ifdef HAVE_MMAP
-       if ( munmap( start, size ) != 0 ) {
-               DEBUG( 1, ("map_file: Failed to unmap address %p "
-                       "of size %u - %s\n", 
-                       start, (unsigned int)size, strerror(errno) ));
-               return False;
-       }
-       return True;
-#else
-       SAFE_FREE( start );
-       return True;
-#endif
-}
-
-/*******************************************************************
- mmap (if possible) or read a file.
-********************************************************************/
-
-void *map_file(char *fname, size_t size)
-{
-       size_t s2 = 0;
-       void *p = NULL;
-#ifdef HAVE_MMAP
-       int fd;
-       fd = open(fname, O_RDONLY, 0);
-       if (fd == -1) {
-               DEBUG(2,("map_file: Failed to load %s - %s\n", fname, strerror(errno)));
-               return NULL;
-       }
-       p = mmap(NULL, size, PROT_READ, MAP_SHARED|MAP_FILE, fd, 0);
-       close(fd);
-       if (p == MAP_FAILED) {
-               DEBUG(1,("map_file: Failed to mmap %s - %s\n", fname, strerror(errno)));
-               return NULL;
-       }
-#endif
-       if (!p) {
-               p = file_load(fname, &s2, 0);
-               if (!p) {
-                       return NULL;
-               }
-               if (s2 != size) {
-                       DEBUG(1,("map_file: incorrect size for %s - got %lu expected %lu\n",
-                                fname, (unsigned long)s2, (unsigned long)size));
-                       SAFE_FREE(p);   
-                       return NULL;
-               }
-       }
-       return p;
-}
-
-/****************************************************************************
- Parse a buffer into lines.
-****************************************************************************/
-
-static char **file_lines_parse(char *p, size_t size, int *numlines)
-{
-       int i;
-       char *s, **ret;
-
-       if (!p) {
-               return NULL;
-       }
-
-       for (s = p, i=0; s < p+size; s++) {
-               if (s[0] == '\n') i++;
-       }
-
-       ret = SMB_MALLOC_ARRAY(char *, i+2);
-       if (!ret) {
-               SAFE_FREE(p);
-               return NULL;
-       }       
-       memset(ret, 0, sizeof(ret[0])*(i+2));
-
-       ret[0] = p;
-       for (s = p, i=0; s < p+size; s++) {
-               if (s[0] == '\n') {
-                       s[0] = 0;
-                       i++;
-                       ret[i] = s+1;
-               }
-               if (s[0] == '\r') {
-                       s[0] = 0;
-               }
-       }
-
-       /* remove any blank lines at the end */
-       while (i > 0 && ret[i-1][0] == 0) {
-               i--;
-       }
-
-       if (numlines) {
-               *numlines = i;
-       }
-
-       return ret;
-}
-
-/****************************************************************************
- Load a file into memory and return an array of pointers to lines in the file
- must be freed with file_lines_free(). 
-****************************************************************************/
-
-char **file_lines_load(const char *fname, int *numlines, size_t maxsize)
-{
-       char *p;
-       size_t size = 0;
-
-       p = file_load(fname, &size, maxsize);
-       if (!p) {
-               return NULL;
-       }
-
-       return file_lines_parse(p, size, numlines);
-}
-
-/****************************************************************************
- Load a fd into memory and return an array of pointers to lines in the file
- must be freed with file_lines_free(). If convert is true calls unix_to_dos on
- the list.
-****************************************************************************/
 
-char **fd_lines_load(int fd, int *numlines, size_t maxsize)
-{
-       char *p;
-       size_t size;
 
-       p = fd_load(fd, &size, maxsize);
-       if (!p) {
-               return NULL;
-       }
-
-       return file_lines_parse(p, size, numlines);
-}
-
-/****************************************************************************
+/**
  Load a pipe into memory and return an array of pointers to lines in the data
  must be freed with file_lines_free(). 
-****************************************************************************/
+**/
 
-char **file_lines_pload(char *syscmd, int *numlines)
+char **file_lines_pload(const char *syscmd, int *numlines)
 {
        char *p;
        size_t size;
@@ -361,64 +82,5 @@ char **file_lines_pload(char *syscmd, int *numlines)
                return NULL;
        }
 
-       return file_lines_parse(p, size, numlines);
-}
-
-/****************************************************************************
- Free lines loaded with file_lines_load.
-****************************************************************************/
-
-void file_lines_free(char **lines)
-{
-       if (!lines) {
-               return;
-       }
-       SAFE_FREE(lines[0]);
-       SAFE_FREE(lines);
-}
-
-/****************************************************************************
- Take a list of lines and modify them to produce a list where \ continues
- a line.
-****************************************************************************/
-
-void file_lines_slashcont(char **lines)
-{
-       int i, j;
-
-       for (i=0; lines[i];) {
-               int len = strlen(lines[i]);
-               if (lines[i][len-1] == '\\') {
-                       lines[i][len-1] = ' ';
-                       if (lines[i+1]) {
-                               char *p = &lines[i][len];
-                               while (p < lines[i+1]) {
-                                       *p++ = ' ';
-                               }
-                               for (j = i+1; lines[j]; j++) {
-                                       lines[j] = lines[j+1];
-                               }
-                       }
-               } else {
-                       i++;
-               }
-       }
-}
-
-/****************************************************************************
- Save a lump of data into a file. Mostly used for debugging.
-****************************************************************************/
-
-bool file_save(const char *fname, void *packet, size_t length)
-{
-       int fd;
-       fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0644);
-       if (fd == -1) {
-               return False;
-       }
-       if (write(fd, packet, length) != (size_t)length) {
-               return False;
-       }
-       close(fd);
-       return True;
+       return file_lines_parse(p, size, numlines, NULL);
 }
index 54aaffa4776be872e18328bbb6338c7fe1f8d284..aa8f7c77700a2fd6b27e8ef81f029d14c4920c6c 100644 (file)
@@ -63,7 +63,7 @@ static NTSTATUS convert_file_from_ucs2(TALLOC_CTX *mem_ctx,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       data_in = (uint8 *)file_load(filename_in, &n, 0);
+       data_in = (uint8 *)file_load(filename_in, &n, 0, NULL);
        if (!data_in) {
                status = NT_STATUS_NO_SUCH_FILE;
                goto out;
@@ -116,7 +116,7 @@ static NTSTATUS convert_file_from_ucs2(TALLOC_CTX *mem_ctx,
                close(tmp_fd);
        }
 
-       SAFE_FREE(data_in);
+       TALLOC_FREE(data_in);
 
        return status;
 }
index 58efa57bab5db90daddf1564018cb02153c34c73..d646a79334900335f330370aad72932a56a6ef84 100644 (file)
@@ -8385,7 +8385,7 @@ static int process_usershare_file(const char *dir_name, const char *file_name, i
                return -1;
        }
 
-       lines = fd_lines_load(fd, &numlines, MAX_USERSHARE_FILE_SIZE);
+       lines = fd_lines_load(fd, &numlines, MAX_USERSHARE_FILE_SIZE, NULL);
 
        close(fd);
        if (lines == NULL) {
@@ -8400,7 +8400,7 @@ static int process_usershare_file(const char *dir_name, const char *file_name, i
        /* Should we allow printers to be shared... ? */
        ctx = talloc_init("usershare_sd_xctx");
        if (!ctx) {
-               file_lines_free(lines);
+               TALLOC_FREE(lines);
                return 1;
        }
 
@@ -8408,11 +8408,11 @@ static int process_usershare_file(const char *dir_name, const char *file_name, i
                        iService, lines, numlines, &sharepath,
                        &comment, &psd, &guest_ok) != USERSHARE_OK) {
                talloc_destroy(ctx);
-               file_lines_free(lines);
+               TALLOC_FREE(lines);
                return -1;
        }
 
-       file_lines_free(lines);
+       TALLOC_FREE(lines);
 
        /* Everything ok - add the service possibly using a template. */
        if (iService < 0) {
index 478376c9e9ab0de79439543c1b05c4921df27769..97db613fc43458961e40c1ca06df0fd3f16c6920 100644 (file)
@@ -118,7 +118,7 @@ static void myfile_close(myFILE *f)
 {
        if (!f)
                return;
-       SAFE_FREE(f->buf);
+       TALLOC_FREE(f->buf);
        SAFE_FREE(f);
 }
 
@@ -525,7 +525,7 @@ static myFILE *OpenConfFile( const char *FileName )
        if (!ret)
                return NULL;
 
-       ret->buf = file_load(FileName, &ret->size, 0);
+       ret->buf = file_load(FileName, &ret->size, 0, NULL);
        if( NULL == ret->buf ) {
                DEBUG( lvl, ("%s Unable to open configuration file \"%s\":\n\t%s\n",
                        func, FileName, strerror(errno)) );
index ff2c9bcb0d9fd46870f10753c684c0760689142e..c7c3cc474b9dcb213036191fa1b716e0ceb2d1d4 100644 (file)
@@ -41,15 +41,15 @@ static bool read_sid_from_file(const char *fname, DOM_SID *sid)
        int numlines;
        bool ret;
 
-       lines = file_lines_load(fname, &numlines,0);
+       lines = file_lines_load(fname, &numlines,0, NULL);
        
        if (!lines || numlines < 1) {
-               if (lines) file_lines_free(lines);
+               if (lines) TALLOC_FREE(lines);
                return False;
        }
        
        ret = string_to_sid(sid, lines[0]);
-       file_lines_free(lines);
+       TALLOC_FREE(lines);
        return ret;
 }
 
index 850375e82b300a6e0a205fb42fafdc24425206fe..13a6403b1c0e9dc4921ceb2366de69158749ab87 100644 (file)
@@ -3925,10 +3925,10 @@ static void map_to_os2_driver(fstring drivername)
                return;
        }
 
-       lines = file_lines_load(mapfile, &numlines,0);
+       lines = file_lines_load(mapfile, &numlines,0,NULL);
        if (numlines == 0 || lines == NULL) {
                DEBUG(0,("No entries in OS/2 driver map %s\n",mapfile));
-               SAFE_FREE(lines);
+               TALLOC_FREE(lines);
                return;
        }
 
@@ -3972,12 +3972,12 @@ static void map_to_os2_driver(fstring drivername)
                        DEBUG(3,("Mapped windows driver %s to os2 driver%s\n",drivername,os2_name));
                        set_last_from_to(drivername,os2_name);
                        fstrcpy(drivername,os2_name);
-                       file_lines_free(lines);
+                       TALLOC_FREE(lines);
                        return;
                }
        }
 
-       file_lines_free(lines);
+       TALLOC_FREE(lines);
 }
 
 /****************************************************************************
index 0c05915bd8f85a60496a9e8bc8983a6dd32dc175..5806b292064821254d5c723ce0ff204ab98daf4e 100644 (file)
@@ -238,7 +238,7 @@ static int generic_queue_get(const char *printer_name,
        }
        
        numlines = 0;
-       qlines = fd_lines_load(fd, &numlines,0);
+       qlines = fd_lines_load(fd, &numlines,0,NULL);
        close(fd);
 
        /* turn the lpq output into a series of job structures */
@@ -247,7 +247,7 @@ static int generic_queue_get(const char *printer_name,
        if (numlines && qlines) {
                queue = SMB_MALLOC_ARRAY(print_queue_struct, numlines+1);
                if (!queue) {
-                       file_lines_free(qlines);
+                       TALLOC_FREE(qlines);
                        *q = NULL;
                        return 0;
                }
@@ -262,7 +262,7 @@ static int generic_queue_get(const char *printer_name,
                }               
        }
 
-       file_lines_free(qlines);
+       TALLOC_FREE(qlines);
         *q = queue;
        return qcount;
 }
index 7e91d3a677acb98c96f88f2b969a702c6f8dccd7..681b2bf459b93bc30e4e1e6547d6a8f5763f5387 100644 (file)
@@ -59,12 +59,12 @@ bool sysv_cache_reload(void)
                 scheduler = file_lines_pload("/usr/bin/lpstat -r", NULL);
                 if(!strcmp(*scheduler,"scheduler is running")){
                         DEBUG(3,("No Printers found!!!\n"));
-                       file_lines_free(scheduler);
+                       TALLOC_FREE(scheduler);
                         return True;
                 }
                 else{
                         DEBUG(3,("Scheduler is not running!!!\n"));
-                       file_lines_free(scheduler);
+                       TALLOC_FREE(scheduler);
                        return False;
                }
 #else
@@ -111,12 +111,12 @@ bool sysv_cache_reload(void)
                
                /* add it to the cache */
                if (!pcap_cache_add(name, NULL)) {
-                       file_lines_free(lines);
+                       TALLOC_FREE(lines);
                        return False;
                }
        }
 
-       file_lines_free(lines);
+       TALLOC_FREE(lines);
        return True;
 }
 
index 635898a9d5769e12b8b07987767f561b00d4a5dd..52cb02b109c86ce3b434d3e8124c40eac8759912 100644 (file)
@@ -6280,7 +6280,7 @@ bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, NT_PRINTER_INFO_LEV
 
        numlines = 0;
        /* Get lines and convert them back to dos-codepage */
-       qlines = fd_lines_load(fd, &numlines, 0);
+       qlines = fd_lines_load(fd, &numlines, 0, NULL);
        DEBUGADD(10,("Lines returned = [%d]\n", numlines));
        close(fd);
 
@@ -6293,7 +6293,7 @@ bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, NT_PRINTER_INFO_LEV
                DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
        }
 
-       file_lines_free(qlines);
+       TALLOC_FREE(qlines);
        return True;
 }
 
@@ -7512,7 +7512,7 @@ WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines )
                }
 
                numlines = 0;
-               qlines = fd_lines_load(fd, &numlines, 0);
+               qlines = fd_lines_load(fd, &numlines, 0, NULL);
                DEBUGADD(10,("Lines returned = [%d]\n", numlines));
                close(fd);
        }
@@ -7537,7 +7537,7 @@ static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *need
 
        result = enumports_hook(talloc_tos(), &numlines, &qlines );
        if (!W_ERROR_IS_OK(result)) {
-               file_lines_free(qlines);
+               TALLOC_FREE(qlines);
                return result;
        }
 
@@ -7545,7 +7545,7 @@ static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *need
                if((ports=SMB_MALLOC_ARRAY( PORT_INFO_1, numlines )) == NULL) {
                        DEBUG(10,("Returning WERR_NOMEM [%s]\n",
                                  dos_errstr(WERR_NOMEM)));
-                       file_lines_free(qlines);
+                       TALLOC_FREE(qlines);
                        return WERR_NOMEM;
                }
 
@@ -7554,7 +7554,7 @@ static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *need
                        fill_port_1(&ports[i], qlines[i]);
                }
        }
-       file_lines_free(qlines);
+       TALLOC_FREE(qlines);
 
        *returned = numlines;
 
@@ -7603,13 +7603,13 @@ static WERROR enumports_level_2(RPC_BUFFER *buffer, uint32 offered, uint32 *need
 
        result = enumports_hook(talloc_tos(), &numlines, &qlines );
        if ( !W_ERROR_IS_OK(result)) {
-               file_lines_free(qlines);
+               TALLOC_FREE(qlines);
                return result;
        }
 
        if(numlines) {
                if((ports=SMB_MALLOC_ARRAY( PORT_INFO_2, numlines)) == NULL) {
-                       file_lines_free(qlines);
+                       TALLOC_FREE(qlines);
                        return WERR_NOMEM;
                }
 
@@ -7619,7 +7619,7 @@ static WERROR enumports_level_2(RPC_BUFFER *buffer, uint32 offered, uint32 *need
                }
        }
 
-       file_lines_free(qlines);
+       TALLOC_FREE(qlines);
 
        *returned = numlines;
 
index 1ddcd48d40469b8d049e8ea51b13946315b53fa1..282027ee5a4c32967803b8319af47ada64b9722b 100644 (file)
@@ -112,7 +112,7 @@ SMB_BIG_UINT sys_disk_free(connection_struct *conn, const char *path, bool small
                                *bsize = STR_TO_SMB_BIG_UINT(p, NULL);
                        else
                                *bsize = 1024;
-                       file_lines_free(lines);
+                       TALLOC_FREE(lines);
                        DEBUG (3, ("Parsed output of dfree, dsize=%u, dfree=%u, bsize=%u\n",
                                (unsigned int)*dsize, (unsigned int)*dfree, (unsigned int)*bsize));
 
index fe1d766b9d38cc47607abdcd3fbd8ceffc338549..0c866da7069b5fd7de1fc1bb2036f2db8f256689 100644 (file)
@@ -1154,7 +1154,7 @@ static int get_server_info(uint32 servertype,
        bool local_list_only;
        int i;
 
-       lines = file_lines_load(lock_path(SERVER_LIST), NULL, 0);
+       lines = file_lines_load(lock_path(SERVER_LIST), NULL, 0, NULL);
        if (!lines) {
                DEBUG(4,("Can't open %s - %s\n",lock_path(SERVER_LIST),strerror(errno)));
                return 0;
@@ -1186,7 +1186,7 @@ static int get_server_info(uint32 servertype,
                        *servers = SMB_REALLOC_ARRAY(*servers,struct srv_info_struct, alloced);
                        if (!*servers) {
                                DEBUG(0,("get_server_info: failed to enlarge servers info struct!\n"));
-                               file_lines_free(lines);
+                               TALLOC_FREE(lines);
                                return 0;
                        }
                        memset((char *)((*servers)+count),'\0',sizeof(**servers)*(alloced-count));
@@ -1267,7 +1267,7 @@ static int get_server_info(uint32 servertype,
                }
        }
   
-       file_lines_free(lines);
+       TALLOC_FREE(lines);
        return count;
 }
 
index 7536758bcb68ee9fc5f89f25559228b24381e569..a8899dd538af118bf45c7b9aeb02d1daaccce91e 100644 (file)
@@ -116,7 +116,7 @@ bool map_username(fstring user)
                }
 
                numlines = 0;
-               qlines = fd_lines_load(fd, &numlines,0);
+               qlines = fd_lines_load(fd, &numlines,0, NULL);
                DEBUGADD(10,("Lines returned = [%d]\n", numlines));
                close(fd);
 
@@ -127,7 +127,7 @@ bool map_username(fstring user)
                        fstrcpy( user, qlines[0] );
                }
 
-               file_lines_free(qlines);
+               TALLOC_FREE(qlines);
 
                return numlines != 0;
        }
index 8f263c636ccd13f95502014c526af39bc95fe130..ce8e82182e83e76934240d8634a1c22e1f28c068 100644 (file)
@@ -371,7 +371,7 @@ static int info_fn(struct file_list *fl, void *priv)
                return -1;
        }
 
-       lines = fd_lines_load(fd, &numlines, 10240);
+       lines = fd_lines_load(fd, &numlines, 10240, NULL);
        close(fd);
 
        if (lines == NULL) {
@@ -385,7 +385,7 @@ static int info_fn(struct file_list *fl, void *priv)
                                &psd,
                                &guest_ok);
 
-       file_lines_free(lines);
+       TALLOC_FREE(lines);
 
        if (us_err != USERSHARE_OK) {
                d_fprintf(stderr, "info_fn: file %s is not a well formed usershare file.\n",
index 364e80a3a6d3213380e91ba8b828bf138880f4a8..8f4f8c95610dffaf8029876df780d8908ad89bbd 100644 (file)
@@ -118,7 +118,7 @@ _PUBLIC_ bool cli_credentials_parse_file(struct cli_credentials *cred, const cha
        char **lines;
        int i, numlines;
 
-       lines = file_lines_load(file, &numlines, NULL);
+       lines = file_lines_load(file, &numlines, 0, NULL);
 
        if (lines == NULL)
        {
index 449ee0f6eefa6277de797f10de933949f02891c8..42946bceeca00a7aed6e0ef571c59589cdd6fe39 100644 (file)
@@ -327,7 +327,7 @@ static WERROR reg_dir_get_value(TALLOC_CTX *mem_ctx,
        size_t size;
        char *contents;
 
-       contents = file_load(path, &size, mem_ctx);
+       contents = file_load(path, &size, 0, mem_ctx);
        talloc_free(path);
        if (contents == NULL)
                return WERR_BADFILE;
index 57a895aa000b6cd17803093a2e58d12b1951bcf4..dd3ff47b78103563193de1cfb40b6875f31246b6 100644 (file)
@@ -2066,7 +2066,7 @@ WERROR reg_open_regf_file(TALLOC_CTX *parent_ctx, const char *location,
 
        pull = tdr_pull_init(regf, regf->iconv_convenience);
 
-       pull->data.data = (uint8_t*)fd_load(regf->fd, &pull->data.length, regf);
+       pull->data.data = (uint8_t*)fd_load(regf->fd, &pull->data.length, 0, regf);
 
        if (pull->data.data == NULL) {
                DEBUG(0, ("Error reading data\n"));
index b298fb10cf3f5abdb483ff1cb6343a17511035de..046c2b90368d475c4a65e098b82bd9178a656263 100644 (file)
@@ -421,7 +421,7 @@ struct tls_params *tls_initialise(TALLOC_CTX *mem_ctx, struct loadparm_context *
        if (dhpfile && *dhpfile) {
                gnutls_datum_t dhparms;
                size_t size;
-               dhparms.data = (uint8_t *)file_load(dhpfile, &size, mem_ctx);
+               dhparms.data = (uint8_t *)file_load(dhpfile, &size, 0, mem_ctx);
 
                if (!dhparms.data) {
                        DEBUG(0,("Failed to read DH Parms from %s\n", dhpfile));
index 3bf3ad8b1bf550f0346134b1be1129d36b89a75e..74ece9942281f43ea57a206a7205440f5e4185e4 100644 (file)
@@ -3046,7 +3046,7 @@ static bool start_gentest(struct event_context *ev,
        /* generate the seeds - after this everything is deterministic */
        if (options.use_preset_seeds) {
                int numops;
-               char **preset = file_lines_load(options.seeds_file, &numops, NULL);
+               char **preset = file_lines_load(options.seeds_file, &numops, 0, NULL);
                if (!preset) {
                        printf("Failed to load %s - %s\n", options.seeds_file, strerror(errno));
                        exit(1);
@@ -3193,7 +3193,7 @@ static bool split_unc_name(const char *unc, char **server, char **share)
        }
 
        if (ignore_file) {
-               options.ignore_patterns = file_lines_load(ignore_file, NULL, NULL);
+               options.ignore_patterns = file_lines_load(ignore_file, NULL, 0, NULL);
        }
 
        argv_new = discard_const_p(char *, poptGetArgs(pc));