The branch, v3-2-test has been updated
       via  d2ee75326ac291ab4f1860075ba35f58703c7d9d (commit)
      from  a04e916b89c901911ffc0a62e57a3ec87fe7ac28 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit d2ee75326ac291ab4f1860075ba35f58703c7d9d
Author: Jeremy Allison <[EMAIL PROTECTED]>
Date:   Wed Nov 21 13:56:36 2007 -0800

    Remove pstring from printing/*.c except for the
    tdb_unpack requirement (I'll be making that an
    allocating interface later).
    Jeremy.

-----------------------------------------------------------------------

Summary of changes:
 source/printing/nt_printing.c   |  456 +++++++++++++++++++++++----------------
 source/printing/pcap.c          |   17 +-
 source/printing/print_aix.c     |   32 ++-
 source/printing/print_cups.c    |   12 +-
 source/printing/print_generic.c |  112 +++++++---
 source/printing/printing_db.c   |   16 +-
 6 files changed, 396 insertions(+), 249 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/printing/nt_printing.c b/source/printing/nt_printing.c
index 1d218ba..bbe312c 100644
--- a/source/printing/nt_printing.c
+++ b/source/printing/nt_printing.c
@@ -228,18 +228,17 @@ static const struct table_node archi_table[]= {
  generate a new TDB_DATA key for storing a printer
 ****************************************************************************/
 
-static TDB_DATA make_printer_tdbkey( const char *sharename )
+static TDB_DATA make_printer_tdbkey(TALLOC_CTX *ctx, const char *sharename )
 {
        fstring share;
-       static pstring keystr;
+       char *keystr = NULL;
        TDB_DATA key;
-       
-       fstrcpy( share, sharename );
-       strlower_m( share );
-       
-       pstr_sprintf( keystr, "%s%s", PRINTERS_PREFIX, share );
-       
-       key = string_term_tdb_data(keystr);
+
+       fstrcpy(share, sharename);
+       strlower_m(share);
+
+       keystr = talloc_asprintf(ctx, "%s%s", PRINTERS_PREFIX, share);
+       key = string_term_tdb_data(keystr ? keystr : "");
 
        return key;
 }
@@ -248,18 +247,18 @@ static TDB_DATA make_printer_tdbkey( const char 
*sharename )
  generate a new TDB_DATA key for storing a printer security descriptor
 ****************************************************************************/
 
-static TDB_DATA make_printers_secdesc_tdbkey( const char* sharename  )
+static TDB_DATA make_printers_secdesc_tdbkey(TALLOC_CTX *ctx,
+                                       const char* sharename  )
 {
        fstring share;
-       static pstring keystr;
+       char *keystr = NULL;
        TDB_DATA key;
 
-       fstrcpy( share, sharename );
-       strlower_m( share );
-       
-       pstr_sprintf( keystr, "%s%s", SECDESC_PREFIX, share );
+       fstrcpy(share, sharename );
+       strlower_m(share);
 
-       key = string_term_tdb_data(keystr);
+       keystr = talloc_asprintf(ctx, "%s%s", SECDESC_PREFIX, share);
+       key = string_term_tdb_data(keystr ? keystr : "");
 
        return key;
 }
@@ -482,38 +481,39 @@ static bool upgrade_to_version_4(void)
 static int normalize_printers_fn( TDB_CONTEXT *the_tdb, TDB_DATA key,
                                   TDB_DATA data, void *state )
 {
+       TALLOC_CTX *ctx = talloc_tos();
        TDB_DATA new_key;
-       
+
        if (!data.dptr || data.dsize == 0)
                return 0;
 
        /* upgrade printer records and security descriptors */
-       
+
        if ( strncmp((const char *) key.dptr, PRINTERS_PREFIX, 
strlen(PRINTERS_PREFIX) ) == 0 ) {
-               new_key = make_printer_tdbkey( (const char 
*)key.dptr+strlen(PRINTERS_PREFIX) );
+               new_key = make_printer_tdbkey(ctx, (const char 
*)key.dptr+strlen(PRINTERS_PREFIX) );
        }
        else if ( strncmp((const char *) key.dptr, SECDESC_PREFIX, 
strlen(SECDESC_PREFIX) ) == 0 ) {
-               new_key = make_printers_secdesc_tdbkey( (const char 
*)key.dptr+strlen(SECDESC_PREFIX) );
+               new_key = make_printers_secdesc_tdbkey(ctx, (const char 
*)key.dptr+strlen(SECDESC_PREFIX) );
        }
        else {
                /* ignore this record */
                return 0;
        }
-               
+
        /* delete the original record and store under the normalized key */
-       
+
        if ( tdb_delete( the_tdb, key ) != 0 ) {
                DEBUG(0,("normalize_printers_fn: tdb_delete for [%s] 
failed!\n", 
                        key.dptr));
                return 1;
        }
-       
+
        if ( tdb_store( the_tdb, new_key, data, TDB_REPLACE) != 0 ) {
                DEBUG(0,("normalize_printers_fn: failed to store new record for 
[%s]!\n",
                        key.dptr));
                return 1;
        }
-       
+
        return 0;
 }
 
@@ -830,24 +830,46 @@ int get_ntforms(nt_forms_struct **list)
 /****************************************************************************
 write a form struct list
 ****************************************************************************/
+
 int write_ntforms(nt_forms_struct **list, int number)
 {
-       pstring buf, key;
+       TALLOC_CTX *ctx = talloc_tos();
+       char *buf = NULL;
+       char *key = NULL;
        int len;
        TDB_DATA dbuf;
        int i;
 
        for (i=0;i<number;i++) {
                /* save index, so list is rebuilt in correct order */
-               len = tdb_pack((uint8 *)buf, sizeof(buf), "dddddddd",
+               len = tdb_pack(NULL, 0, "dddddddd",
                               i, (*list)[i].flag, (*list)[i].width, 
(*list)[i].length,
                               (*list)[i].left, (*list)[i].top, 
(*list)[i].right,
                               (*list)[i].bottom);
-               if (len > sizeof(buf)) break;
-               slprintf(key, sizeof(key)-1, "%s%s", FORMS_PREFIX, 
(*list)[i].name);
+               if (!len) {
+                       continue;
+               }
+               buf = TALLOC_ARRAY(ctx, char, len);
+               if (!buf) {
+                       return 0;
+               }
+               len = tdb_pack((uint8 *)buf, len, "dddddddd",
+                              i, (*list)[i].flag, (*list)[i].width, 
(*list)[i].length,
+                              (*list)[i].left, (*list)[i].top, 
(*list)[i].right,
+                              (*list)[i].bottom);
+               key = talloc_asprintf(ctx, "%s%s", FORMS_PREFIX, 
(*list)[i].name);
+               if (!key) {
+                       return 0;
+               }
                dbuf.dsize = len;
                dbuf.dptr = (uint8 *)buf;
-               if (tdb_store_bystring(tdb_forms, key, dbuf, TDB_REPLACE) != 0) 
break;
+               if (tdb_store_bystring(tdb_forms, key, dbuf, TDB_REPLACE) != 0) 
{
+                       TALLOC_FREE(key);
+                       TALLOC_FREE(buf);
+                       break;
+               }
+               TALLOC_FREE(key);
+               TALLOC_FREE(buf);
        }
 
        return i;
@@ -907,7 +929,7 @@ bool add_a_form(nt_forms_struct **list, const FORM *form, 
int *count)
 
 bool delete_a_form(nt_forms_struct **list, UNISTR2 *del_name, int *count, 
WERROR *ret)
 {
-       pstring key;
+       char *key = NULL;
        int n=0;
        fstring form_name;
 
@@ -928,13 +950,17 @@ bool delete_a_form(nt_forms_struct **list, UNISTR2 
*del_name, int *count, WERROR
                return False;
        }
 
-       slprintf(key, sizeof(key)-1, "%s%s", FORMS_PREFIX, (*list)[n].name);
+       if (asprintf(&key, "%s%s", FORMS_PREFIX, (*list)[n].name) < 0) {
+               *ret = WERR_NOMEM;
+               return false;
+       }
        if (tdb_delete_bystring(tdb_forms, key) != 0) {
+               SAFE_FREE(key);
                *ret = WERR_NOMEM;
                return False;
        }
-
-       return True;
+       SAFE_FREE(key);
+       return true;
 }
 
 /****************************************************************************
@@ -973,7 +999,7 @@ int get_ntdrivers(fstring **list, const char *architecture, 
uint32 version)
 {
        int total=0;
        const char *short_archi;
-       pstring key;
+       char *key = NULL;
        TDB_DATA kbuf, newkey;
 
        short_archi = get_short_archi(architecture);
@@ -981,7 +1007,10 @@ int get_ntdrivers(fstring **list, const char 
*architecture, uint32 version)
                return 0;
        }
 
-       slprintf(key, sizeof(key)-1, "%s%s/%d/", DRIVERS_PREFIX, short_archi, 
version);
+       if (asprintf(&key, "%s%s/%d/", DRIVERS_PREFIX,
+                               short_archi, version) < 0) {
+               return 0;
+       }
 
        for (kbuf = tdb_firstkey(tdb_drivers);
             kbuf.dptr;
@@ -989,9 +1018,10 @@ int get_ntdrivers(fstring **list, const char 
*architecture, uint32 version)
 
                if (strncmp((const char *)kbuf.dptr, key, strlen(key)) != 0)
                        continue;
-               
+
                if((*list = SMB_REALLOC_ARRAY(*list, fstring, total+1)) == 
NULL) {
                        DEBUG(0,("get_ntdrivers: failed to enlarge list!\n"));
+                       SAFE_FREE(key);
                        return -1;
                }
 
@@ -999,6 +1029,7 @@ int get_ntdrivers(fstring **list, const char 
*architecture, uint32 version)
                total++;
        }
 
+       SAFE_FREE(key);
        return(total);
 }
 
@@ -2063,13 +2094,15 @@ WERROR 
move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
 
 /****************************************************************************
 ****************************************************************************/
+
 static uint32 add_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 *driver)
 {
+       TALLOC_CTX *ctx = talloc_tos();
        int len, buflen;
        const char *architecture;
-       pstring directory;
+       char *directory = NULL;
        fstring temp_name;
-       pstring key;
+       char *key = NULL;
        uint8 *buf;
        int i, ret;
        TDB_DATA dbuf;
@@ -2084,7 +2117,11 @@ static uint32 
add_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 *driver)
         * It does make sense to NOT store the server's name in the printer TDB.
         */
 
-       slprintf(directory, sizeof(directory)-1, "\\print$\\%s\\%d\\", 
architecture, driver->cversion);
+       directory = talloc_asprintf(ctx, "\\print$\\%s\\%d\\",
+                       architecture, driver->cversion);
+       if (!directory) {
+               return (uint32)-1;
+       }
 
        /* .inf files do not always list a file for each of the four standard 
files. 
         * Don't prepend a path to a null filename, or client claims:
@@ -2119,7 +2156,11 @@ static uint32 
add_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 *driver)
                }
        }
 
-       slprintf(key, sizeof(key)-1, "%s%s/%d/%s", DRIVERS_PREFIX, 
architecture, driver->cversion, driver->name);
+       key = talloc_asprintf(ctx, "%s%s/%d/%s", DRIVERS_PREFIX,
+                       architecture, driver->cversion, driver->name);
+       if (!key) {
+               return (uint32)-1;
+       }
 
        DEBUG(5,("add_a_printer_driver_3: Adding driver with key %s\n", key ));
 
@@ -2159,7 +2200,7 @@ static uint32 
add_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 *driver)
 
        dbuf.dptr = buf;
        dbuf.dsize = len;
-       
+
        ret = tdb_store_bystring(tdb_drivers, key, dbuf, TDB_REPLACE);
 
 done:
@@ -2232,7 +2273,7 @@ static WERROR 
get_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 **info_ptr,
        const char *architecture;
        int len = 0;
        int i;
-       pstring key;
+       char *key = NULL;
 
        ZERO_STRUCT(driver);
 
@@ -2240,19 +2281,24 @@ static WERROR 
get_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 **info_ptr,
        if ( !architecture ) {
                return WERR_UNKNOWN_PRINTER_DRIVER;
        }
-       
+
        /* Windows 4.0 (i.e. win9x) should always use a version of 0 */
-       
+
        if ( strcmp( architecture, SPL_ARCH_WIN40 ) == 0 )
                version = 0;
 
        DEBUG(8,("get_a_printer_driver_3: [%s%s/%d/%s]\n", DRIVERS_PREFIX, 
architecture, version, drivername));
 
-       slprintf(key, sizeof(key)-1, "%s%s/%d/%s", DRIVERS_PREFIX, 
architecture, version, drivername);
-       
+       if (asprintf(&key, "%s%s/%d/%s", DRIVERS_PREFIX,
+                               architecture, version, drivername) < 0) {
+               return WERR_NOMEM;
+       }
+
        dbuf = tdb_fetch_bystring(tdb_drivers, key);
-       if (!dbuf.dptr) 
+       if (!dbuf.dptr) {
+               SAFE_FREE(key);
                return WERR_UNKNOWN_PRINTER_DRIVER;
+       }
 
        len += tdb_unpack(dbuf.dptr, dbuf.dsize, "dffffffff",
                          &driver.cversion,
@@ -2277,11 +2323,12 @@ static WERROR 
get_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 **info_ptr,
                                  &driver.dependentfiles[i]);
                i++;
        }
-       
+
        if ( driver.dependentfiles )
                fstrcpy( driver.dependentfiles[i], "" );
 
        SAFE_FREE(dbuf.dptr);
+       SAFE_FREE(key);
 
        if (len != dbuf.dsize) {
                SAFE_FREE(driver.dependentfiles);
@@ -2397,7 +2444,6 @@ int pack_devicemode(NT_DEVICEMODE *nt_devmode, uint8 
*buf, int buflen)
                        nt_devmode->panningheight,
                        nt_devmode->nt_dev_private);
 
-       
        if (nt_devmode->nt_dev_private) {
                len += tdb_pack(buf+len, buflen-len, "B",
                                nt_devmode->driverextra,
@@ -2412,44 +2458,46 @@ int pack_devicemode(NT_DEVICEMODE *nt_devmode, uint8 
*buf, int buflen)
 /****************************************************************************
  Pack all values in all printer keys
  ***************************************************************************/
- 
+
 static int pack_values(NT_PRINTER_DATA *data, uint8 *buf, int buflen)
 {
        int             len = 0;
        int             i, j;
        REGISTRY_VALUE  *val;
        REGVAL_CTR      *val_ctr;
-       pstring         path;
+       char *path = NULL;
        int             num_values;
 
        if ( !data )
                return 0;
 
        /* loop over all keys */
-               
-       for ( i=0; i<data->num_keys; i++ ) {    
+
+       for ( i=0; i<data->num_keys; i++ ) {
                val_ctr = data->keys[i].values;
                num_values = regval_ctr_numvals( val_ctr );
 
                /* pack the keyname followed by a empty value */
 
-               len += tdb_pack(buf+len, buflen-len, "pPdB", 
+               len += tdb_pack(buf+len, buflen-len, "pPdB",
                                &data->keys[i].name,
-                               data->keys[i].name, 
+                               data->keys[i].name,
                                REG_NONE,
                                0,
                                NULL);
-               
+
                /* now loop over all values */
-               
+
                for ( j=0; j<num_values; j++ ) {
                        /* pathname should be stored as <key>\<value> */
-                       
+
                        val = regval_ctr_specific_value( val_ctr, j );
-                       pstrcpy( path, data->keys[i].name );
-                       pstrcat( path, "\\" );
-                       pstrcat( path, regval_name(val) );
-                       
+                       if (asprintf(&path, "%s\\%s",
+                                       data->keys[i].name,
+                                       regval_name(val)) < 0) {
+                               return -1;
+                       }
+
                        len += tdb_pack(buf+len, buflen-len, "pPdB",
                                        val,
                                        path,
@@ -2458,12 +2506,13 @@ static int pack_values(NT_PRINTER_DATA *data, uint8 
*buf, int buflen)
                                        regval_data_p(val) );
 
                        DEBUG(8,("specific: [%s], len: %d\n", regval_name(val), 
regval_size(val)));
+                       SAFE_FREE(path);
                }
-       
+
        }
 
        /* terminator */
-       
+
        len += tdb_pack(buf+len, buflen-len, "p", NULL);
 
        return len;
@@ -2478,22 +2527,25 @@ static int pack_values(NT_PRINTER_DATA *data, uint8 
*buf, int buflen)
 uint32 del_a_printer(const char *sharename)
 {
        TDB_DATA kbuf;
-       pstring printdb_path;
+       char *printdb_path = NULL;
+       TALLOC_CTX *ctx = talloc_tos();
 
-       kbuf = make_printer_tdbkey( sharename );
+       kbuf = make_printer_tdbkey(ctx, sharename);
        tdb_delete(tdb_printers, kbuf);
 
-       kbuf= make_printers_secdesc_tdbkey( sharename );
+       kbuf= make_printers_secdesc_tdbkey(ctx, sharename);
        tdb_delete(tdb_printers, kbuf);
 
        close_all_print_db();
 
        if (geteuid() == 0) {
-               pstrcpy(printdb_path, lock_path("printing/"));
-               pstrcat(printdb_path, sharename);
-               pstrcat(printdb_path, ".tdb");
-
+               if (asprintf(&printdb_path, "%s%s.tdb",
+                               lock_path("printing/"),
+                               sharename) < 0) {
+                       return (uint32)-1;
+               }
                unlink(printdb_path);
+               SAFE_FREE(printdb_path);
        }
 
        return 0;
@@ -2505,6 +2557,7 @@ static WERROR update_a_printer_2(NT_PRINTER_INFO_LEVEL_2 
*info)
 {
        uint8 *buf;
        int buflen, len;
+       int retlen;
        WERROR ret;
        TDB_DATA kbuf, dbuf;
        
@@ -2539,7 +2592,7 @@ static WERROR update_a_printer_2(NT_PRINTER_INFO_LEVEL_2 
*info)
        buf = NULL;
        buflen = 0;
 
- again:        
+ again:
        len = 0;
        len += tdb_pack(buf+len, buflen-len, "dddddddddddfffffPfffff",
                        info->attributes,
@@ -2566,8 +2619,12 @@ static WERROR update_a_printer_2(NT_PRINTER_INFO_LEVEL_2 
*info)
                        info->parameters);
 
        len += pack_devicemode(info->devmode, buf+len, buflen-len);
-       
-       len += pack_values( info->data, buf+len, buflen-len );
+       retlen = pack_values( info->data, buf+len, buflen-len );
+       if (retlen == -1) {
+               ret = WERR_NOMEM;
+               goto done;
+       }
+       len += retlen;
 
        if (buflen != len) {
                buf = (uint8 *)SMB_REALLOC(buf, len);
@@ -2579,9 +2636,8 @@ static WERROR update_a_printer_2(NT_PRINTER_INFO_LEVEL_2 
*info)
                buflen = len;
                goto again;
        }
-       
 
-       kbuf = make_printer_tdbkey( info->sharename );
+       kbuf = make_printer_tdbkey(talloc_tos(), info->sharename );
 
        dbuf.dptr = buf;
        dbuf.dsize = len;
@@ -3645,13 +3701,13 @@ WERROR add_printer_data( NT_PRINTER_INFO_LEVEL_2 *p2, 
const char *key, const cha
        
        DEBUG(8,("add_printer_data: Added key => [%s], value => [%s], type=> 
[%d], size => [%d]\n",
                key, value, type, real_len  ));
-       
+


-- 
Samba Shared Repository

Reply via email to