RIP BOOL. Convert BOOL -> bool. I found a few interesting
[nivanova/samba-autobuild/.git] / source3 / printing / nt_printing.c
index 1ff29a67eee9b9d5d4ae9343df82dffb21fe90c0..5276c2d78ca329e412271ebc89387f108c1d3256 100644 (file)
@@ -7,7 +7,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,
@@ -16,8 +16,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"
@@ -43,14 +42,14 @@ static TDB_CONTEXT *tdb_printers; /* used for printers files */
 
 /* Map generic permissions to printer object specific permissions */
 
-GENERIC_MAPPING printer_generic_mapping = {
+const struct generic_mapping printer_generic_mapping = {
        PRINTER_READ,
        PRINTER_WRITE,
        PRINTER_EXECUTE,
        PRINTER_ALL_ACCESS
 };
 
-STANDARD_MAPPING printer_std_mapping = {
+const struct standard_mapping printer_std_mapping = {
        PRINTER_READ,
        PRINTER_WRITE,
        PRINTER_EXECUTE,
@@ -59,14 +58,14 @@ STANDARD_MAPPING printer_std_mapping = {
 
 /* Map generic permissions to print server object specific permissions */
 
-GENERIC_MAPPING printserver_generic_mapping = {
+const struct generic_mapping printserver_generic_mapping = {
        SERVER_READ,
        SERVER_WRITE,
        SERVER_EXECUTE,
        SERVER_ALL_ACCESS
 };
 
-STANDARD_MAPPING printserver_std_mapping = {
+const struct generic_mapping printserver_std_mapping = {
        SERVER_READ,
        SERVER_WRITE,
        SERVER_EXECUTE,
@@ -240,8 +239,7 @@ static TDB_DATA make_printer_tdbkey( const char *sharename )
        
        pstr_sprintf( keystr, "%s%s", PRINTERS_PREFIX, share );
        
-       key.dptr = keystr;
-       key.dsize = strlen(keystr)+1;
+       key = string_term_tdb_data(keystr);
 
        return key;
 }
@@ -250,23 +248,26 @@ static TDB_DATA make_printer_tdbkey( const char *sharename )
  generate a new TDB_DATA key for storing a printer security descriptor
 ****************************************************************************/
 
-static char *make_printers_secdesc_tdbkey( const char* sharename  )
+static TDB_DATA make_printers_secdesc_tdbkey( const char* sharename  )
 {
        fstring share;
        static pstring keystr;
-       
+       TDB_DATA key;
+
        fstrcpy( share, sharename );
        strlower_m( share );
        
        pstr_sprintf( keystr, "%s%s", SECDESC_PREFIX, share );
 
-       return keystr;
+       key = string_term_tdb_data(keystr);
+
+       return key;
 }
 
 /****************************************************************************
 ****************************************************************************/
 
-static BOOL upgrade_to_version_3(void)
+static bool upgrade_to_version_3(void)
 {
        TDB_DATA kbuf, newkey, dbuf;
  
@@ -277,7 +278,7 @@ static BOOL upgrade_to_version_3(void)
 
                dbuf = tdb_fetch(tdb_drivers, kbuf);
 
-               if (strncmp(kbuf.dptr, FORMS_PREFIX, strlen(FORMS_PREFIX)) == 0) {
+               if (strncmp((const char *)kbuf.dptr, FORMS_PREFIX, strlen(FORMS_PREFIX)) == 0) {
                        DEBUG(0,("upgrade_to_version_3:moving form\n"));
                        if (tdb_store(tdb_forms, kbuf, dbuf, TDB_REPLACE) != 0) {
                                SAFE_FREE(dbuf.dptr);
@@ -291,7 +292,7 @@ static BOOL upgrade_to_version_3(void)
                        }
                }
  
-               if (strncmp(kbuf.dptr, PRINTERS_PREFIX, strlen(PRINTERS_PREFIX)) == 0) {
+               if (strncmp((const char *)kbuf.dptr, PRINTERS_PREFIX, strlen(PRINTERS_PREFIX)) == 0) {
                        DEBUG(0,("upgrade_to_version_3:moving printer\n"));
                        if (tdb_store(tdb_printers, kbuf, dbuf, TDB_REPLACE) != 0) {
                                SAFE_FREE(dbuf.dptr);
@@ -305,7 +306,7 @@ static BOOL upgrade_to_version_3(void)
                        }
                }
  
-               if (strncmp(kbuf.dptr, SECDESC_PREFIX, strlen(SECDESC_PREFIX)) == 0) {
+               if (strncmp((const char *)kbuf.dptr, SECDESC_PREFIX, strlen(SECDESC_PREFIX)) == 0) {
                        DEBUG(0,("upgrade_to_version_3:moving secdesc\n"));
                        if (tdb_store(tdb_printers, kbuf, dbuf, TDB_REPLACE) != 0) {
                                SAFE_FREE(dbuf.dptr);
@@ -350,7 +351,7 @@ static int sec_desc_upg_fn( TDB_CONTEXT *the_tdb, TDB_DATA key,
                return 0;
        }
 
-       if ( strncmp( key.dptr, SECDESC_PREFIX, strlen(SECDESC_PREFIX) ) != 0 ) {
+       if ( strncmp((const char *) key.dptr, SECDESC_PREFIX, strlen(SECDESC_PREFIX) ) != 0 ) {
                return 0;
        }
 
@@ -359,11 +360,12 @@ static int sec_desc_upg_fn( TDB_CONTEXT *the_tdb, TDB_DATA key,
        ZERO_STRUCT( ps );
 
        prs_init( &ps, 0, ctx, UNMARSHALL );
-       prs_give_memory( &ps, data.dptr, data.dsize, False );
+       prs_give_memory( &ps, (char *)data.dptr, data.dsize, False );
 
        if ( !sec_io_desc_buf( "sec_desc_upg_fn", &sd_orig, &ps, 1 ) ) {
                /* delete bad entries */
-               DEBUG(0,("sec_desc_upg_fn: Failed to parse original sec_desc for %si.  Deleting....\n", key.dptr ));
+               DEBUG(0,("sec_desc_upg_fn: Failed to parse original sec_desc for %si.  Deleting....\n",
+                       (const char *)key.dptr ));
                tdb_delete( tdb_printers, key );
                prs_mem_free( &ps );
                return 0;
@@ -437,7 +439,7 @@ static int sec_desc_upg_fn( TDB_CONTEXT *the_tdb, TDB_DATA key,
                return 0;
        }
 
-       data.dptr = prs_data_p( &ps );
+       data.dptr = (uint8 *)prs_data_p( &ps );
        data.dsize = sd_size;
        
        result = tdb_store( tdb_printers, key, data, TDB_REPLACE );
@@ -452,7 +454,7 @@ static int sec_desc_upg_fn( TDB_CONTEXT *the_tdb, TDB_DATA key,
 /*******************************************************************
 *******************************************************************/
 
-static BOOL upgrade_to_version_4(void)
+static bool upgrade_to_version_4(void)
 {
        TALLOC_CTX *ctx;
        int result;
@@ -487,12 +489,11 @@ static int normalize_printers_fn( TDB_CONTEXT *the_tdb, TDB_DATA key,
 
        /* upgrade printer records and security descriptors */
        
-       if ( strncmp( key.dptr, PRINTERS_PREFIX, strlen(PRINTERS_PREFIX) ) == 0 ) {
-               new_key = make_printer_tdbkey( key.dptr+strlen(PRINTERS_PREFIX) );
+       if ( strncmp((const char *) key.dptr, PRINTERS_PREFIX, strlen(PRINTERS_PREFIX) ) == 0 ) {
+               new_key = make_printer_tdbkey( (const char *)key.dptr+strlen(PRINTERS_PREFIX) );
        }
-       else if ( strncmp( key.dptr, SECDESC_PREFIX, strlen(SECDESC_PREFIX) ) == 0 ) {
-               new_key.dptr = make_printers_secdesc_tdbkey( key.dptr+strlen(SECDESC_PREFIX) );
-               new_key.dsize = strlen( new_key.dptr ) + 1;
+       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) );
        }
        else {
                /* ignore this record */
@@ -519,7 +520,7 @@ static int normalize_printers_fn( TDB_CONTEXT *the_tdb, TDB_DATA key,
 /*******************************************************************
 *******************************************************************/
 
-static BOOL upgrade_to_version_5(void)
+static bool upgrade_to_version_5(void)
 {
        TALLOC_CTX *ctx;
        int result;
@@ -540,7 +541,7 @@ static BOOL upgrade_to_version_5(void)
  Open the NT printing tdbs. Done once before fork().
 ****************************************************************************/
 
-BOOL nt_printing_init(void)
+bool nt_printing_init(struct messaging_context *msg_ctx)
 {
        const char *vstring = "INFO/version";
        WERROR win_rc;
@@ -629,14 +630,16 @@ BOOL nt_printing_init(void)
         * drivers are installed
         */
 
-       message_register( MSG_PRINTER_DRVUPGRADE, do_drv_upgrade_printer );
+       messaging_register(msg_ctx, NULL, MSG_PRINTER_DRVUPGRADE,
+                          do_drv_upgrade_printer);
 
        /*
         * register callback to handle updating printer data
         * when a driver is initialized
         */
 
-       message_register( MSG_PRINTERDATA_INIT_RESET, reset_all_printerdata );
+       messaging_register(msg_ctx, NULL, MSG_PRINTERDATA_INIT_RESET,
+                          reset_all_printerdata);
 
        /* of course, none of the message callbacks matter if you don't
           tell messages.c that you interested in receiving PRINT_GENERAL 
@@ -656,13 +659,18 @@ BOOL nt_printing_init(void)
  Function to allow filename parsing "the old way".
 ********************************************************************/
 
-static BOOL driver_unix_convert(char *name,connection_struct *conn,
-               char *saved_last_component, BOOL *bad_path, SMB_STRUCT_STAT *pst)
+static void driver_unix_convert(connection_struct *conn,
+               pstring name,
+               SMB_STRUCT_STAT *pst)
 {
+       char *new_name = NULL;
        unix_format(name);
        unix_clean_name(name);
        trim_string(name,"/","/");
-       return unix_convert(name, conn, saved_last_component, bad_path, pst);
+       unix_convert(talloc_tos(),conn, name, False, &new_name, NULL, pst);
+       if (new_name) {
+               pstrcpy(name, new_name);
+       }
 }
 
 /*******************************************************************
@@ -689,7 +697,7 @@ static int traverse_counting_printers(TDB_CONTEXT *t, TDB_DATA key,
  each add or delete printer RPC. Only Microsoft knows why... JRR020119
 ********************************************************************/
 
-uint32 update_c_setprinter(BOOL initialize)
+uint32 update_c_setprinter(bool initialize)
 {
        int32 c_setprinter;
        int32 printer_count = 0;
@@ -748,11 +756,11 @@ int get_builtin_ntforms(nt_forms_struct **list)
  get a builtin form struct
 ****************************************************************************/
 
-BOOL get_a_builtin_ntform(UNISTR2 *uni_formname,nt_forms_struct *form)
+bool get_a_builtin_ntform(UNISTR2 *uni_formname,nt_forms_struct *form)
 {
        int i,count;
        fstring form_name;
-       unistr2_to_ascii(form_name, uni_formname, sizeof(form_name)-1);
+       unistr2_to_ascii(form_name, uni_formname, sizeof(form_name));
        DEBUGADD(6,("Looking for builtin form %s \n", form_name));
        count = sizeof(default_forms) / sizeof(default_forms[0]);
        for (i=0;i<count;i++) {
@@ -784,14 +792,14 @@ int get_ntforms(nt_forms_struct **list)
             kbuf.dptr;
             newkey = tdb_nextkey(tdb_forms, kbuf), safe_free(kbuf.dptr), kbuf=newkey) 
        {
-               if (strncmp(kbuf.dptr, FORMS_PREFIX, strlen(FORMS_PREFIX)) != 0) 
+               if (strncmp((const char *)kbuf.dptr, FORMS_PREFIX, strlen(FORMS_PREFIX)) != 0) 
                        continue;
                
                dbuf = tdb_fetch(tdb_forms, kbuf);
                if (!dbuf.dptr) 
                        continue;
 
-               fstrcpy(form.name, kbuf.dptr+strlen(FORMS_PREFIX));
+               fstrcpy(form.name, (const char *)kbuf.dptr+strlen(FORMS_PREFIX));
                ret = tdb_unpack(dbuf.dptr, dbuf.dsize, "dddddddd",
                                 &i, &form.flag, &form.width, &form.length, &form.left,
                                 &form.top, &form.right, &form.bottom);
@@ -819,22 +827,20 @@ int write_ntforms(nt_forms_struct **list, int number)
 {
        pstring buf, key;
        int len;
-       TDB_DATA kbuf,dbuf;
+       TDB_DATA dbuf;
        int i;
 
        for (i=0;i<number;i++) {
                /* save index, so list is rebuilt in correct order */
-               len = tdb_pack(buf, sizeof(buf), "dddddddd",
+               len = tdb_pack((uint8 *)buf, sizeof(buf), "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);
-               kbuf.dsize = strlen(key)+1;
-               kbuf.dptr = key;
                dbuf.dsize = len;
-               dbuf.dptr = buf;
-               if (tdb_store(tdb_forms, kbuf, dbuf, TDB_REPLACE) != 0) break;
+               dbuf.dptr = (uint8 *)buf;
+               if (tdb_store_bystring(tdb_forms, key, dbuf, TDB_REPLACE) != 0) break;
        }
 
        return i;
@@ -843,10 +849,10 @@ int write_ntforms(nt_forms_struct **list, int number)
 /****************************************************************************
 add a form struct at the end of the list
 ****************************************************************************/
-BOOL add_a_form(nt_forms_struct **list, const FORM *form, int *count)
+bool add_a_form(nt_forms_struct **list, const FORM *form, int *count)
 {
        int n=0;
-       BOOL update;
+       bool update;
        fstring form_name;
 
        /*
@@ -857,7 +863,7 @@ BOOL add_a_form(nt_forms_struct **list, const FORM *form, int *count)
 
        update=False;
        
-       unistr2_to_ascii(form_name, &form->name, sizeof(form_name)-1);
+       unistr2_to_ascii(form_name, &form->name, sizeof(form_name));
        for (n=0; n<*count; n++) {
                if ( strequal((*list)[n].name, form_name) ) {
                        update=True;
@@ -870,7 +876,7 @@ BOOL add_a_form(nt_forms_struct **list, const FORM *form, int *count)
                        DEBUG(0,("add_a_form: failed to enlarge forms list!\n"));
                        return False;
                }
-               unistr2_to_ascii((*list)[n].name, &form->name, sizeof((*list)[n].name)-1);
+               unistr2_to_ascii((*list)[n].name, &form->name, sizeof((*list)[n].name));
                (*count)++;
        }
        
@@ -892,16 +898,15 @@ BOOL add_a_form(nt_forms_struct **list, const FORM *form, int *count)
  Delete a named form struct.
 ****************************************************************************/
 
-BOOL delete_a_form(nt_forms_struct **list, UNISTR2 *del_name, int *count, WERROR *ret)
+bool delete_a_form(nt_forms_struct **list, UNISTR2 *del_name, int *count, WERROR *ret)
 {
        pstring key;
-       TDB_DATA kbuf;
        int n=0;
        fstring form_name;
 
        *ret = WERR_OK;
 
-       unistr2_to_ascii(form_name, del_name, sizeof(form_name)-1);
+       unistr2_to_ascii(form_name, del_name, sizeof(form_name));
 
        for (n=0; n<*count; n++) {
                if (!strncmp((*list)[n].name, form_name, strlen(form_name))) {
@@ -917,9 +922,7 @@ BOOL delete_a_form(nt_forms_struct **list, UNISTR2 *del_name, int *count, WERROR
        }
 
        slprintf(key, sizeof(key)-1, "%s%s", FORMS_PREFIX, (*list)[n].name);
-       kbuf.dsize = strlen(key)+1;
-       kbuf.dptr = key;
-       if (tdb_delete(tdb_forms, kbuf) != 0) {
+       if (tdb_delete_bystring(tdb_forms, key) != 0) {
                *ret = WERR_NOMEM;
                return False;
        }
@@ -935,7 +938,7 @@ void update_a_form(nt_forms_struct **list, const FORM *form, int count)
 {
        int n=0;
        fstring form_name;
-       unistr2_to_ascii(form_name, &(form->name), sizeof(form_name)-1);
+       unistr2_to_ascii(form_name, &(form->name), sizeof(form_name));
 
        DEBUG(106, ("[%s]\n", form_name));
        for (n=0; n<count; n++) {
@@ -977,7 +980,7 @@ int get_ntdrivers(fstring **list, const char *architecture, uint32 version)
             kbuf.dptr;
             newkey = tdb_nextkey(tdb_drivers, kbuf), safe_free(kbuf.dptr), kbuf=newkey) {
 
-               if (strncmp(kbuf.dptr, key, strlen(key)) != 0)
+               if (strncmp((const char *)kbuf.dptr, key, strlen(key)) != 0)
                        continue;
                
                if((*list = SMB_REALLOC_ARRAY(*list, fstring, total+1)) == NULL) {
@@ -985,7 +988,7 @@ int get_ntdrivers(fstring **list, const char *architecture, uint32 version)
                        return -1;
                }
 
-               fstrcpy((*list)[total], kbuf.dptr+strlen(key));
+               fstrcpy((*list)[total], (const char *)kbuf.dptr+strlen(key));
                total++;
        }
 
@@ -1035,13 +1038,12 @@ static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32
        char    *buf = NULL;
        ssize_t byte_count;
 
-       if ((buf=(char *)SMB_MALLOC(PE_HEADER_SIZE)) == NULL) {
-               DEBUG(0,("get_file_version: PE file [%s] PE Header malloc failed bytes = %d\n",
-                               fname, PE_HEADER_SIZE));
+       if ((buf=(char *)SMB_MALLOC(DOS_HEADER_SIZE)) == NULL) {
+               DEBUG(0,("get_file_version: PE file [%s] DOS Header malloc failed bytes = %d\n",
+                               fname, DOS_HEADER_SIZE));
                goto error_exit;
        }
 
-       /* Note: DOS_HEADER_SIZE < malloc'ed PE_HEADER_SIZE */
        if ((byte_count = vfs_read_data(fsp, buf, DOS_HEADER_SIZE)) < DOS_HEADER_SIZE) {
                DEBUG(3,("get_file_version: File [%s] DOS header too short, bytes read = %lu\n",
                         fname, (unsigned long)byte_count));
@@ -1063,7 +1065,8 @@ static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32
                goto no_version_info;
        }
 
-       if ((byte_count = vfs_read_data(fsp, buf, PE_HEADER_SIZE)) < PE_HEADER_SIZE) {
+       /* Note: DOS_HEADER_SIZE and NE_HEADER_SIZE are incidentally same */
+       if ((byte_count = vfs_read_data(fsp, buf, NE_HEADER_SIZE)) < NE_HEADER_SIZE) {
                DEBUG(3,("get_file_version: File [%s] Windows header too short, bytes read = %lu\n",
                         fname, (unsigned long)byte_count));
                /* Assume this isn't an error... the file just looks sort of like a PE/NE file */
@@ -1074,13 +1077,13 @@ static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32
        if (IVAL(buf,PE_HEADER_SIGNATURE_OFFSET) == PE_HEADER_SIGNATURE) {
                unsigned int num_sections;
                unsigned int section_table_bytes;
-               
-               if (SVAL(buf,PE_HEADER_MACHINE_OFFSET) != PE_HEADER_MACHINE_I386) {
-                       DEBUG(3,("get_file_version: PE file [%s] wrong machine = 0x%x\n",
-                                       fname, SVAL(buf,PE_HEADER_MACHINE_OFFSET)));
-                       /* At this point, we assume the file is in error. It still could be somthing
-                        * else besides a PE file, but it unlikely at this point.
-                        */
+
+               /* Just skip over optional header to get to section table */
+               if (SMB_VFS_LSEEK(fsp, fsp->fh->fd,
+                               SVAL(buf,PE_HEADER_OPTIONAL_HEADER_SIZE)-(NE_HEADER_SIZE-PE_HEADER_SIZE),
+                               SEEK_CUR) == (SMB_OFF_T)-1) {
+                       DEBUG(3,("get_file_version: File [%s] Windows optional header too short, errno = %d\n",
+                               fname, errno));
                        goto error_exit;
                }
 
@@ -1265,7 +1268,7 @@ the modification date). Otherwise chose the numerically larger version number.
 
 static int file_version_is_newer(connection_struct *conn, fstring new_file, fstring old_file)
 {
-       BOOL   use_version = True;
+       bool   use_version = True;
        pstring filepath;
 
        uint32 new_major;
@@ -1279,7 +1282,6 @@ static int file_version_is_newer(connection_struct *conn, fstring new_file, fstr
        files_struct    *fsp = NULL;
        SMB_STRUCT_STAT st;
        SMB_STRUCT_STAT stat_buf;
-       BOOL bad_path;
 
        NTSTATUS status;
 
@@ -1291,9 +1293,9 @@ static int file_version_is_newer(connection_struct *conn, fstring new_file, fstr
        /* Get file version info (if available) for previous file (if it exists) */
        pstrcpy(filepath, old_file);
 
-       driver_unix_convert(filepath,conn,NULL,&bad_path,&stat_buf);
+       driver_unix_convert(conn,filepath,&stat_buf);
 
-       status = open_file_ntcreate(conn, filepath, &stat_buf,
+       status = open_file_ntcreate(conn, NULL, filepath, &stat_buf,
                                FILE_GENERIC_READ,
                                FILE_SHARE_READ|FILE_SHARE_WRITE,
                                FILE_OPEN,
@@ -1327,9 +1329,9 @@ static int file_version_is_newer(connection_struct *conn, fstring new_file, fstr
 
        /* Get file version info (if available) for new file */
        pstrcpy(filepath, new_file);
-       driver_unix_convert(filepath,conn,NULL,&bad_path,&stat_buf);
+       driver_unix_convert(conn,filepath,&stat_buf);
 
-       status = open_file_ntcreate(conn, filepath, &stat_buf,
+       status = open_file_ntcreate(conn, NULL, filepath, &stat_buf,
                                FILE_GENERIC_READ,
                                FILE_SHARE_READ|FILE_SHARE_WRITE,
                                FILE_OPEN,
@@ -1404,7 +1406,6 @@ static uint32 get_correct_cversion(const char *architecture, fstring driverpath_
        DATA_BLOB         null_pw;
        fstring           res_type;
        files_struct      *fsp = NULL;
-       BOOL              bad_path;
        SMB_STRUCT_STAT   st;
        connection_struct *conn;
        NTSTATUS status;
@@ -1433,7 +1434,7 @@ static uint32 get_correct_cversion(const char *architecture, fstring driverpath_
         */
 
        /* Null password is ok - we are already an authenticated user... */
-       null_pw = data_blob(NULL, 0);
+       null_pw = data_blob_null;
        fstrcpy(res_type, "A:");
        become_root();
        conn = make_connection_with_chdir("print$", null_pw, res_type, user->vuid, &nt_status);
@@ -1456,14 +1457,14 @@ static uint32 get_correct_cversion(const char *architecture, fstring driverpath_
         * deriver the cversion. */
        slprintf(driverpath, sizeof(driverpath)-1, "%s/%s", architecture, driverpath_in);
 
-       driver_unix_convert(driverpath,conn,NULL,&bad_path,&st);
+       driver_unix_convert(conn,driverpath,&st);
 
        if ( !vfs_file_exist( conn, driverpath, &st ) ) {
                *perr = WERR_BADFILE;
                goto error_exit;
        }
 
-       status = open_file_ntcreate(conn, driverpath, &st,
+       status = open_file_ntcreate(conn, NULL, driverpath, &st,
                                FILE_GENERIC_READ,
                                FILE_SHARE_READ|FILE_SHARE_WRITE,
                                FILE_OPEN,
@@ -1742,11 +1743,10 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
        pstring inbuf;
        pstring outbuf;
        fstring res_type;
-       BOOL bad_path;
        SMB_STRUCT_STAT st;
        int ver = 0;
        int i;
-       int err;
+       TALLOC_CTX *ctx = talloc_tos();
 
        memset(inbuf, '\0', sizeof(inbuf));
        memset(outbuf, '\0', sizeof(outbuf));
@@ -1772,7 +1772,7 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
         * Note we must be root to do this.
         */
 
-       null_pw = data_blob(NULL, 0);
+       null_pw = data_blob_null;
        fstrcpy(res_type, "A:");
        become_root();
        conn = make_connection_with_chdir("print$", null_pw, res_type, user->vuid, &nt_status);
@@ -1799,8 +1799,8 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
         */
        DEBUG(5,("Creating first directory\n"));
        slprintf(new_dir, sizeof(new_dir)-1, "%s/%d", architecture, driver->cversion);
-       driver_unix_convert(new_dir, conn, NULL, &bad_path, &st);
-       mkdir_internal(conn, new_dir, bad_path);
+       driver_unix_convert(conn,new_dir,&st);
+       create_directory(conn, new_dir);
 
        /* For each driver file, archi\filexxx.yyy, if there is a duplicate file
         * listed for this driver which has already been moved, skip it (note:
@@ -1825,9 +1825,9 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
                slprintf(new_name, sizeof(new_name)-1, "%s/%s", architecture, driver->driverpath);      
                slprintf(old_name, sizeof(old_name)-1, "%s/%s", new_dir, driver->driverpath);   
                if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
-                       driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
-                       if ( !copy_file(new_name, old_name, conn, OPENX_FILE_EXISTS_TRUNCATE|
-                                               OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False, &err) ) {
+                       driver_unix_convert(conn,new_name,&st);
+                       if ( !NT_STATUS_IS_OK(copy_file(ctx,conn, new_name, old_name, OPENX_FILE_EXISTS_TRUNCATE|
+                                               OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False))) {
                                DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
                                                new_name, old_name));
                                *perr = WERR_ACCESS_DENIED;
@@ -1841,9 +1841,9 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
                        slprintf(new_name, sizeof(new_name)-1, "%s/%s", architecture, driver->datafile);        
                        slprintf(old_name, sizeof(old_name)-1, "%s/%s", new_dir, driver->datafile);     
                        if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
-                               driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
-                               if ( !copy_file(new_name, old_name, conn, OPENX_FILE_EXISTS_TRUNCATE|
-                                               OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False, &err) ) {
+                               driver_unix_convert(conn,new_name,&st);
+                               if ( !NT_STATUS_IS_OK(copy_file(ctx,conn, new_name, old_name, OPENX_FILE_EXISTS_TRUNCATE|
+                                               OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False))) {
                                        DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
                                                        new_name, old_name));
                                        *perr = WERR_ACCESS_DENIED;
@@ -1859,9 +1859,9 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
                        slprintf(new_name, sizeof(new_name)-1, "%s/%s", architecture, driver->configfile);      
                        slprintf(old_name, sizeof(old_name)-1, "%s/%s", new_dir, driver->configfile);   
                        if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
-                               driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
-                               if ( !copy_file(new_name, old_name, conn, OPENX_FILE_EXISTS_TRUNCATE|
-                                               OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False, &err) ) {
+                               driver_unix_convert(conn,new_name,&st);
+                               if ( !NT_STATUS_IS_OK(copy_file(ctx,conn, new_name, old_name, OPENX_FILE_EXISTS_TRUNCATE|
+                                               OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False))) {
                                        DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
                                                        new_name, old_name));
                                        *perr = WERR_ACCESS_DENIED;
@@ -1878,9 +1878,9 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
                        slprintf(new_name, sizeof(new_name)-1, "%s/%s", architecture, driver->helpfile);        
                        slprintf(old_name, sizeof(old_name)-1, "%s/%s", new_dir, driver->helpfile);     
                        if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
-                               driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
-                               if ( !copy_file(new_name, old_name, conn, OPENX_FILE_EXISTS_TRUNCATE|
-                                               OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False, &err) ) {
+                               driver_unix_convert(conn,new_name,&st);
+                               if ( !NT_STATUS_IS_OK(copy_file(ctx,conn, new_name, old_name, OPENX_FILE_EXISTS_TRUNCATE|
+                                               OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False))) {
                                        DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
                                                        new_name, old_name));
                                        *perr = WERR_ACCESS_DENIED;
@@ -1906,10 +1906,10 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
                                slprintf(new_name, sizeof(new_name)-1, "%s/%s", architecture, driver->dependentfiles[i]);       
                                slprintf(old_name, sizeof(old_name)-1, "%s/%s", new_dir, driver->dependentfiles[i]);    
                                if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
-                                       driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
-                                       if ( !copy_file(new_name, old_name, conn,
+                                       driver_unix_convert(conn,new_name,&st);
+                                       if ( !NT_STATUS_IS_OK(copy_file(ctx,conn, new_name, old_name,
                                                        OPENX_FILE_EXISTS_TRUNCATE|
-                                                       OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False, &err) ) {
+                                                       OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False))) {
                                                DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
                                                                new_name, old_name));
                                                *perr = WERR_ACCESS_DENIED;
@@ -1936,9 +1936,9 @@ static uint32 add_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 *driver)
        pstring directory;
        fstring temp_name;
        pstring key;
-       char *buf;
+       uint8 *buf;
        int i, ret;
-       TDB_DATA kbuf, dbuf;
+       TDB_DATA dbuf;
 
        architecture = get_short_archi(driver->environment);
        if (!architecture) {
@@ -2013,7 +2013,7 @@ static uint32 add_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 *driver)
        }
 
        if (len != buflen) {
-               buf = (char *)SMB_REALLOC(buf, len);
+               buf = (uint8 *)SMB_REALLOC(buf, len);
                if (!buf) {
                        DEBUG(0,("add_a_printer_driver_3: failed to enlarge buffer\n!"));
                        ret = -1;
@@ -2023,13 +2023,10 @@ static uint32 add_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 *driver)
                goto again;
        }
 
-
-       kbuf.dptr = key;
-       kbuf.dsize = strlen(key)+1;
        dbuf.dptr = buf;
        dbuf.dsize = len;
        
-       ret = tdb_store(tdb_drivers, kbuf, dbuf, TDB_REPLACE);
+       ret = tdb_store_bystring(tdb_drivers, key, dbuf, TDB_REPLACE);
 
 done:
        if (ret)
@@ -2097,7 +2094,7 @@ static WERROR get_a_printer_driver_3_default(NT_PRINTER_DRIVER_INFO_LEVEL_3 **in
 static WERROR get_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 **info_ptr, fstring drivername, const char *arch, uint32 version)
 {
        NT_PRINTER_DRIVER_INFO_LEVEL_3 driver;
-       TDB_DATA kbuf, dbuf;
+       TDB_DATA dbuf;
        const char *architecture;
        int len = 0;
        int i;
@@ -2118,11 +2115,8 @@ static WERROR get_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 **info_ptr,
        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);
-
-       kbuf.dptr = key;
-       kbuf.dsize = strlen(key)+1;
        
-       dbuf = tdb_fetch(tdb_drivers, kbuf);
+       dbuf = tdb_fetch_bystring(tdb_drivers, key);
        if (!dbuf.dptr) 
                return WERR_UNKNOWN_PRINTER_DRIVER;
 
@@ -2221,7 +2215,7 @@ static uint32 dump_a_printer_driver(NT_PRINTER_DRIVER_INFO_LEVEL driver, uint32
 
 /****************************************************************************
 ****************************************************************************/
-int pack_devicemode(NT_DEVICEMODE *nt_devmode, char *buf, int buflen)
+int pack_devicemode(NT_DEVICEMODE *nt_devmode, uint8 *buf, int buflen)
 {
        int len = 0;
 
@@ -2285,7 +2279,7 @@ int pack_devicemode(NT_DEVICEMODE *nt_devmode, char *buf, int buflen)
  Pack all values in all printer keys
  ***************************************************************************/
  
-static int pack_values(NT_PRINTER_DATA *data, char *buf, int buflen)
+static int pack_values(NT_PRINTER_DATA *data, uint8 *buf, int buflen)
 {
        int             len = 0;
        int             i, j;
@@ -2355,8 +2349,7 @@ uint32 del_a_printer(const char *sharename)
        kbuf = make_printer_tdbkey( sharename );
        tdb_delete(tdb_printers, kbuf);
 
-       kbuf.dptr = make_printers_secdesc_tdbkey( sharename );
-       kbuf.dsize = strlen(kbuf.dptr) + 1;
+       kbuf= make_printers_secdesc_tdbkey( sharename );
        tdb_delete(tdb_printers, kbuf);
 
        close_all_print_db();
@@ -2376,7 +2369,7 @@ uint32 del_a_printer(const char *sharename)
 ****************************************************************************/
 static WERROR update_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info)
 {
-       char *buf;
+       uint8 *buf;
        int buflen, len;
        WERROR ret;
        TDB_DATA kbuf, dbuf;
@@ -2443,7 +2436,7 @@ static WERROR update_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info)
        len += pack_values( info->data, buf+len, buflen-len );
 
        if (buflen != len) {
-               buf = (char *)SMB_REALLOC(buf, len);
+               buf = (uint8 *)SMB_REALLOC(buf, len);
                if (!buf) {
                        DEBUG(0,("update_a_printer_2: failed to enlarge buffer!\n"));
                        ret = WERR_NOMEM;
@@ -2601,7 +2594,7 @@ static void free_nt_printer_info_level_2(NT_PRINTER_INFO_LEVEL_2 **info_ptr)
 
 /****************************************************************************
 ****************************************************************************/
-int unpack_devicemode(NT_DEVICEMODE **nt_devmode, char *buf, int buflen)
+int unpack_devicemode(NT_DEVICEMODE **nt_devmode, const uint8 *buf, int buflen)
 {
        int len = 0;
        int extra_len = 0;
@@ -2898,7 +2891,7 @@ static void map_dword_into_ctr(REGVAL_CTR *ctr, const char *val_name,
 }
 
 static void map_bool_into_ctr(REGVAL_CTR *ctr, const char *val_name,
-                             BOOL b)
+                             bool b)
 {
        uint8 bin_bool = (b ? 1 : 0);
        regval_ctr_delvalue(ctr, val_name);
@@ -2936,10 +2929,10 @@ static void map_single_multi_sz_into_ctr(REGVAL_CTR *ctr, const char *val_name,
  * Map the NT_PRINTER_INFO_LEVEL_2 data into DsSpooler keys for publishing.
  *
  * @param info2 NT_PRINTER_INFO_LEVEL_2 describing printer - gets modified
- * @return BOOL indicating success or failure
+ * @return bool indicating success or failure
  ***************************************************************************/
 
-static BOOL map_nt_printer_info2_to_dsspooler(NT_PRINTER_INFO_LEVEL_2 *info2)
+static bool map_nt_printer_info2_to_dsspooler(NT_PRINTER_INFO_LEVEL_2 *info2)
 {
        REGVAL_CTR *ctr = NULL;
        fstring longname;
@@ -3002,11 +2995,15 @@ static BOOL map_nt_printer_info2_to_dsspooler(NT_PRINTER_INFO_LEVEL_2 *info2)
        return True;
 }
 
+/*****************************************************************
+ ****************************************************************/
+
 static void store_printer_guid(NT_PRINTER_INFO_LEVEL_2 *info2, 
                               struct GUID guid)
 {
        int i;
        REGVAL_CTR *ctr=NULL;
+       UNISTR2 unistr_guid;
 
        /* find the DsSpooler key */
        if ((i = lookup_printerkey(info2->data, SPOOL_DSSPOOLER_KEY)) < 0)
@@ -3014,8 +3011,18 @@ static void store_printer_guid(NT_PRINTER_INFO_LEVEL_2 *info2,
        ctr = info2->data->keys[i].values;
 
        regval_ctr_delvalue(ctr, "objectGUID");
-       regval_ctr_addvalue(ctr, "objectGUID", REG_BINARY, 
-                           (char *) &guid, sizeof(struct GUID));       
+
+       /* We used to store this as a REG_BINARY but that causes
+          Vista to whine */
+
+       ZERO_STRUCT( unistr_guid );     
+       init_unistr2( &unistr_guid, smb_uuid_string_static(guid),
+                     UNI_STR_TERMINATE );
+
+       regval_ctr_addvalue(ctr, "objectGUID", REG_SZ, 
+                           (char *)unistr_guid.buffer, 
+                           unistr_guid.uni_max_len*2);
+       
 }
 
 static WERROR nt_printer_publish_ads(ADS_STRUCT *ads,
@@ -3023,7 +3030,7 @@ static WERROR nt_printer_publish_ads(ADS_STRUCT *ads,
 {
        ADS_STATUS ads_rc;
        LDAPMessage *res;
-       char *prt_dn = NULL, *srv_dn, *srv_cn_0;
+       char *prt_dn = NULL, *srv_dn, *srv_cn_0, *srv_cn_escaped, *sharename_escaped;
        char *srv_dn_utf8, **srv_cn_utf8;
        TALLOC_CTX *ctx;
        ADS_MODLIST mods;
@@ -3039,7 +3046,7 @@ static WERROR nt_printer_publish_ads(ADS_STRUCT *ads,
        /* We use ldap_get_dn here as we need the answer
         * in utf8 to call ldap_explode_dn(). JRA. */
 
-       srv_dn_utf8 = ldap_get_dn((LDAP *)ads->ld, (LDAPMessage *)res);
+       srv_dn_utf8 = ldap_get_dn((LDAP *)ads->ldap.ld, (LDAPMessage *)res);
        if (!srv_dn_utf8) {
                ads_destroy(&ads);
                return WERR_SERVER_UNAVAILABLE;
@@ -3069,11 +3076,29 @@ static WERROR nt_printer_publish_ads(ADS_STRUCT *ads,
        ldap_memfree(srv_dn_utf8);
        ldap_memfree(srv_cn_utf8);
 
-       asprintf(&prt_dn, "cn=%s-%s,%s", srv_cn_0, 
-                printer->info_2->sharename, srv_dn);
+       srv_cn_escaped = escape_rdn_val_string_alloc(srv_cn_0);
+       if (!srv_cn_escaped) {
+               SAFE_FREE(srv_cn_0);
+               ldap_memfree(srv_dn_utf8);
+               ads_destroy(&ads);
+               return WERR_SERVER_UNAVAILABLE;
+       }
+       sharename_escaped = escape_rdn_val_string_alloc(printer->info_2->sharename);
+       if (!sharename_escaped) {
+               SAFE_FREE(srv_cn_escaped);
+               SAFE_FREE(srv_cn_0);
+               ldap_memfree(srv_dn_utf8);
+               ads_destroy(&ads);
+               return WERR_SERVER_UNAVAILABLE;
+       }
+
+
+       asprintf(&prt_dn, "cn=%s-%s,%s", srv_cn_escaped, sharename_escaped, srv_dn);
 
        SAFE_FREE(srv_dn);
        SAFE_FREE(srv_cn_0);
+       SAFE_FREE(srv_cn_escaped);
+       SAFE_FREE(sharename_escaped);
 
        /* build the ads mods */
        ctx = talloc_init("nt_printer_publish_ads");
@@ -3245,6 +3270,7 @@ WERROR check_published_printers(void)
        if (!ADS_ERR_OK(ads_rc)) {
                DEBUG(3, ("ads_connect failed: %s\n", ads_errstr(ads_rc)));
                ads_destroy(&ads);
+               ads_kdestroy("MEMORY:prtpub_cache");
                return WERR_ACCESS_DENIED;
        }
 
@@ -3261,10 +3287,11 @@ WERROR check_published_printers(void)
        }
 
        ads_destroy(&ads);
+       ads_kdestroy("MEMORY:prtpub_cache");
        return WERR_OK;
 }
 
-BOOL is_printer_published(Printer_entry *print_hnd, int snum, 
+bool is_printer_published(Printer_entry *print_hnd, int snum, 
                          struct GUID *guid)
 {
        NT_PRINTER_INFO_LEVEL *printer = NULL;
@@ -3272,6 +3299,7 @@ BOOL is_printer_published(Printer_entry *print_hnd, int snum,
        REGISTRY_VALUE *guid_val;
        WERROR win_rc;
        int i;
+       bool ret = False;
 
        win_rc = get_a_printer(print_hnd, &printer, 2, lp_servicename(snum));
 
@@ -3285,12 +3313,36 @@ BOOL is_printer_published(Printer_entry *print_hnd, int snum,
                return False;
        }
 
-       /* fetching printer guids really ought to be a separate function.. */
-       if (guid && regval_size(guid_val) == sizeof(struct GUID))
-               memcpy(guid, regval_data_p(guid_val), sizeof(struct GUID));
+       /* fetching printer guids really ought to be a separate function. */
+
+       if ( guid ) {   
+               fstring guid_str;
+               
+               /* We used to store the guid as REG_BINARY, then swapped 
+                  to REG_SZ for Vista compatibility so check for both */
+
+               switch ( regval_type(guid_val) ){
+               case REG_SZ:            
+                       rpcstr_pull( guid_str, regval_data_p(guid_val), 
+                                    sizeof(guid_str)-1, -1, STR_TERMINATE );
+                       ret = smb_string_to_uuid( guid_str, guid );
+                       break;                  
+               case REG_BINARY:
+                       if ( regval_size(guid_val) != sizeof(struct GUID) ) {
+                               ret = False;
+                               break;
+                       }
+                       memcpy(guid, regval_data_p(guid_val), sizeof(struct GUID));
+                       break;
+               default:
+                       DEBUG(0,("is_printer_published: GUID value stored as "
+                                "invaluid type (%d)\n", regval_type(guid_val) ));                      
+                       break;
+               }
+       }
 
        free_a_printer(&printer, 2);
-       return True;
+       return ret;
 }
 #else
 WERROR nt_printer_publish(Printer_entry *print_hnd, int snum, int action)
@@ -3303,7 +3355,7 @@ WERROR check_published_printers(void)
        return WERR_OK;
 }
 
-BOOL is_printer_published(Printer_entry *print_hnd, int snum, 
+bool is_printer_published(Printer_entry *print_hnd, int snum, 
                          struct GUID *guid)
 {
        return False;
@@ -3481,7 +3533,7 @@ REGISTRY_VALUE* get_printer_data( NT_PRINTER_INFO_LEVEL_2 *p2, const char *key,
  Unpack a list of registry values frem the TDB
  ***************************************************************************/
  
-static int unpack_values(NT_PRINTER_DATA *printer_data, char *buf, int buflen)
+static int unpack_values(NT_PRINTER_DATA *printer_data, const uint8 *buf, int buflen)
 {
        int             len = 0;
        uint32          type;
@@ -3557,13 +3609,43 @@ static int unpack_values(NT_PRINTER_DATA *printer_data, char *buf, int buflen)
                        break;
                }
                
-               /* add the new value */
+               DEBUG(8,("specific: [%s:%s], len: %d\n", keyname, valuename, size));
+
+               /* Vista doesn't like unknown REG_BINARY values in DsSpooler.  
+                  Thanks to Martin Zielinski for the hint. */
+
+               if ( type == REG_BINARY && 
+                    strequal( keyname, SPOOL_DSSPOOLER_KEY ) && 
+                    strequal( valuename, "objectGUID" ) ) 
+               {
+                       struct GUID guid;
+                       UNISTR2 unistr_guid;
+
+                       ZERO_STRUCT( unistr_guid );
+                       
+                       /* convert the GUID to a UNICODE string */
+                       
+                       memcpy( &guid, data_p, sizeof(struct GUID) );
+                       
+                       init_unistr2( &unistr_guid, smb_uuid_string_static(guid), 
+                                     UNI_STR_TERMINATE );
+                       
+                       regval_ctr_addvalue( printer_data->keys[key_index].values, 
+                                            valuename, REG_SZ, 
+                                            (const char *)unistr_guid.buffer, 
+                                            unistr_guid.uni_str_len*2 );
+
+               } else {
+                       /* add the value */
+
+                       regval_ctr_addvalue( printer_data->keys[key_index].values, 
+                                            valuename, type, (const char *)data_p, 
+                                            size );
+               }
                
-               regval_ctr_addvalue( printer_data->keys[key_index].values, valuename, type, (const char *)data_p, size );
 
                SAFE_FREE(data_p); /* 'B' option to tdbpack does a malloc() */
 
-               DEBUG(8,("specific: [%s:%s], len: %d\n", keyname, valuename, size));
        }
 
        return len;
@@ -3574,7 +3656,7 @@ static int unpack_values(NT_PRINTER_DATA *printer_data, char *buf, int buflen)
 
 static void map_to_os2_driver(fstring drivername)
 {
-       static BOOL initialised=False;
+       static bool initialised=False;
        static fstring last_from,last_to;
        char *mapfile = lp_os2_driver_map();
        char **lines = NULL;
@@ -3659,9 +3741,7 @@ static void map_to_os2_driver(fstring drivername)
 ****************************************************************************/
 static WERROR get_a_printer_2_default(NT_PRINTER_INFO_LEVEL_2 *info, const char *servername, const char* sharename)
 {
-       int snum;
-
-       snum = lp_servicenumber(sharename);
+       int snum = lp_servicenumber(sharename);
 
        slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", servername);
        slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s", 
@@ -3685,6 +3765,15 @@ static WERROR get_a_printer_2_default(NT_PRINTER_INFO_LEVEL_2 *info, const char
        fstrcpy(info->printprocessor, "winprint");
        fstrcpy(info->datatype, "RAW");
 
+#ifdef HAVE_CUPS
+       if ( (enum printing_types)lp_printing(snum) == PRINT_CUPS ) {           
+               /* Pull the location and comment strings from cups if we don't
+                  already have one */
+               if ( !strlen(info->location) || !strlen(info->comment) )
+                       cups_pull_comment_location( info );
+       }
+#endif
+
        info->attributes = PRINTER_ATTRIBUTE_SAMBA;
 
        info->starttime = 0; /* Minutes since 12:00am GMT */
@@ -3780,6 +3869,15 @@ static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info, const char *servern
 
        fstrcpy(info->printername, printername);
 
+#ifdef HAVE_CUPS
+       if ( (enum printing_types)lp_printing(snum) == PRINT_CUPS ) {           
+               /* Pull the location and comment strings from cups if we don't
+                  already have one */
+               if ( !strlen(info->location) || !strlen(info->comment) )
+                       cups_pull_comment_location( info );
+       }
+#endif
+
        len += unpack_devicemode(&info->devmode,dbuf.dptr+len, dbuf.dsize-len);
 
        /*
@@ -3979,11 +4077,11 @@ WERROR mod_a_printer(NT_PRINTER_INFO_LEVEL *printer, uint32 level)
  Initialize printer devmode & data with previously saved driver init values.
 ****************************************************************************/
 
-static BOOL set_driver_init_2( NT_PRINTER_INFO_LEVEL_2 *info_ptr )
+static bool set_driver_init_2( NT_PRINTER_INFO_LEVEL_2 *info_ptr )
 {
        int                     len = 0;
        pstring                 key;
-       TDB_DATA                kbuf, dbuf;
+       TDB_DATA                dbuf;
        NT_PRINTER_INFO_LEVEL_2 info;
 
 
@@ -4000,10 +4098,7 @@ static BOOL set_driver_init_2( NT_PRINTER_INFO_LEVEL_2 *info_ptr )
        
        slprintf(key, sizeof(key)-1, "%s%s", DRIVER_INIT_PREFIX, info_ptr->drivername);
 
-       kbuf.dptr = key;
-       kbuf.dsize = strlen(key)+1;
-
-       dbuf = tdb_fetch(tdb_drivers, kbuf);
+       dbuf = tdb_fetch_bystring(tdb_drivers, key);
        if (!dbuf.dptr) {
                /*
                 * When changing to a driver that has no init info in the tdb, remove
@@ -4071,9 +4166,9 @@ static BOOL set_driver_init_2( NT_PRINTER_INFO_LEVEL_2 *info_ptr )
  is bound to the new printer.
 ****************************************************************************/
 
-BOOL set_driver_init(NT_PRINTER_INFO_LEVEL *printer, uint32 level)
+bool set_driver_init(NT_PRINTER_INFO_LEVEL *printer, uint32 level)
 {
-       BOOL result = False;
+       bool result = False;
        
        switch (level) {
                case 2:
@@ -4093,10 +4188,9 @@ BOOL set_driver_init(NT_PRINTER_INFO_LEVEL *printer, uint32 level)
  Delete driver init data stored for a specified driver
 ****************************************************************************/
 
-BOOL del_driver_init(char *drivername)
+bool del_driver_init(char *drivername)
 {
        pstring key;
-       TDB_DATA kbuf;
 
        if (!drivername || !*drivername) {
                DEBUG(3,("del_driver_init: No drivername specified!\n"));
@@ -4105,12 +4199,9 @@ BOOL del_driver_init(char *drivername)
 
        slprintf(key, sizeof(key)-1, "%s%s", DRIVER_INIT_PREFIX, drivername);
 
-       kbuf.dptr = key;
-       kbuf.dsize = strlen(key)+1;
-
        DEBUG(6,("del_driver_init: Removing driver init data for [%s]\n", drivername));
 
-       return (tdb_delete(tdb_drivers, kbuf) == 0);
+       return (tdb_delete_bystring(tdb_drivers, key) == 0);
 }
 
 /****************************************************************************
@@ -4124,9 +4215,9 @@ BOOL del_driver_init(char *drivername)
 static uint32 update_driver_init_2(NT_PRINTER_INFO_LEVEL_2 *info)
 {
        pstring key;
-       char *buf;
+       uint8 *buf;
        int buflen, len, ret;
-       TDB_DATA kbuf, dbuf;
+       TDB_DATA dbuf;
 
        buf = NULL;
        buflen = 0;
@@ -4138,7 +4229,7 @@ static uint32 update_driver_init_2(NT_PRINTER_INFO_LEVEL_2 *info)
        len += pack_values( info->data, buf+len, buflen-len );
 
        if (buflen < len) {
-               buf = (char *)SMB_REALLOC(buf, len);
+               buf = (uint8 *)SMB_REALLOC(buf, len);
                if (!buf) {
                        DEBUG(0, ("update_driver_init_2: failed to enlarge buffer!\n"));
                        ret = -1;
@@ -4150,12 +4241,10 @@ static uint32 update_driver_init_2(NT_PRINTER_INFO_LEVEL_2 *info)
 
        slprintf(key, sizeof(key)-1, "%s%s", DRIVER_INIT_PREFIX, info->drivername);
 
-       kbuf.dptr = key;
-       kbuf.dsize = strlen(key)+1;
        dbuf.dptr = buf;
        dbuf.dsize = len;
 
-       ret = tdb_store(tdb_drivers, kbuf, dbuf, TDB_REPLACE);
+       ret = tdb_store_bystring(tdb_drivers, key, dbuf, TDB_REPLACE);
 
 done:
        if (ret == -1)
@@ -4197,9 +4286,9 @@ static uint32 update_driver_init(NT_PRINTER_INFO_LEVEL *printer, uint32 level)
  got to keep the endians happy :).
 ****************************************************************************/
 
-static BOOL convert_driver_init( TALLOC_CTX *ctx, NT_DEVICEMODE *nt_devmode, uint8 *data, uint32 data_len )
+static bool convert_driver_init( TALLOC_CTX *ctx, NT_DEVICEMODE *nt_devmode, uint8 *data, uint32 data_len )
 {
-       BOOL       result = False;
+       bool       result = False;
        prs_struct ps;
        DEVICEMODE devmode;
 
@@ -4538,12 +4627,12 @@ uint32 free_a_printer_driver(NT_PRINTER_DRIVER_INFO_LEVEL driver, uint32 level)
   to a printer
 ****************************************************************************/
 
-BOOL printer_driver_in_use ( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3 )
+bool printer_driver_in_use ( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3 )
 {
        int snum;
        int n_services = lp_numservices();
        NT_PRINTER_INFO_LEVEL *printer = NULL;
-       BOOL in_use = False;
+       bool in_use = False;
 
        if ( !info_3 ) 
                return False;
@@ -4614,7 +4703,7 @@ BOOL printer_driver_in_use ( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3 )
  Check to see if a ogiven file is in use by *info
  *********************************************************************/
  
-static BOOL drv_file_in_use( char* file, NT_PRINTER_DRIVER_INFO_LEVEL_3 *info )
+static bool drv_file_in_use( char* file, NT_PRINTER_DRIVER_INFO_LEVEL_3 *info )
 {
        int i = 0;
        
@@ -4672,10 +4761,10 @@ static void trim_dependent_file( fstring files[], int idx )
  Check if any of the files used by src are also used by drv 
  *********************************************************************/
 
-static BOOL trim_overlap_drv_files( NT_PRINTER_DRIVER_INFO_LEVEL_3 *src, 
+static bool trim_overlap_drv_files( NT_PRINTER_DRIVER_INFO_LEVEL_3 *src, 
                                       NT_PRINTER_DRIVER_INFO_LEVEL_3 *drv )
 {
-       BOOL    in_use = False;
+       bool    in_use = False;
        int     i = 0;
        
        if ( !src || !drv )
@@ -4735,7 +4824,7 @@ static BOOL trim_overlap_drv_files( NT_PRINTER_DRIVER_INFO_LEVEL_3 *src,
   which are not in use
 ****************************************************************************/
 
-BOOL printer_driver_files_in_use ( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info )
+bool printer_driver_files_in_use ( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info )
 {
        int                             i;
        int                             ndrivers;
@@ -4804,7 +4893,7 @@ BOOL printer_driver_files_in_use ( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info )
   this.
 ****************************************************************************/
 
-static BOOL delete_driver_files( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, struct current_user *user )
+static bool delete_driver_files( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, struct current_user *user )
 {
        int i = 0;
        char *s;
@@ -4813,7 +4902,6 @@ static BOOL delete_driver_files( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, struct
        DATA_BLOB null_pw;
        NTSTATUS nt_status;
        fstring res_type;
-       BOOL bad_path;
        SMB_STRUCT_STAT  st;
 
        if ( !info_3 )
@@ -4827,7 +4915,7 @@ static BOOL delete_driver_files( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, struct
         * do this.
         */
         
-       null_pw = data_blob( NULL, 0 );
+       null_pw = data_blob_null;
        fstrcpy(res_type, "A:");
        become_root();
         conn = make_connection_with_chdir( "print$", null_pw, res_type, user->vuid, &nt_status );
@@ -4856,36 +4944,36 @@ static BOOL delete_driver_files( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, struct
        if ( *info_3->driverpath ) {
                if ( (s = strchr( &info_3->driverpath[1], '\\' )) != NULL ) {
                        pstrcpy( file, s );
-                       driver_unix_convert(file, conn, NULL, &bad_path, &st);
+                       driver_unix_convert(conn,file,&st);
                        DEBUG(10,("deleting driverfile [%s]\n", s));
-                       unlink_internals(conn, 0, file, False);
+                       unlink_internals(conn, NULL, 0, file, False);
                }
        }
                
        if ( *info_3->configfile ) {
                if ( (s = strchr( &info_3->configfile[1], '\\' )) != NULL ) {
                        pstrcpy( file, s );
-                       driver_unix_convert(file, conn, NULL, &bad_path, &st);
+                       driver_unix_convert(conn,file,&st);
                        DEBUG(10,("deleting configfile [%s]\n", s));
-                       unlink_internals(conn, 0, file, False);
+                       unlink_internals(conn, NULL, 0, file, False);
                }
        }
        
        if ( *info_3->datafile ) {
                if ( (s = strchr( &info_3->datafile[1], '\\' )) != NULL ) {
                        pstrcpy( file, s );
-                       driver_unix_convert(file, conn, NULL, &bad_path, &st);
+                       driver_unix_convert(conn,file,&st);
                        DEBUG(10,("deleting datafile [%s]\n", s));
-                       unlink_internals(conn, 0, file, False);
+                       unlink_internals(conn, NULL, 0, file, False);
                }
        }
        
        if ( *info_3->helpfile ) {
                if ( (s = strchr( &info_3->helpfile[1], '\\' )) != NULL ) {
                        pstrcpy( file, s );
-                       driver_unix_convert(file, conn, NULL, &bad_path, &st);
+                       driver_unix_convert(conn,file,&st);
                        DEBUG(10,("deleting helpfile [%s]\n", s));
-                       unlink_internals(conn, 0, file, False);
+                       unlink_internals(conn, NULL, 0, file, False);
                }
        }
        
@@ -4899,9 +4987,9 @@ static BOOL delete_driver_files( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, struct
                        
                        if ( (p = strchr( info_3->dependentfiles[i]+1, '\\' )) != NULL ) {
                                pstrcpy( file, p );
-                               driver_unix_convert(file, conn, NULL, &bad_path, &st);
+                               driver_unix_convert(conn,file,&st);
                                DEBUG(10,("deleting dependent file [%s]\n", file));
-                               unlink_internals(conn, 0, file, False);
+                               unlink_internals(conn, NULL, 0, file, False);
                        }
                        
                        i++;
@@ -4919,11 +5007,11 @@ static BOOL delete_driver_files( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, struct
  ***************************************************************************/
 
 WERROR delete_printer_driver( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, struct current_user *user,
-                              uint32 version, BOOL delete_files )
+                              uint32 version, bool delete_files )
 {
        pstring         key;
        const char     *arch;
-       TDB_DATA        kbuf, dbuf;
+       TDB_DATA        dbuf;
        NT_PRINTER_DRIVER_INFO_LEVEL    ctr;
 
        /* delete the tdb data first */
@@ -4941,12 +5029,9 @@ WERROR delete_printer_driver( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, struct cur
        ctr.info_3 = info_3;
        dump_a_printer_driver( ctr, 3 );
 
-       kbuf.dptr=key;
-       kbuf.dsize=strlen(key)+1;
-
        /* check if the driver actually exists for this environment */
        
-       dbuf = tdb_fetch( tdb_drivers, kbuf );
+       dbuf = tdb_fetch_bystring( tdb_drivers, key );
        if ( !dbuf.dptr ) {
                DEBUG(8,("delete_printer_driver: Driver unknown [%s]\n", key));
                return WERR_UNKNOWN_PRINTER_DRIVER;
@@ -4956,7 +5041,7 @@ WERROR delete_printer_driver( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, struct cur
        
        /* ok... the driver exists so the delete should return success */
                
-       if (tdb_delete(tdb_drivers, kbuf) == -1) {
+       if (tdb_delete_bystring(tdb_drivers, key) == -1) {
                DEBUG (0,("delete_printer_driver: fail to delete %s!\n", key));
                return WERR_ACCESS_DENIED;
        }
@@ -4986,7 +5071,7 @@ WERROR nt_printing_setsec(const char *sharename, SEC_DESC_BUF *secdesc_ctr)
        SEC_DESC_BUF *old_secdesc_ctr = NULL;
        prs_struct ps;
        TALLOC_CTX *mem_ctx = NULL;
-       char *key;
+       TDB_DATA kbuf;
        WERROR status;
 
        mem_ctx = talloc_init("nt_printing_setsec");
@@ -5058,9 +5143,9 @@ WERROR nt_printing_setsec(const char *sharename, SEC_DESC_BUF *secdesc_ctr)
                goto out;
        }
 
-       key = make_printers_secdesc_tdbkey( sharename );
+       kbuf = make_printers_secdesc_tdbkey( sharename );
 
-       if (tdb_prs_store(tdb_printers, key, &ps)==0) {
+       if (tdb_prs_store(tdb_printers, kbuf, &ps)==0) {
                status = WERR_OK;
        } else {
                DEBUG(1,("Failed to store secdesc for %s\n", sharename));
@@ -5165,10 +5250,10 @@ static SEC_DESC_BUF *construct_default_printer_sdb(TALLOC_CTX *ctx)
  Get a security desc for a printer.
 ****************************************************************************/
 
-BOOL nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **secdesc_ctr)
+bool nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **secdesc_ctr)
 {
        prs_struct ps;
-       char *key;
+       TDB_DATA kbuf;
        char *temp;
 
        if (strlen(sharename) > 2 && (temp = strchr(sharename + 2, '\\'))) {
@@ -5179,9 +5264,9 @@ BOOL nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **s
 
        /* Fetch security descriptor from tdb */
 
-       key = make_printers_secdesc_tdbkey( sharename  );
+       kbuf = make_printers_secdesc_tdbkey( sharename  );
 
-       if (tdb_prs_fetch(tdb_printers, key, &ps, ctx)!=0 ||
+       if (tdb_prs_fetch(tdb_printers, kbuf, &ps, ctx)!=0 ||
            !sec_io_desc_buf("nt_printing_getsec", secdesc_ctr, &ps, 1)) {
 
                prs_mem_free(&ps);
@@ -5198,7 +5283,7 @@ BOOL nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **s
                                sizeof(SEC_DESC_BUF), ctx, MARSHALL);
 
                if (sec_io_desc_buf("nt_printing_getsec", secdesc_ctr, &ps, 1)) {
-                       tdb_prs_store(tdb_printers, key, &ps);
+                       tdb_prs_store(tdb_printers, kbuf, &ps);
                }
 
                prs_mem_free(&ps);
@@ -5346,12 +5431,12 @@ void map_printer_permissions(SEC_DESC *sd)
     3)  "printer admins" (may result in numerous calls to winbind)
 
  ****************************************************************************/
-BOOL print_access_check(struct current_user *user, int snum, int access_type)
+bool print_access_check(struct current_user *user, int snum, int access_type)
 {
        SEC_DESC_BUF *secdesc = NULL;
        uint32 access_granted;
        NTSTATUS status;
-       BOOL result;
+       bool result;
        const char *pname;
        TALLOC_CTX *mem_ctx = NULL;
        SE_PRIV se_printop = SE_PRINT_OPERATOR;
@@ -5445,10 +5530,10 @@ BOOL print_access_check(struct current_user *user, int snum, int access_type)
  Check the time parameters allow a print operation.
 *****************************************************************************/
 
-BOOL print_time_access_check(const char *servicename)
+bool print_time_access_check(const char *servicename)
 {
        NT_PRINTER_INFO_LEVEL *printer = NULL;
-       BOOL ok = False;
+       bool ok = False;
        time_t now = time(NULL);
        struct tm *t;
        uint32 mins;