Remove redundant parameter fd from SMB_VFS_FSTAT().
[ira/wip.git] / source / printing / nt_printing.c
index bbe312ca277a4308d0f187998b1ab6e1ddf7eaba..1a4a26ee6f2c226e8177d14f666dd5bbf16d1a46 100644 (file)
@@ -429,7 +429,8 @@ static int sec_desc_upg_fn( TDB_CONTEXT *the_tdb, TDB_DATA key,
 
        /* store it back */
        
-       sd_size = sec_desc_size(sd_store->sd) + sizeof(SEC_DESC_BUF);
+       sd_size = ndr_size_security_descriptor(sd_store->sd, 0)
+               + sizeof(SEC_DESC_BUF);
        prs_init(&ps, sd_size, ctx, MARSHALL);
 
        if ( !sec_io_desc_buf( "sec_desc_upg_fn", &sd_store, &ps, 1 ) ) {
@@ -1096,7 +1097,7 @@ static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32
        }
 
        /* Skip OEM header (if any) and the DOS stub to start of Windows header */
-       if (SMB_VFS_LSEEK(fsp, fsp->fh->fd, SVAL(buf,DOS_HEADER_LFANEW_OFFSET), SEEK_SET) == (SMB_OFF_T)-1) {
+       if (SMB_VFS_LSEEK(fsp, SVAL(buf,DOS_HEADER_LFANEW_OFFSET), SEEK_SET) == (SMB_OFF_T)-1) {
                DEBUG(3,("get_file_version: File [%s] too short, errno = %d\n",
                                fname, errno));
                /* Assume this isn't an error... the file just looks sort of like a PE/NE file */
@@ -1117,7 +1118,7 @@ static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32
                unsigned int section_table_bytes;
 
                /* Just skip over optional header to get to section table */
-               if (SMB_VFS_LSEEK(fsp, fsp->fh->fd,
+               if (SMB_VFS_LSEEK(fsp,
                                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",
@@ -1163,7 +1164,7 @@ static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32
                                }
 
                                /* Seek to the start of the .rsrc section info */
-                               if (SMB_VFS_LSEEK(fsp, fsp->fh->fd, section_pos, SEEK_SET) == (SMB_OFF_T)-1) {
+                               if (SMB_VFS_LSEEK(fsp, section_pos, SEEK_SET) == (SMB_OFF_T)-1) {
                                        DEBUG(3,("get_file_version: PE file [%s] too short for section info, errno = %d\n",
                                                        fname, errno));
                                        goto error_exit;
@@ -1259,7 +1260,7 @@ static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32
                                 * twice, as it is simpler to read the code. */
                                if (strcmp(&buf[i], VS_SIGNATURE) == 0) {
                                        /* Compute skip alignment to next long address */
-                                       int skip = -(SMB_VFS_LSEEK(fsp, fsp->fh->fd, 0, SEEK_CUR) - (byte_count - i) +
+                                       int skip = -(SMB_VFS_LSEEK(fsp, 0, SEEK_CUR) - (byte_count - i) +
                                                                 sizeof(VS_SIGNATURE)) & 3;
                                        if (IVAL(buf,i+sizeof(VS_SIGNATURE)+skip) != 0xfeef04bd) continue;
 
@@ -1359,7 +1360,7 @@ static int file_version_is_newer(connection_struct *conn, fstring new_file, fstr
                        DEBUG(6,("file_version_is_newer: Version info not found [%s], use mod time\n",
                                         old_file));
                        use_version = false;
-                       if (SMB_VFS_FSTAT(fsp, fsp->fh->fd, &st) == -1) {
+                       if (SMB_VFS_FSTAT(fsp, &st) == -1) {
                                 goto error_exit;
                        }
                        old_create_time = st.st_mtime;
@@ -1399,7 +1400,7 @@ static int file_version_is_newer(connection_struct *conn, fstring new_file, fstr
                        DEBUG(6,("file_version_is_newer: Version info not found [%s], use mod time\n",
                                         new_file));
                        use_version = false;
-                       if (SMB_VFS_FSTAT(fsp, fsp->fh->fd, &st) == -1) {
+                       if (SMB_VFS_FSTAT(fsp, &st) == -1) {
                                goto error_exit;
                        }
                        new_create_time = st.st_mtime;
@@ -1866,7 +1867,7 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
                goto err_exit;
        }
 
-       create_directory(conn, new_dir);
+       create_directory(conn, NULL, 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:
@@ -3208,7 +3209,8 @@ static void store_printer_guid(NT_PRINTER_INFO_LEVEL_2 *info2,
           Vista to whine */
 
        ZERO_STRUCT( unistr_guid );     
-       init_unistr2( &unistr_guid, smb_uuid_string_static(guid),
+       
+       init_unistr2( &unistr_guid, smb_uuid_string(talloc_tos(), guid),
                      UNI_STR_TERMINATE );
 
        regval_ctr_addvalue(ctr, "objectGUID", REG_SZ, 
@@ -3821,7 +3823,8 @@ static int unpack_values(NT_PRINTER_DATA *printer_data, const uint8 *buf, int bu
 
                        memcpy( &guid, data_p, sizeof(struct GUID) );
 
-                       init_unistr2( &unistr_guid, smb_uuid_string_static(guid), 
+                       init_unistr2( &unistr_guid,
+                                     smb_uuid_string(talloc_tos(), guid), 
                                      UNI_STR_TERMINATE );
 
                        regval_ctr_addvalue( printer_data->keys[key_index].values, 
@@ -3847,10 +3850,46 @@ static int unpack_values(NT_PRINTER_DATA *printer_data, const uint8 *buf, int bu
 /****************************************************************************
  ***************************************************************************/
 
+static char *last_from;
+static char *last_to;
+
+static const char *get_last_from(void)
+{
+       if (!last_from) {
+               return "";
+       }
+       return last_from;
+}
+
+static const char *get_last_to(void)
+{
+       if (!last_to) {
+               return "";
+       }
+       return last_to;
+}
+
+static bool set_last_from_to(const char *from, const char *to)
+{
+       char *orig_from = last_from;
+       char *orig_to = last_to;
+
+       last_from = SMB_STRDUP(from);
+       last_to = SMB_STRDUP(to);
+
+       SAFE_FREE(orig_from);
+       SAFE_FREE(orig_to);
+
+       if (!last_from || !last_to) {
+               SAFE_FREE(last_from);
+               SAFE_FREE(last_to);
+               return false;
+       }
+       return true;
+}
+
 static void map_to_os2_driver(fstring drivername)
 {
-       static bool initialised=False;
-       static fstring last_from,last_to;
        char *mapfile = lp_os2_driver_map();
        char **lines = NULL;
        int numlines = 0;
@@ -3862,14 +3901,10 @@ static void map_to_os2_driver(fstring drivername)
        if (!*mapfile)
                return;
 
-       if (!initialised) {
-               *last_from = *last_to = 0;
-               initialised = True;
-       }
-
-       if (strequal(drivername,last_from)) {
-               DEBUG(3,("Mapped Windows driver %s to OS/2 driver %s\n",drivername,last_to));
-               fstrcpy(drivername,last_to);
+       if (strequal(drivername,get_last_from())) {
+               DEBUG(3,("Mapped Windows driver %s to OS/2 driver %s\n",
+                       drivername,get_last_to()));
+               fstrcpy(drivername,get_last_to());
                return;
        }
 
@@ -3918,8 +3953,7 @@ static void map_to_os2_driver(fstring drivername)
 
                if (strequal(nt_name,drivername)) {
                        DEBUG(3,("Mapped windows driver %s to os2 driver%s\n",drivername,os2_name));
-                       fstrcpy(last_from,drivername);
-                       fstrcpy(last_to,os2_name);
+                       set_last_from_to(drivername,os2_name);
                        fstrcpy(drivername,os2_name);
                        file_lines_free(lines);
                        return;
@@ -3954,7 +3988,7 @@ static WERROR get_a_printer_2_default(NT_PRINTER_INFO_LEVEL_2 *info, const char
 
        DEBUG(10,("get_a_printer_2_default: driver name set to [%s]\n", info->drivername));
 
-       pstrcpy(info->comment, "");
+       strlcpy(info->comment, "", sizeof(info->comment));
        fstrcpy(info->printprocessor, "winprint");
        fstrcpy(info->datatype, "RAW");
 
@@ -4015,6 +4049,7 @@ static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info, const char *servern
        TDB_DATA kbuf, dbuf;
        fstring printername;
        char adevice[MAXDEVICENAME];
+       char *comment = NULL;
 
        kbuf = make_printer_tdbkey(talloc_tos(), sharename);
 
@@ -4040,13 +4075,18 @@ static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info, const char *servern
                        info->sharename,
                        info->portname,
                        info->drivername,
-                       info->comment,
+                       &comment,
                        info->location,
                        info->sepfile,
                        info->printprocessor,
                        info->datatype,
                        info->parameters);
 
+       if (comment) {
+               strlcpy(info->comment, comment, sizeof(info->comment));
+               SAFE_FREE(comment);
+       }
+
        /* Samba has to have shared raw drivers. */
        info->attributes |= PRINTER_ATTRIBUTE_SAMBA;
        info->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
@@ -5350,8 +5390,9 @@ WERROR nt_printing_setsec(const char *sharename, SEC_DESC_BUF *secdesc_ctr)
 
        /* Store the security descriptor in a tdb */
 
-       prs_init(&ps, (uint32)sec_desc_size(new_secdesc_ctr->sd) +
-                sizeof(SEC_DESC_BUF), mem_ctx, MARSHALL);
+       prs_init(&ps,
+                (uint32)ndr_size_security_descriptor(new_secdesc_ctr->sd, 0)
+                + sizeof(SEC_DESC_BUF), mem_ctx, MARSHALL);
 
        if (!sec_io_desc_buf("nt_printing_setsec", &new_secdesc_ctr,
                             &ps, 1)) {
@@ -5495,7 +5536,7 @@ bool nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **s
 
                /* Save default security descriptor for later */
 
-               prs_init(&ps, (uint32)sec_desc_size((*secdesc_ctr)->sd) +
+               prs_init(&ps, (uint32)ndr_size_security_descriptor((*secdesc_ctr)->sd, 0) +
                                sizeof(SEC_DESC_BUF), ctx, MARSHALL);
 
                if (sec_io_desc_buf("nt_printing_getsec", secdesc_ctr, &ps, 1)) {
@@ -5561,11 +5602,8 @@ bool nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **s
                           sharename, the_acl->num_aces));
 
                for (i = 0; i < the_acl->num_aces; i++) {
-                       fstring sid_str;
-
-                       sid_to_string(sid_str, &the_acl->aces[i].trustee);
-
-                       DEBUG(10, ("%s %d %d 0x%08x\n", sid_str,
+                       DEBUG(10, ("%s %d %d 0x%08x\n",
+                                  sid_string_dbg(&the_acl->aces[i].trustee),
                                   the_acl->aces[i].type, the_acl->aces[i].flags, 
                                   the_acl->aces[i].access_mask)); 
                }