Ignore:
Timestamp:
May 26, 2009, 9:44:50 AM (16 years ago)
Author:
Herwig Bauernfeind
Message:

Update 3.2 branch to 3.2.6

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.2.x/source/smbd/open.c

    r204 r228  
    285285            (!file_existed && (local_flags & O_CREAT)) ||
    286286            ((local_flags & O_TRUNC) == O_TRUNC) ) {
     287                const char *wild;
    287288
    288289                /*
     
    306307
    307308                /* Don't create files with Microsoft wildcard characters. */
     309                if (fsp->base_fsp) {
     310                        /*
     311                         * wildcard characters are allowed in stream names
     312                         * only test the basefilename
     313                         */
     314                        wild = fsp->base_fsp->fsp_name;
     315                } else {
     316                        wild = path;
     317                }
    308318                if ((local_flags & O_CREAT) && !file_existed &&
    309                     ms_has_wild(path))  {
     319                    ms_has_wild(wild))  {
    310320                        return NT_STATUS_OBJECT_NAME_INVALID;
    311321                }
     
    405415                 current_user_info.smb_name : conn->user,fsp->fsp_name,
    406416                 BOOLSTR(fsp->can_read), BOOLSTR(fsp->can_write),
    407                  conn->num_files_open + 1));
     417                 conn->num_files_open));
    408418
    409419        errno = 0;
     
    894904****************************************************************************/
    895905
    896 static files_struct *fcb_or_dos_open(connection_struct *conn,
     906static NTSTATUS fcb_or_dos_open(connection_struct *conn,
     907                                     files_struct *fsp_to_dup_into,
    897908                                     const char *fname,
    898909                                     struct file_id id,
     
    904915{
    905916        files_struct *fsp;
    906         files_struct *dup_fsp;
    907917
    908918        DEBUG(5,("fcb_or_dos_open: attempting old open semantics for "
     
    933943
    934944        if (!fsp) {
    935                 return NULL;
     945                return NT_STATUS_NOT_FOUND;
    936946        }
    937947
     
    940950            (fsp->fh->private_options & NTCREATEX_OPTIONS_PRIVATE_DENY_DOS)) {
    941951                DEBUG(10,("fcb_or_dos_open: file fail due to is_executable.\n"));
    942                 return NULL;
     952                return NT_STATUS_INVALID_PARAMETER;
    943953        }
    944954
    945955        /* We need to duplicate this fsp. */
    946         if (!NT_STATUS_IS_OK(dup_file_fsp(fsp, access_mask, share_access,
    947                                           create_options, &dup_fsp))) {
    948                 return NULL;
    949         }
    950 
    951         return dup_fsp;
     956        dup_file_fsp(fsp, access_mask, share_access,
     957                          create_options, fsp_to_dup_into);
     958
     959        return NT_STATUS_OK;
    952960}
    953961
     
    11291137
    11301138/****************************************************************************
    1131  Open a file with a share mode.
     1139 Open a file with a share mode. Passed in an already created files_struct *.
    11321140****************************************************************************/
    11331141
    1134 NTSTATUS open_file_ntcreate(connection_struct *conn,
     1142static NTSTATUS open_file_ntcreate_internal(connection_struct *conn,
    11351143                            struct smb_request *req,
    11361144                            const char *fname,
     
    11441152                                                        /* Information (FILE_EXISTS etc.) */
    11451153                            int *pinfo,
    1146                             files_struct **result)
     1154                            files_struct *fsp)
    11471155{
    11481156        int flags=0;
     
    11541162        struct file_id id;
    11551163        NTSTATUS fsp_open = NT_STATUS_ACCESS_DENIED;
    1156         files_struct *fsp = NULL;
    11571164        mode_t new_unx_mode = (mode_t)0;
    11581165        mode_t unx_mode = (mode_t)0;
     
    11711178
    11721179        if (conn->printer) {
    1173                 /* 
     1180                /*
    11741181                 * Printers are handled completely differently.
    11751182                 * Most of the passed parameters are ignored.
     
    11821189                DEBUG(10, ("open_file_ntcreate: printer open fname=%s\n", fname));
    11831190
    1184                 return print_fsp_open(conn, fname, result);
     1191                return print_fsp_open(conn, fname, fsp);
    11851192        }
    11861193
     
    14391446        }
    14401447
    1441         status = file_new(conn, &fsp);
    1442         if(!NT_STATUS_IS_OK(status)) {
    1443                 return status;
    1444         }
    1445 
    14461448        fsp->file_id = vfs_file_id_from_sbuf(conn, psbuf);
    14471449        fsp->share_access = share_access;
     
    14681470
    14691471                if (lck == NULL) {
    1470                         file_free(fsp);
    14711472                        DEBUG(0, ("Could not get share mode lock\n"));
    14721473                        return NT_STATUS_SHARING_VIOLATION;
     
    14791480                        schedule_defer_open(lck, request_time, req);
    14801481                        TALLOC_FREE(lck);
    1481                         file_free(fsp);
    14821482                        return NT_STATUS_SHARING_VIOLATION;
    14831483                }
     
    14991499                                schedule_defer_open(lck, request_time, req);
    15001500                                TALLOC_FREE(lck);
    1501                                 file_free(fsp);
    15021501                                return NT_STATUS_SHARING_VIOLATION;
    15031502                        }
     
    15071506                        /* DELETE_PENDING is not deferred for a second */
    15081507                        TALLOC_FREE(lck);
    1509                         file_free(fsp);
    15101508                        return status;
    15111509                }
     
    15221520                            (NTCREATEX_OPTIONS_PRIVATE_DENY_DOS|
    15231521                             NTCREATEX_OPTIONS_PRIVATE_DENY_FCB)) {
    1524                                 files_struct *fsp_dup;
    1525 
    15261522                                if (req == NULL) {
    15271523                                        DEBUG(0, ("DOS open without an SMB "
    15281524                                                  "request!\n"));
    15291525                                        TALLOC_FREE(lck);
    1530                                         file_free(fsp);
    15311526                                        return NT_STATUS_INTERNAL_ERROR;
    15321527                                }
     
    15341529                                /* Use the client requested access mask here,
    15351530                                 * not the one we open with. */
    1536                                 fsp_dup = fcb_or_dos_open(conn, fname, id,
     1531                                status = fcb_or_dos_open(conn,
     1532                                                          fsp,
     1533                                                          fname,
     1534                                                          id,
    15371535                                                          req->smbpid,
    15381536                                                          req->vuid,
     
    15411539                                                          create_options);
    15421540
    1543                                 if (fsp_dup) {
     1541                                if (NT_STATUS_IS_OK(status)) {
    15441542                                        TALLOC_FREE(lck);
    1545                                         file_free(fsp);
    15461543                                        if (pinfo) {
    15471544                                                *pinfo = FILE_WAS_OPENED;
    15481545                                        }
    1549                                         conn->num_files_open++;
    1550                                         *result = fsp_dup;
    15511546                                        return NT_STATUS_OK;
    15521547                                }
     
    16291624                                status = NT_STATUS_ACCESS_DENIED;
    16301625                        }
    1631                         file_free(fsp);
    16321626                        return status;
    16331627                }
     
    16671661                        TALLOC_FREE(lck);
    16681662                }
    1669                 file_free(fsp);
    16701663                return fsp_open;
    16711664        }
     
    16981691                                  "mode lock for %s\n", fname));
    16991692                        fd_close(fsp);
    1700                         file_free(fsp);
    17011693                        return NT_STATUS_SHARING_VIOLATION;
    17021694                }
     
    17091701                        TALLOC_FREE(lck);
    17101702                        fd_close(fsp);
    1711                         file_free(fsp);
    17121703                        return NT_STATUS_SHARING_VIOLATION;
    17131704                }
     
    17281719                                TALLOC_FREE(lck);
    17291720                                fd_close(fsp);
    1730                                 file_free(fsp);
    17311721                                return NT_STATUS_SHARING_VIOLATION;
    17321722                        }
     
    17371727
    17381728                        fd_close(fsp);
    1739                         file_free(fsp);
    17401729
    17411730                        state.delayed_for_oplocks = False;
     
    17791768                        TALLOC_FREE(lck);
    17801769                        fd_close(fsp);
    1781                         file_free(fsp);
    17821770
    17831771                        return NT_STATUS_SHARING_VIOLATION;
     
    18051793                        TALLOC_FREE(lck);
    18061794                        fd_close(fsp);
    1807                         file_free(fsp);
    18081795                        return status;
    18091796                }
     
    18651852                        TALLOC_FREE(lck);
    18661853                        fd_close(fsp);
    1867                         file_free(fsp);
    18681854                        return status;
    18691855                }
     
    19411927        TALLOC_FREE(lck);
    19421928
    1943         conn->num_files_open++;
     1929        return NT_STATUS_OK;
     1930}
     1931
     1932/****************************************************************************
     1933 Open a file with a share mode.
     1934****************************************************************************/
     1935
     1936NTSTATUS open_file_ntcreate(connection_struct *conn,
     1937                            struct smb_request *req,
     1938                            const char *fname,
     1939                            SMB_STRUCT_STAT *psbuf,
     1940                            uint32 access_mask,         /* access bits (FILE_READ_DATA etc.) */
     1941                            uint32 share_access,        /* share constants (FILE_SHARE_READ etc) */
     1942                            uint32 create_disposition,  /* FILE_OPEN_IF etc. */
     1943                            uint32 create_options,      /* options such as delete on close. */
     1944                            uint32 new_dos_attributes,  /* attributes used for new file. */
     1945                            int oplock_request,         /* internal Samba oplock codes. */
     1946                                                        /* Information (FILE_EXISTS etc.) */
     1947                            int *pinfo,
     1948                            files_struct **result)
     1949{
     1950        NTSTATUS status;
     1951        files_struct *fsp = NULL;
     1952
     1953        *result = NULL;
     1954
     1955        status = file_new(conn, &fsp);
     1956        if(!NT_STATUS_IS_OK(status)) {
     1957                return status;
     1958        }
     1959
     1960        status = open_file_ntcreate_internal(conn,
     1961                                        req,
     1962                                        fname,
     1963                                        psbuf,
     1964                                        access_mask,
     1965                                        share_access,
     1966                                        create_disposition,
     1967                                        create_options,
     1968                                        new_dos_attributes,
     1969                                        oplock_request,
     1970                                        pinfo,
     1971                                        fsp);
     1972
     1973        if(!NT_STATUS_IS_OK(status)) {
     1974                file_free(fsp);
     1975                return status;
     1976        }
    19441977
    19451978        *result = fsp;
    1946         return NT_STATUS_OK;
     1979        return status;
    19471980}
    19481981
     
    19712004                           0, FILE_WRITE_DATA, FILE_WRITE_DATA);
    19722005
    1973         /* 
     2006        /*
    19742007         * This is not a user visible file open.
    1975          * Don't set a share mode and don't increment
    1976          * the conn->num_files_open.
     2008         * Don't set a share mode.
    19772009         */
    19782010
     
    22792311        }
    22802312
    2281         conn->num_files_open++;
    2282 
    22832313        *result = fsp;
    22842314        return NT_STATUS_OK;
     
    23552385        string_set(&fsp->fsp_name,fname);
    23562386
    2357         conn->num_files_open++;
    2358 
    23592387        *result = fsp;
    23602388        return NT_STATUS_OK;
     
    26632691            && (share_access & FILE_SHARE_DELETE)
    26642692            && (access_mask & DELETE_ACCESS)
    2665             && (((dos_mode(conn, fname, &sbuf) & FILE_ATTRIBUTE_READONLY)
    2666                  && !lp_delete_readonly(SNUM(conn)))
    2667                 || !can_delete_file_in_directory(conn, fname))) {
     2693            && (!can_delete_file_in_directory(conn, fname))) {
    26682694                status = NT_STATUS_ACCESS_DENIED;
    26692695                goto fail;
     
    27102736                        break;
    27112737                }
     2738
     2739                DEBUG(10, ("Recursing into create_file_unixpath for "
     2740                        "base %s\n", base));
    27122741
    27132742                status = create_file_unixpath(conn, NULL, base, 0,
     
    27232752                        goto fail;
    27242753                }
     2754                /* we don't need to low level fd */
     2755                fd_close(base_fsp);
    27252756        }
    27262757
     
    27592790                 */
    27602791
    2761                 status = open_file_ntcreate(
    2762                         conn, req, fname, &sbuf, access_mask, share_access,
    2763                         create_disposition, create_options, file_attributes,
    2764                         oplock_request, &info, &fsp);
     2792                if (base_fsp) {
     2793                        /*
     2794                         * We're opening the stream element of a base_fsp
     2795                         * we already opened. We need to initialize
     2796                         * the fsp first, and set up the base_fsp pointer.
     2797                         */
     2798                        status = file_new(conn, &fsp);
     2799                        if(!NT_STATUS_IS_OK(status)) {
     2800                                goto fail;
     2801                        }
     2802
     2803                        fsp->base_fsp = base_fsp;
     2804
     2805                        status = open_file_ntcreate_internal(conn,
     2806                                                req,
     2807                                                fname,
     2808                                                &sbuf,
     2809                                                access_mask,
     2810                                                share_access,
     2811                                                create_disposition,
     2812                                                create_options,
     2813                                                file_attributes,
     2814                                                oplock_request,
     2815                                                &info,
     2816                                                fsp);
     2817
     2818                        if(!NT_STATUS_IS_OK(status)) {
     2819                                file_free(fsp);
     2820                                fsp = NULL;
     2821                        }
     2822                } else {
     2823                        status = open_file_ntcreate(
     2824                                conn, req, fname, &sbuf, access_mask, share_access,
     2825                                create_disposition, create_options, file_attributes,
     2826                                oplock_request, &info, &fsp);
     2827                }
    27652828
    27662829                if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_IS_A_DIRECTORY)) {
     2830
     2831                        /* A stream open never opens a directory */
     2832
     2833                        if (base_fsp) {
     2834                                status = NT_STATUS_FILE_IS_A_DIRECTORY;
     2835                                goto fail;
     2836                        }
    27672837
    27682838                        /*
     
    27882858                goto fail;
    27892859        }
     2860
     2861        fsp->base_fsp = base_fsp;
    27902862
    27912863        /*
     
    28662938        DEBUG(10, ("create_file_unixpath: info=%d\n", info));
    28672939
    2868         /*
    2869          * Set fsp->base_fsp late enough that we can't "goto fail" anymore. In
    2870          * the fail: branch we call close_file(fsp, ERROR_CLOSE) which would
    2871          * also close fsp->base_fsp which we have to also do explicitly in
    2872          * this routine here, as not in all "goto fail:" we have the fsp set
    2873          * up already to be initialized with the base_fsp.
    2874          */
    2875 
    2876         fsp->base_fsp = base_fsp;
    2877 
    28782940        *result = fsp;
    28792941        if (pinfo != NULL) {
     
    28942956
    28952957        if (fsp != NULL) {
     2958                if (base_fsp && fsp->base_fsp == base_fsp) {
     2959                        /*
     2960                         * The close_file below will close
     2961                         * fsp->base_fsp.
     2962                         */
     2963                        base_fsp = NULL;
     2964                }
    28962965                close_file(fsp, ERROR_CLOSE);
    28972966                fsp = NULL;
     
    30533122                         * close it
    30543123                         */
     3124
    30553125                        status = open_fake_file(conn, fake_file_type, fname,
    30563126                                                access_mask, &fsp);
Note: See TracChangeset for help on using the changeset viewer.