Ignore:
Timestamp:
May 27, 2009, 9:09:42 AM (16 years ago)
Author:
Herwig Bauernfeind
Message:

Update 3.2 branch to 3.2.8

Location:
branches/samba-3.2.x/source/smbd
Files:
13 edited

Legend:

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

    r228 r232  
    20022002        output(screen, "   HAVE_STAT_ST_ATIMENSEC\n");
    20032003#endif
     2004#ifdef HAVE_STAT_ST_ATIMESPEC
     2005        output(screen, "   HAVE_STAT_ST_ATIMESPEC\n");
     2006#endif
     2007#ifdef HAVE_STAT_ST_ATIME_N
     2008        output(screen, "   HAVE_STAT_ST_ATIME_N\n");
     2009#endif
    20042010#ifdef HAVE_STAT_ST_BIRTHTIME
    20052011        output(screen, "   HAVE_STAT_ST_BIRTHTIME\n");
     
    20232029        output(screen, "   HAVE_STAT_ST_CTIMENSEC\n");
    20242030#endif
     2031#ifdef HAVE_STAT_ST_CTIMESPEC
     2032        output(screen, "   HAVE_STAT_ST_CTIMESPEC\n");
     2033#endif
     2034#ifdef HAVE_STAT_ST_CTIME_N
     2035        output(screen, "   HAVE_STAT_ST_CTIME_N\n");
     2036#endif
    20252037#ifdef HAVE_STAT_ST_FLAGS
    20262038        output(screen, "   HAVE_STAT_ST_FLAGS\n");
     
    20312043#ifdef HAVE_STAT_ST_MTIMENSEC
    20322044        output(screen, "   HAVE_STAT_ST_MTIMENSEC\n");
     2045#endif
     2046#ifdef HAVE_STAT_ST_MTIMESPEC
     2047        output(screen, "   HAVE_STAT_ST_MTIMESPEC\n");
     2048#endif
     2049#ifdef HAVE_STAT_ST_MTIME_N
     2050        output(screen, "   HAVE_STAT_ST_MTIME_N\n");
     2051#endif
     2052#ifdef HAVE_STAT_ST_UATIME
     2053        output(screen, "   HAVE_STAT_ST_UATIME\n");
     2054#endif
     2055#ifdef HAVE_STAT_ST_UCTIME
     2056        output(screen, "   HAVE_STAT_ST_UCTIME\n");
     2057#endif
     2058#ifdef HAVE_STAT_ST_UMTIME
     2059        output(screen, "   HAVE_STAT_ST_UMTIME\n");
    20332060#endif
    20342061#ifdef HAVE_STRCASECMP
     
    25292556        output(screen, "\n Build Options:\n");
    25302557
     2558#ifdef AC_APPLE_UNIVERSAL_BUILD
     2559        output(screen, "   AC_APPLE_UNIVERSAL_BUILD\n");
     2560#endif
    25312561#ifdef AIX
    25322562        output(screen, "   AIX\n");
     
    29002930#ifdef WITH_WINBIND
    29012931        output(screen, "   WITH_WINBIND\n");
    2902 #endif
    2903 #ifdef WORDS_BIGENDIAN
    2904         output(screen, "   WORDS_BIGENDIAN\n");
    29052932#endif
    29062933#ifdef XATTR_ADD_OPT
  • branches/samba-3.2.x/source/smbd/close.c

    r228 r232  
    6868        }
    6969
    70         chmod(fsp->fsp_name,0755);
    71         ret = smbrun(fsp->fsp_name,&tmp_fd);
     70        /* Ensure we don't depend on user's PATH. */
     71        p = talloc_asprintf(ctx, "./%s", fsp->fsp_name);
     72        if (!p) {
     73                TALLOC_FREE(ctx);
     74                return;
     75        }
     76
     77        if (chmod(fsp->fsp_name,0755) == -1) {
     78                TALLOC_FREE(ctx);
     79                return;
     80        }
     81        ret = smbrun(p,&tmp_fd);
    7282        DEBUG(3,("Invoking magic command %s gave %d\n",
    73                 fsp->fsp_name,ret));
     83                p,ret));
    7484
    7585        unlink(fsp->fsp_name);
  • branches/samba-3.2.x/source/smbd/dosmode.c

    r204 r232  
    214214        sizeret = SMB_VFS_GETXATTR(conn, path, SAMBA_XATTR_DOS_ATTRIB, attrstr, sizeof(attrstr));
    215215        if (sizeret == -1) {
    216 #if defined(ENOTSUP) && defined(ENOATTR)
    217                 if ((errno != ENOTSUP) && (errno != ENOATTR) && (errno != EACCES) && (errno != EPERM)) {
     216                if (errno == ENOSYS
     217#if defined(ENOTSUP)
     218                        || errno == ENOTSUP) {
     219#else
     220                                ) {
     221#endif
    218222                        DEBUG(1,("get_ea_dos_attributes: Cannot get attribute from EA on file %s: Error = %s\n",
    219223                                path, strerror(errno) ));
    220224                        set_store_dos_attributes(SNUM(conn), False);
    221225                }
    222 #endif
    223226                return False;
    224227        }
     
    274277                                ) {
    275278#endif
     279                                DEBUG(1,("set_ea_dos_attributes: Cannot set attribute EA on file %s: Error = %s\n",
     280                                        path, strerror(errno) ));
    276281                                set_store_dos_attributes(SNUM(conn), False);
    277282                        }
  • branches/samba-3.2.x/source/smbd/nttrans.c

    r228 r232  
    13061306        }
    13071307
    1308         if( is_ntfs_stream_name(oldname)) {
    1309                 /* Can't rename a stream. */
    1310                 reply_nterror(req, NT_STATUS_ACCESS_DENIED);
    1311                 END_PROFILE(SMBntrename);
    1312                 return;
    1313         }
    1314 
    13151308        if (ms_has_wild(oldname)) {
    13161309                reply_nterror(req, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
     
    13571350                }
    13581351                reply_nterror(req, status);
     1352                END_PROFILE(SMBntrename);
     1353                return;
     1354        }
     1355
     1356        /* The new name must begin with a ':' if the old name is a stream. */
     1357        if (is_ntfs_stream_name(oldname) && (newname[0] != ':')) {
     1358                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
    13591359                END_PROFILE(SMBntrename);
    13601360                return;
  • branches/samba-3.2.x/source/smbd/open.c

    r228 r232  
    668668
    669669/*
    670  * 1) No files open at all or internal open: Grant whatever the client wants.
    671  *
    672  * 2) Exclusive (or batch) oplock around: If the requested access is a delete
    673  *    request, break if the oplock around is a batch oplock. If it's another
    674  *    requested access type, break.
    675  *
    676  * 3) Only level2 around: Grant level2 and do nothing else.
     670 * Send a break message to the oplock holder and delay the open for
     671 * our client.
    677672 */
    678673
    679 static bool delay_for_oplocks(struct share_mode_lock *lck,
    680                               files_struct *fsp,
    681                               uint16 mid,
    682                               int pass_number,
    683                               int oplock_request)
     674static NTSTATUS send_break_message(files_struct *fsp,
     675                                        struct share_mode_entry *exclusive,
     676                                        uint16 mid,
     677                                        int oplock_request)
    684678{
    685         int i;
    686         struct share_mode_entry *exclusive = NULL;
    687         bool valid_entry = False;
    688         bool delay_it = False;
    689         bool have_level2 = False;
    690679        NTSTATUS status;
    691680        char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
    692 
    693         if (oplock_request & INTERNAL_OPEN_ONLY) {
    694                 fsp->oplock_type = NO_OPLOCK;
    695         }
    696 
    697         if ((oplock_request & INTERNAL_OPEN_ONLY) || is_stat_open(fsp->access_mask)) {
    698                 return False;
    699         }
    700 
    701         for (i=0; i<lck->num_share_modes; i++) {
    702 
    703                 if (!is_valid_share_mode_entry(&lck->share_modes[i])) {
    704                         continue;
    705                 }
    706 
    707                 /* At least one entry is not an invalid or deferred entry. */
    708                 valid_entry = True;
    709 
    710                 if (pass_number == 1) {
    711                         if (BATCH_OPLOCK_TYPE(lck->share_modes[i].op_type)) {
    712                                 SMB_ASSERT(exclusive == NULL);                 
    713                                 exclusive = &lck->share_modes[i];
    714                         }
    715                 } else {
    716                         if (EXCLUSIVE_OPLOCK_TYPE(lck->share_modes[i].op_type)) {
    717                                 SMB_ASSERT(exclusive == NULL);                 
    718                                 exclusive = &lck->share_modes[i];
    719                         }
    720                 }
    721 
    722                 if (lck->share_modes[i].op_type == LEVEL_II_OPLOCK) {
    723                         SMB_ASSERT(exclusive == NULL);                 
    724                         have_level2 = True;
    725                 }
    726         }
    727 
    728         if (!valid_entry) {
    729                 /* All entries are placeholders or deferred.
    730                  * Directly grant whatever the client wants. */
    731                 if (fsp->oplock_type == NO_OPLOCK) {
    732                         /* Store a level2 oplock, but don't tell the client */
    733                         fsp->oplock_type = FAKE_LEVEL_II_OPLOCK;
    734                 }
    735                 return False;
    736         }
    737 
    738         if (exclusive != NULL) { /* Found an exclusive oplock */
    739                 SMB_ASSERT(!have_level2);
    740                 delay_it = is_delete_request(fsp) ?
    741                         BATCH_OPLOCK_TYPE(exclusive->op_type) : True;
    742         }
    743 
    744         if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
    745                 /* We can at most grant level2 as there are other
    746                  * level2 or NO_OPLOCK entries. */
    747                 fsp->oplock_type = LEVEL_II_OPLOCK;
    748         }
    749 
    750         if ((fsp->oplock_type == NO_OPLOCK) && have_level2) {
    751                 /* Store a level2 oplock, but don't tell the client */
    752                 fsp->oplock_type = FAKE_LEVEL_II_OPLOCK;
    753         }
    754 
    755         if (!delay_it) {
    756                 return False;
    757         }
    758 
    759         /*
    760          * Send a break message to the oplock holder and delay the open for
    761          * our client.
    762          */
    763681
    764682        DEBUG(10, ("Sending break request to PID %s\n",
     
    785703        }
    786704
    787         return True;
     705        return status;
     706}
     707
     708/*
     709 * 1) No files open at all or internal open: Grant whatever the client wants.
     710 *
     711 * 2) Exclusive (or batch) oplock around: If the requested access is a delete
     712 *    request, break if the oplock around is a batch oplock. If it's another
     713 *    requested access type, break.
     714 *
     715 * 3) Only level2 around: Grant level2 and do nothing else.
     716 */
     717
     718static bool delay_for_oplocks(struct share_mode_lock *lck,
     719                              files_struct *fsp,
     720                              uint16 mid,
     721                              int pass_number,
     722                              int oplock_request)
     723{
     724        extern uint32 global_client_caps;
     725        int i;
     726        struct share_mode_entry *exclusive = NULL;
     727        bool valid_entry = false;
     728        bool have_level2 = false;
     729        bool have_a_none_oplock = false;
     730        bool allow_level2 = (global_client_caps & CAP_LEVEL_II_OPLOCKS) &&
     731                            lp_level2_oplocks(SNUM(fsp->conn));
     732
     733        if (oplock_request & INTERNAL_OPEN_ONLY) {
     734                fsp->oplock_type = NO_OPLOCK;
     735        }
     736
     737        if ((oplock_request & INTERNAL_OPEN_ONLY) || is_stat_open(fsp->access_mask)) {
     738                return false;
     739        }
     740
     741        for (i=0; i<lck->num_share_modes; i++) {
     742
     743                if (!is_valid_share_mode_entry(&lck->share_modes[i])) {
     744                        continue;
     745                }
     746
     747                /* At least one entry is not an invalid or deferred entry. */
     748                valid_entry = true;
     749
     750                if (pass_number == 1) {
     751                        if (BATCH_OPLOCK_TYPE(lck->share_modes[i].op_type)) {
     752                                SMB_ASSERT(exclusive == NULL);
     753                                exclusive = &lck->share_modes[i];
     754                        }
     755                } else {
     756                        if (EXCLUSIVE_OPLOCK_TYPE(lck->share_modes[i].op_type)) {
     757                                SMB_ASSERT(exclusive == NULL);
     758                                exclusive = &lck->share_modes[i];
     759                        }
     760                }
     761
     762                if (LEVEL_II_OPLOCK_TYPE(lck->share_modes[i].op_type)) {
     763                        SMB_ASSERT(exclusive == NULL);
     764                        have_level2 = true;
     765                }
     766
     767                if (lck->share_modes[i].op_type == NO_OPLOCK) {
     768                        have_a_none_oplock = true;
     769                }
     770        }
     771
     772        if (exclusive != NULL) { /* Found an exclusive oplock */
     773                bool delay_it = is_delete_request(fsp) ?
     774                                BATCH_OPLOCK_TYPE(exclusive->op_type) : true;
     775                SMB_ASSERT(!have_level2);
     776                if (delay_it) {
     777                        send_break_message(fsp, exclusive, mid, oplock_request);
     778                        return true;
     779                }
     780        }
     781
     782        /*
     783         * Match what was requested (fsp->oplock_type) with
     784         * what was found in the existing share modes.
     785         */
     786
     787        if (!valid_entry) {
     788                /* All entries are placeholders or deferred.
     789                 * Directly grant whatever the client wants. */
     790                if (fsp->oplock_type == NO_OPLOCK) {
     791                        /* Store a level2 oplock, but don't tell the client */
     792                        fsp->oplock_type = FAKE_LEVEL_II_OPLOCK;
     793                }
     794        } else if (have_a_none_oplock) {
     795                fsp->oplock_type = NO_OPLOCK;
     796        } else if (have_level2) {
     797                if (fsp->oplock_type == NO_OPLOCK ||
     798                                fsp->oplock_type == FAKE_LEVEL_II_OPLOCK) {
     799                        /* Store a level2 oplock, but don't tell the client */
     800                        fsp->oplock_type = FAKE_LEVEL_II_OPLOCK;
     801                } else {
     802                        fsp->oplock_type = LEVEL_II_OPLOCK;
     803                }
     804        } else {
     805                /* This case can never happen. */
     806                SMB_ASSERT(1);
     807        }
     808
     809        /*
     810         * Don't grant level2 to clients that don't want them
     811         * or if we've turned them off.
     812         */
     813        if (fsp->oplock_type == LEVEL_II_OPLOCK && !allow_level2) {
     814                fsp->oplock_type = FAKE_LEVEL_II_OPLOCK;
     815        }
     816
     817        DEBUG(10,("delay_for_oplocks: oplock type 0x%x on file %s\n",
     818                fsp->oplock_type, fsp->fsp_name));
     819
     820        /* No delay. */
     821        return false;
    788822}
    789823
     
    9731007        uint32 share_mode;
    9741008        uint32 create_disposition;
    975         uint32 create_options = 0;
     1009        uint32 create_options = FILE_NON_DIRECTORY_FILE;
    9761010
    9771011        DEBUG(10,("map_open_params_to_ntcreate: fname = %s, deny_mode = 0x%x, "
     
    11891223                DEBUG(10, ("open_file_ntcreate: printer open fname=%s\n", fname));
    11901224
    1191                 return print_fsp_open(conn, fname, fsp);
     1225                return print_fsp_open(conn, fname, fsp, psbuf);
    11921226        }
    11931227
     
    18261860         */
    18271861
    1828         if ((fsp->oplock_type != NO_OPLOCK) &&
    1829             (fsp->oplock_type != FAKE_LEVEL_II_OPLOCK)) {
    1830                 if (!set_file_oplock(fsp, fsp->oplock_type)) {
    1831                         /* Could not get the kernel oplock */
    1832                         fsp->oplock_type = NO_OPLOCK;
    1833                 }
     1862        if (!set_file_oplock(fsp, fsp->oplock_type)) {
     1863                /* Could not get the kernel oplock */
     1864                fsp->oplock_type = NO_OPLOCK;
    18341865        }
    18351866
     
    18381869        }
    18391870
    1840         set_share_mode(lck, fsp, current_user.ut.uid, 0, fsp->oplock_type, new_file_created);
     1871        set_share_mode(lck, fsp, current_user.ut.uid, 0,
     1872                       fsp->oplock_type);
    18411873
    18421874        /* Handle strange delete on close create semantics. */
    1843         if ((create_options & FILE_DELETE_ON_CLOSE)
    1844             && (((conn->fs_capabilities & FILE_NAMED_STREAMS)
    1845                         && is_ntfs_stream_name(fname))
    1846                 || can_set_initial_delete_on_close(lck))) {
     1875        if (create_options & FILE_DELETE_ON_CLOSE) {
     1876
    18471877                status = can_set_delete_on_close(fsp, True, new_dos_attributes);
    18481878
     
    22862316        }
    22872317
    2288         set_share_mode(lck, fsp, current_user.ut.uid, 0, NO_OPLOCK, True);
     2318        set_share_mode(lck, fsp, current_user.ut.uid, 0, NO_OPLOCK);
    22892319
    22902320        /* For directories the delete on close bit at open time seems
  • branches/samba-3.2.x/source/smbd/oplock.c

    r137 r232  
    105105bool set_file_oplock(files_struct *fsp, int oplock_type)
    106106{
    107         if (koplocks && !koplocks->set_oplock(fsp, oplock_type)) {
     107        if ((fsp->oplock_type != NO_OPLOCK) &&
     108            (fsp->oplock_type != FAKE_LEVEL_II_OPLOCK) &&
     109            koplocks &&
     110            !koplocks->set_oplock(fsp, oplock_type)) {
    108111                return False;
    109112        }
     
    113116        if (oplock_type == LEVEL_II_OPLOCK) {
    114117                level_II_oplocks_open++;
    115         } else {
     118        } else if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
    116119                exclusive_oplocks_open++;
    117120        }
     
    146149        SMB_ASSERT(exclusive_oplocks_open>=0);
    147150        SMB_ASSERT(level_II_oplocks_open>=0);
    148        
    149         fsp->oplock_type = NO_OPLOCK;
     151
     152        if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
     153                /* This doesn't matter for close. */
     154                fsp->oplock_type = FAKE_LEVEL_II_OPLOCK;
     155        } else {
     156                fsp->oplock_type = NO_OPLOCK;
     157        }
    150158        fsp->sent_oplock_break = NO_BREAK_SENT;
    151        
     159
    152160        flush_write_cache(fsp, OPLOCK_RELEASE_FLUSH);
    153161
     
    436444        SMB_ASSERT(fsp->oplock_type == LEVEL_II_OPLOCK);
    437445
     446        DEBUG(10,("process_oplock_async_level2_break_message: sending break to "
     447                "none message for fid %d, file %s\n",
     448                fsp->fnum,
     449                fsp->fsp_name));
     450
    438451        /* Now send a break to none message to our client. */
    439452
     
    809822                share_mode_entry_to_message(msg, share_entry);
    810823
    811                 messaging_send_buf(smbd_messaging_context(), share_entry->pid,
    812                                    MSG_SMB_ASYNC_LEVEL2_BREAK,
    813                                    (uint8 *)msg,
    814                                    MSG_SMB_SHARE_MODE_ENTRY_SIZE);
     824                /*
     825                 * Deal with a race condition when breaking level2
     826                 * oplocks. Don't send all the messages and release
     827                 * the lock, this allows someone else to come in and
     828                 * get a level2 lock before any of the messages are
     829                 * processed, and thus miss getting a break message.
     830                 * Ensure at least one entry (the one we're breaking)
     831                 * is processed immediately under the lock and becomes
     832                 * set as NO_OPLOCK to stop any waiter getting a level2.
     833                 * Bugid #5980.
     834                 */
     835
     836                if (procid_is_me(&share_entry->pid)) {
     837                        DATA_BLOB blob = data_blob_const(msg,
     838                                        MSG_SMB_SHARE_MODE_ENTRY_SIZE);
     839                        process_oplock_async_level2_break_message(smbd_messaging_context(),
     840                                                NULL,
     841                                                MSG_SMB_ASYNC_LEVEL2_BREAK,
     842                                                share_entry->pid,
     843                                                &blob);
     844                } else {
     845                        messaging_send_buf(smbd_messaging_context(),
     846                                        share_entry->pid,
     847                                        MSG_SMB_ASYNC_LEVEL2_BREAK,
     848                                        (uint8 *)msg,
     849                                        MSG_SMB_SHARE_MODE_ENTRY_SIZE);
     850                }
    815851        }
    816852
  • branches/samba-3.2.x/source/smbd/password.c

    r133 r232  
    2828/* this holds info on user ids that are already validated for this VC */
    2929static user_struct *validated_users;
    30 static int next_vuid = VUID_OFFSET;
     30static uint16_t next_vuid = VUID_OFFSET;
    3131static int num_validated_vuids;
    3232
     
    150150}
    151151
     152static void increment_next_vuid(uint16_t *vuid)
     153{
     154        *vuid += 1;
     155
     156        /* Check for vuid wrap. */
     157        if (*vuid == UID_FIELD_INVALID) {
     158                *vuid = VUID_OFFSET;
     159        }
     160}
     161
    152162/****************************************************
    153163 Create a new partial auth user struct.
     
    178188        while( get_valid_user_struct_internal(next_vuid,
    179189                        SERVER_ALLOCATED_REQUIRED_ANY) != NULL ) {
    180                 next_vuid++;
    181                 /* Check for vuid wrap. */
    182                 if (next_vuid == UID_FIELD_INVALID) {
    183                         next_vuid = VUID_OFFSET;
    184                 }
     190                increment_next_vuid(&next_vuid);
    185191        }
    186192
     
    195201         * to NTLMSSP.
    196202         */
    197         next_vuid++;
     203        increment_next_vuid(&next_vuid);
    198204        num_validated_vuids++;
    199205
     
    325331                "and will be vuid %u\n",
    326332                (int)vuser->uid,vuser->user.unix_name, vuser->vuid));
    327 
    328         next_vuid++;
    329         num_validated_vuids++;
    330333
    331334        if (!session_claim(vuser)) {
  • branches/samba-3.2.x/source/smbd/posix_acls.c

    r228 r232  
    31983198        }
    31993199
     3200        /* only allow chown to the current user. This is more secure,
     3201           and also copes with the case where the SID in a take ownership ACL is
     3202           a local SID on the users workstation
     3203        */
     3204        if (uid != current_user.ut.uid) {
     3205                errno = EPERM;
     3206                return -1;
     3207        }
     3208
    32003209        if (SMB_VFS_STAT(conn,fname,&st)) {
    32013210                return -1;
     
    32053214                return -1;
    32063215        }
    3207 
    3208         /* only allow chown to the current user. This is more secure,
    3209            and also copes with the case where the SID in a take ownership ACL is
    3210            a local SID on the users workstation
    3211         */
    3212         uid = current_user.ut.uid;
    32133216
    32143217        become_root();
     
    34383441        mode_t orig_mode = (mode_t)0;
    34393442        NTSTATUS status;
    3440         uid_t orig_uid;
    3441         gid_t orig_gid;
    3442         bool need_chown = False;
     3443        bool set_acl_as_root = false;
     3444        bool acl_set_support = false;
     3445        bool ret = false;
    34433446
    34443447        DEBUG(10,("set_nt_acl: called for file %s\n", fsp->fsp_name ));
     
    34613464        }
    34623465
    3463         /* Save the original elements we check against. */
     3466        /* Save the original element we check against. */
    34643467        orig_mode = sbuf.st_mode;
    3465         orig_uid = sbuf.st_uid;
    3466         orig_gid = sbuf.st_gid;
    34673468
    34683469        /*
     
    34763477
    34773478        /*
    3478          * Do we need to chown ?
     3479         * Do we need to chown ? If so this must be done first as the incoming
     3480         * CREATOR_OWNER acl will be relative to the *new* owner, not the old.
     3481         * Noticed by Simo.
    34793482         */
    34803483
    3481         if (((user != (uid_t)-1) && (orig_uid != user)) || (( grp != (gid_t)-1) && (orig_gid != grp))) {
    3482                 need_chown = True;
    3483         }
    3484 
    3485         if (need_chown && (user == (uid_t)-1 || user == current_user.ut.uid)) {
     3484        if (((user != (uid_t)-1) && (sbuf.st_uid != user)) || (( grp != (gid_t)-1) && (sbuf.st_gid != grp))) {
    34863485
    34873486                DEBUG(3,("set_nt_acl: chown %s. uid = %u, gid = %u.\n",
     
    35083507                } else {
    35093508
    3510                         int ret;
     3509                        int sret;
    35113510
    35123511                        if(fsp->fh->fd == -1)
    3513                                 ret = SMB_VFS_STAT(fsp->conn, fsp->fsp_name, &sbuf);
     3512                                sret = SMB_VFS_STAT(fsp->conn, fsp->fsp_name, &sbuf);
    35143513                        else
    3515                                 ret = SMB_VFS_FSTAT(fsp, &sbuf);
    3516 
    3517                         if(ret != 0)
     3514                                sret = SMB_VFS_FSTAT(fsp, &sbuf);
     3515
     3516                        if(sret != 0)
    35183517                                return map_nt_error_from_unix(errno);
    35193518                }
    35203519
    3521                 /* Save the original elements we check against. */
     3520                /* Save the original element we check against. */
    35223521                orig_mode = sbuf.st_mode;
    3523                 orig_uid = sbuf.st_uid;
    3524                 orig_gid = sbuf.st_gid;
    3525 
    3526                 /* We did chown already, drop the flag */
    3527                 need_chown = False;
     3522
     3523                /* If we successfully chowned, we know we must
     3524                 * be able to set the acl, so do it as root.
     3525                */
     3526                set_acl_as_root = true;
    35283527        }
    35293528
    35303529        create_file_sids(&sbuf, &file_owner_sid, &file_grp_sid);
    3531 
    3532 #if 0
    3533         /* Disable this - prevents ACL inheritance from the ACL editor. JRA. */
    3534 
    3535         /* See here: http://www.codeproject.com/KB/winsdk/accessctrl2.aspx
    3536          * for details and also the log trace in bug #4308. JRA.
    3537          */
    3538 
    3539         if ((security_info_sent & DACL_SECURITY_INFORMATION) &&
    3540                 psd->dacl != NULL &&
    3541                 (psd->type & (SE_DESC_DACL_AUTO_INHERITED|
    3542                               SE_DESC_DACL_AUTO_INHERIT_REQ))==
    3543                         (SE_DESC_DACL_AUTO_INHERITED|
    3544                          SE_DESC_DACL_AUTO_INHERIT_REQ) ) {
    3545                 status = append_parent_acl(fsp, &sbuf, psd, &psd);
    3546                 if (!NT_STATUS_IS_OK(status)) {
    3547                         return status;
    3548                 }
    3549         }
    3550 #endif
    35513530
    35523531        acl_perms = unpack_canon_ace( fsp, &sbuf, &file_owner_sid, &file_grp_sid,
     
    35543533
    35553534        /* Ignore W2K traverse DACL set. */
    3556         if (file_ace_list || dir_ace_list) {
    3557 
    3558                 if (!acl_perms) {
    3559                         DEBUG(3,("set_nt_acl: cannot set permissions\n"));
     3535        if (!file_ace_list && !dir_ace_list) {
     3536                return NT_STATUS_OK;
     3537        }
     3538
     3539        if (!acl_perms) {
     3540                DEBUG(3,("set_nt_acl: cannot set permissions\n"));
     3541                free_canon_ace_list(file_ace_list);
     3542                free_canon_ace_list(dir_ace_list);
     3543                return NT_STATUS_ACCESS_DENIED;
     3544        }
     3545
     3546        /*
     3547         * Only change security if we got a DACL.
     3548         */
     3549
     3550        if(!(security_info_sent & DACL_SECURITY_INFORMATION) || (psd->dacl == NULL)) {
     3551                free_canon_ace_list(file_ace_list);
     3552                free_canon_ace_list(dir_ace_list);
     3553                return NT_STATUS_OK;
     3554        }
     3555
     3556        /*
     3557         * Try using the POSIX ACL set first. Fall back to chmod if
     3558         * we have no ACL support on this filesystem.
     3559         */
     3560
     3561        if (acl_perms && file_ace_list) {
     3562                if (set_acl_as_root) {
     3563                        become_root();
     3564                }
     3565                ret = set_canon_ace_list(fsp, file_ace_list, False, sbuf.st_gid, &acl_set_support);
     3566                if (set_acl_as_root) {
     3567                        unbecome_root();
     3568                }
     3569                if (acl_set_support && ret == false) {
     3570                        DEBUG(3,("set_nt_acl: failed to set file acl on file %s (%s).\n", fsp->fsp_name, strerror(errno) ));
    35603571                        free_canon_ace_list(file_ace_list);
    3561                         free_canon_ace_list(dir_ace_list);
    3562                         return NT_STATUS_ACCESS_DENIED;
    3563                 }
    3564 
    3565                 /*
    3566                  * Only change security if we got a DACL.
    3567                  */
    3568 
    3569                 if((security_info_sent & DACL_SECURITY_INFORMATION) && (psd->dacl != NULL)) {
    3570 
    3571                         bool acl_set_support = False;
    3572                         bool ret = False;
     3572                        free_canon_ace_list(dir_ace_list);
     3573                        return map_nt_error_from_unix(errno);
     3574                }
     3575        }
     3576
     3577        if (acl_perms && acl_set_support && fsp->is_directory) {
     3578                if (dir_ace_list) {
     3579                        if (set_acl_as_root) {
     3580                                become_root();
     3581                        }
     3582                        ret = set_canon_ace_list(fsp, dir_ace_list, True, sbuf.st_gid, &acl_set_support);
     3583                        if (set_acl_as_root) {
     3584                                unbecome_root();
     3585                        }
     3586                        if (ret == false) {
     3587                                DEBUG(3,("set_nt_acl: failed to set default acl on directory %s (%s).\n", fsp->fsp_name, strerror(errno) ));
     3588                                free_canon_ace_list(file_ace_list);
     3589                                free_canon_ace_list(dir_ace_list);
     3590                                return map_nt_error_from_unix(errno);
     3591                        }
     3592                } else {
     3593                        int sret = -1;
    35733594
    35743595                        /*
    3575                          * Try using the POSIX ACL set first. Fall back to chmod if
    3576                          * we have no ACL support on this filesystem.
     3596                         * No default ACL - delete one if it exists.
    35773597                         */
    35783598
    3579                         if (acl_perms && file_ace_list) {
    3580                                 ret = set_canon_ace_list(fsp, file_ace_list, False, sbuf.st_gid, &acl_set_support);
    3581                                 if (acl_set_support && ret == False) {
    3582                                         DEBUG(3,("set_nt_acl: failed to set file acl on file %s (%s).\n", fsp->fsp_name, strerror(errno) ));
     3599                        if (set_acl_as_root) {
     3600                                become_root();
     3601                        }
     3602                        sret = SMB_VFS_SYS_ACL_DELETE_DEF_FILE(conn, fsp->fsp_name);
     3603                        if (set_acl_as_root) {
     3604                                unbecome_root();
     3605                        }
     3606                        if (sret == -1) {
     3607                                if (acl_group_override(conn, sbuf.st_gid, fsp->fsp_name)) {
     3608                                        DEBUG(5,("set_nt_acl: acl group control on and "
     3609                                                "current user in file %s primary group. Override delete_def_acl\n",
     3610                                                fsp->fsp_name ));
     3611
     3612                                        become_root();
     3613                                        sret = SMB_VFS_SYS_ACL_DELETE_DEF_FILE(conn, fsp->fsp_name);
     3614                                        unbecome_root();
     3615                                }
     3616
     3617                                if (sret == -1) {
     3618                                        DEBUG(3,("set_nt_acl: sys_acl_delete_def_file failed (%s)\n", strerror(errno)));
    35833619                                        free_canon_ace_list(file_ace_list);
    3584                                         free_canon_ace_list(dir_ace_list); 
     3620                                        free_canon_ace_list(dir_ace_list);
    35853621                                        return map_nt_error_from_unix(errno);
    35863622                                }
    35873623                        }
    3588 
    3589                         if (acl_perms && acl_set_support && fsp->is_directory) {
    3590                                 if (dir_ace_list) {
    3591                                         if (!set_canon_ace_list(fsp, dir_ace_list, True, sbuf.st_gid, &acl_set_support)) {
    3592                                                 DEBUG(3,("set_nt_acl: failed to set default acl on directory %s (%s).\n", fsp->fsp_name, strerror(errno) ));
    3593                                                 free_canon_ace_list(file_ace_list);
    3594                                                 free_canon_ace_list(dir_ace_list);
    3595                                                 return map_nt_error_from_unix(errno);
    3596                                         }
    3597                                 } else {
    3598 
    3599                                         /*
    3600                                          * No default ACL - delete one if it exists.
    3601                                          */
    3602 
    3603                                         if (SMB_VFS_SYS_ACL_DELETE_DEF_FILE(conn, fsp->fsp_name) == -1) {
    3604                                                 int sret = -1;
    3605 
    3606                                                 if (acl_group_override(conn, sbuf.st_gid, fsp->fsp_name)) {
    3607                                                         DEBUG(5,("set_nt_acl: acl group control on and "
    3608                                                                 "current user in file %s primary group. Override delete_def_acl\n",
    3609                                                                 fsp->fsp_name ));
    3610 
    3611                                                         become_root();
    3612                                                         sret = SMB_VFS_SYS_ACL_DELETE_DEF_FILE(conn, fsp->fsp_name);
    3613                                                         unbecome_root();
    3614                                                 }
    3615 
    3616                                                 if (sret == -1) {
    3617                                                         DEBUG(3,("set_nt_acl: sys_acl_delete_def_file failed (%s)\n", strerror(errno)));
    3618                                                         free_canon_ace_list(file_ace_list);
    3619                                                         free_canon_ace_list(dir_ace_list);
    3620                                                         return map_nt_error_from_unix(errno);
    3621                                                 }
    3622                                         }
     3624                }
     3625        }
     3626
     3627        if (acl_set_support) {
     3628                if (set_acl_as_root) {
     3629                        become_root();
     3630                }
     3631                store_inheritance_attributes(fsp, file_ace_list, dir_ace_list,
     3632                                (psd->type & SE_DESC_DACL_PROTECTED) ? True : False);
     3633                if (set_acl_as_root) {
     3634                        unbecome_root();
     3635                }
     3636        }
     3637
     3638        /*
     3639         * If we cannot set using POSIX ACLs we fall back to checking if we need to chmod.
     3640         */
     3641
     3642        if(!acl_set_support && acl_perms) {
     3643                mode_t posix_perms;
     3644
     3645                if (!convert_canon_ace_to_posix_perms( fsp, file_ace_list, &posix_perms)) {
     3646                        free_canon_ace_list(file_ace_list);
     3647                        free_canon_ace_list(dir_ace_list);
     3648                        DEBUG(3,("set_nt_acl: failed to convert file acl to posix permissions for file %s.\n",
     3649                                fsp->fsp_name ));
     3650                        return NT_STATUS_ACCESS_DENIED;
     3651                }
     3652
     3653                if (orig_mode != posix_perms) {
     3654                        int sret = -1;
     3655
     3656                        DEBUG(3,("set_nt_acl: chmod %s. perms = 0%o.\n",
     3657                                fsp->fsp_name, (unsigned int)posix_perms ));
     3658
     3659                        if (set_acl_as_root) {
     3660                                become_root();
     3661                        }
     3662                        sret = SMB_VFS_CHMOD(conn,fsp->fsp_name, posix_perms);
     3663                        if (set_acl_as_root) {
     3664                                unbecome_root();
     3665                        }
     3666                        if(sret == -1) {
     3667                                if (acl_group_override(conn, sbuf.st_gid, fsp->fsp_name)) {
     3668                                        DEBUG(5,("set_nt_acl: acl group control on and "
     3669                                                "current user in file %s primary group. Override chmod\n",
     3670                                                fsp->fsp_name ));
     3671
     3672                                        become_root();
     3673                                        sret = SMB_VFS_CHMOD(conn,fsp->fsp_name, posix_perms);
     3674                                        unbecome_root();
    36233675                                }
    3624                         }
    3625 
    3626                         if (acl_set_support) {
    3627                                 store_inheritance_attributes(fsp, file_ace_list, dir_ace_list,
    3628                                                 (psd->type & SE_DESC_DACL_PROTECTED) ? True : False);
    3629                         }
    3630 
    3631                         /*
    3632                          * If we cannot set using POSIX ACLs we fall back to checking if we need to chmod.
    3633                          */
    3634 
    3635                         if(!acl_set_support && acl_perms) {
    3636                                 mode_t posix_perms;
    3637 
    3638                                 if (!convert_canon_ace_to_posix_perms( fsp, file_ace_list, &posix_perms)) {
     3676
     3677                                if (sret == -1) {
     3678                                        DEBUG(3,("set_nt_acl: chmod %s, 0%o failed. Error = %s.\n",
     3679                                                fsp->fsp_name, (unsigned int)posix_perms, strerror(errno) ));
    36393680                                        free_canon_ace_list(file_ace_list);
    36403681                                        free_canon_ace_list(dir_ace_list);
    3641                                         DEBUG(3,("set_nt_acl: failed to convert file acl to posix permissions for file %s.\n",
    3642                                                 fsp->fsp_name ));
    3643                                         return NT_STATUS_ACCESS_DENIED;
     3682                                        return map_nt_error_from_unix(errno);
    36443683                                }
    3645 
    3646                                 if (orig_mode != posix_perms) {
    3647 
    3648                                         DEBUG(3,("set_nt_acl: chmod %s. perms = 0%o.\n",
    3649                                                 fsp->fsp_name, (unsigned int)posix_perms ));
    3650 
    3651                                         if(SMB_VFS_CHMOD(conn,fsp->fsp_name, posix_perms) == -1) {
    3652                                                 int sret = -1;
    3653                                                 if (acl_group_override(conn, sbuf.st_gid, fsp->fsp_name)) {
    3654                                                         DEBUG(5,("set_nt_acl: acl group control on and "
    3655                                                                 "current user in file %s primary group. Override chmod\n",
    3656                                                                 fsp->fsp_name ));
    3657 
    3658                                                         become_root();
    3659                                                         sret = SMB_VFS_CHMOD(conn,fsp->fsp_name, posix_perms);
    3660                                                         unbecome_root();
    3661                                                 }
    3662 
    3663                                                 if (sret == -1) {
    3664                                                         DEBUG(3,("set_nt_acl: chmod %s, 0%o failed. Error = %s.\n",
    3665                                                                 fsp->fsp_name, (unsigned int)posix_perms, strerror(errno) ));
    3666                                                         free_canon_ace_list(file_ace_list);
    3667                                                         free_canon_ace_list(dir_ace_list);
    3668                                                         return map_nt_error_from_unix(errno);
    3669                                                 }
    3670                                         }
    3671                                 }
    3672                         }
    3673                 }
    3674 
    3675                 free_canon_ace_list(file_ace_list);
    3676                 free_canon_ace_list(dir_ace_list);
    3677         }
    3678 
    3679         /* Any chown pending? */
    3680         if (need_chown) {
    3681                 DEBUG(3,("set_nt_acl: chown %s. uid = %u, gid = %u.\n",
    3682                          fsp->fsp_name, (unsigned int)user, (unsigned int)grp ));
    3683                
    3684                 if(try_chown( fsp->conn, fsp->fsp_name, user, grp) == -1) {
    3685                         DEBUG(3,("set_nt_acl: chown %s, %u, %u failed. Error = %s.\n",
    3686                                  fsp->fsp_name, (unsigned int)user, (unsigned int)grp, strerror(errno) ));
    3687                         if (errno == EPERM) {
    3688                                 return NT_STATUS_INVALID_OWNER;
    3689                         }
    3690                         return map_nt_error_from_unix(errno);
    3691                 }
    3692         }
    3693        
     3684                        }
     3685                }
     3686        }
     3687
     3688        free_canon_ace_list(file_ace_list);
     3689        free_canon_ace_list(dir_ace_list);
    36943690        return NT_STATUS_OK;
    36953691}
  • branches/samba-3.2.x/source/smbd/process.c

    r228 r232  
    280280        if (CVAL(lenbuf,0) == 0 &&
    281281                        min_recv_size &&
    282                         smb_len_large(lenbuf) > min_recv_size && /* Could be a UNIX large writeX. */
     282                        smb_len_large(lenbuf) > (min_recv_size + STANDARD_WRITE_AND_X_HEADER_SIZE) && /* Could be a UNIX large writeX. */
    283283                        !srv_is_signing_active()) {
    284284
  • branches/samba-3.2.x/source/smbd/reply.c

    r228 r232  
    23632363
    23642364        if (!NT_STATUS_IS_OK(status)) {
    2365                 DEBUG(10, ("open_file_ntcreate failed: %s\n",
     2365                DEBUG(10, ("create_file_unixpath failed: %s\n",
    23662366                           nt_errstr(status)));
    23672367                return status;
     
    32033203
    32043204                if ((nread = SMB_VFS_SENDFILE(smbd_server_fd(), fsp, &header, startpos, smb_maxcnt)) == -1) {
    3205                         /* Returning ENOSYS or EINVAL means no data at all was sent.
     3205                        /* Returning ENOSYS means no data at all was sent.
    32063206                           Do this as a normal read. */
    3207                         if (errno == ENOSYS || errno == EINVAL) {
     3207                        if (errno == ENOSYS) {
    32083208                                goto normal_read;
    32093209                        }
     
    38943894                return false;
    38953895        }
     3896        if (IS_PRINT(conn)) {
     3897                DEBUG(10,("is_valid_writeX_buffer: printing tid\n"));
     3898                return false;
     3899        }
    38963900        doff = SVAL(inbuf,smb_vwv11);
    38973901
     
    46344638        files_struct *fsp;
    46354639        NTSTATUS status;
     4640        SMB_STRUCT_STAT sbuf;
    46364641
    46374642        START_PROFILE(SMBsplopen);
     
    46574662
    46584663        /* Open for exclusive use, write only. */
    4659         status = print_fsp_open(conn, NULL, fsp);
     4664        status = print_fsp_open(conn, NULL, fsp, &sbuf);
    46604665
    46614666        if (!NT_STATUS_IS_OK(status)) {
     
    54765481        NTSTATUS status = NT_STATUS_OK;
    54775482        struct share_mode_lock *lck = NULL;
    5478         bool dst_exists;
     5483        bool dst_exists, old_is_stream, new_is_stream;
    54795484
    54805485        ZERO_STRUCT(sbuf);
     
    55455550        }
    55465551
     5552        old_is_stream = is_ntfs_stream_name(fsp->fsp_name);
     5553        new_is_stream = is_ntfs_stream_name(newname);
     5554
     5555        /* Return the correct error code if both names aren't streams. */
     5556        if (!old_is_stream && new_is_stream) {
     5557                return NT_STATUS_OBJECT_NAME_INVALID;
     5558        }
     5559
     5560        if (old_is_stream && !new_is_stream) {
     5561                return NT_STATUS_INVALID_PARAMETER;
     5562        }
     5563
    55475564        /*
    55485565         * Have vfs_object_exist also fill sbuf1
     
    55565573        }
    55575574
    5558         if(replace_if_exists && dst_exists) {
    5559                 if (is_ntfs_stream_name(newname)) {
    5560                         return NT_STATUS_INVALID_PARAMETER;
    5561                 }
    5562         }
    5563 
    55645575        if (dst_exists) {
    55655576                struct file_id fileid = vfs_file_id_from_sbuf(conn, &sbuf1);
    55665577                files_struct *dst_fsp = file_find_di_first(fileid);
    5567                 if (dst_fsp) {
     5578                /* The file can be open when renaming a stream */
     5579                if (dst_fsp && !new_is_stream) {
    55685580                        DEBUG(3, ("rename_internals_fsp: Target file open\n"));
    55695581                        return NT_STATUS_ACCESS_DENIED;
     
    56245636                 * depends on these semantics. JRA.
    56255637                 */
    5626 
    5627                 set_allow_initial_delete_on_close(lck, fsp, True);
    56285638
    56295639                if (create_options & FILE_DELETE_ON_CLOSE) {
  • branches/samba-3.2.x/source/smbd/server.c

    r228 r232  
    741741
    742742                                if (!reinit_after_fork(
    743                                             smbd_messaging_context(), true)) {
     743                                            smbd_messaging_context(),
     744                                            smbd_event_context(),
     745                                            true)) {
    744746                                        DEBUG(0,("reinit_after_fork() failed\n"));
    745747                                        smb_panic("reinit_after_fork() failed");
     
    13091311                pidfile_create("smbd");
    13101312
    1311         if (!reinit_after_fork(smbd_messaging_context(), false)) {
     1313        if (!reinit_after_fork(smbd_messaging_context(),
     1314                               smbd_event_context(), false)) {
    13121315                DEBUG(0,("reinit_after_fork() failed\n"));
    13131316                exit(1);
  • branches/samba-3.2.x/source/smbd/service.c

    r230 r232  
    698698
    699699                guest = True;
    700                 pass = getpwnam_alloc(NULL, guestname);
     700                pass = getpwnam_alloc(talloc_tos(), guestname);
    701701                if (!pass) {
    702702                        DEBUG(0,("make_connection_snum: Invalid guest "
  • branches/samba-3.2.x/source/smbd/trans2.c

    r228 r232  
    36753675        unsigned int ofs = 0;
    36763676
    3677         for (i=0; i<num_streams; i++) {
     3677        for (i = 0; i < num_streams && ofs <= max_data_bytes; i++) {
    36783678                unsigned int next_offset;
    36793679                size_t namelen;
     
    36933693
    36943694                namelen -= 2;
    3695 
    3696                 if (ofs + 24 + namelen > max_data_bytes) {
    3697                         TALLOC_FREE(namebuf);
    3698                         return NT_STATUS_BUFFER_TOO_SMALL;
    3699                 }
    37003695
    37013696                SIVAL(data, ofs+4, namelen);
     
    37123707                else {
    37133708                        unsigned int align = ndr_align_size(next_offset, 8);
    3714 
    3715                         if (next_offset + align > max_data_bytes) {
    3716                                 return NT_STATUS_BUFFER_TOO_SMALL;
    3717                         }
    37183709
    37193710                        memset(data+next_offset, 0, align);
     
    53535344        char *base_name = NULL;
    53545345        bool dest_has_wcard = False;
     5346        SMB_STRUCT_STAT sbuf;
     5347        char *newname_last_component = NULL;
    53555348        NTSTATUS status = NT_STATUS_OK;
    53565349        char *p;
     
    53605353                return NT_STATUS_INVALID_PARAMETER;
    53615354        }
     5355
     5356        ZERO_STRUCT(sbuf);
    53625357
    53635358        overwrite = (CVAL(pdata,0) ? True : False);
     
    53945389
    53955390        if (fsp && fsp->base_fsp) {
     5391                /* newname must be a stream name. */
    53965392                if (newname[0] != ':') {
    53975393                        return NT_STATUS_NOT_SUPPORTED;
     
    54045400                }
    54055401        } else {
     5402                /* newname must *not* be a stream name. */
    54065403                if (is_ntfs_stream_name(newname)) {
    54075404                        return NT_STATUS_NOT_SUPPORTED;
     
    54295426                        return NT_STATUS_NO_MEMORY;
    54305427                }
    5431         }
    5432 
    5433         if (fsp) {
    5434                 SMB_STRUCT_STAT sbuf;
    5435                 char *newname_last_component = NULL;
    5436 
    5437                 ZERO_STRUCT(sbuf);
    54385428
    54395429                status = unix_convert(ctx, conn, newname, False,
    5440                                         &newname,
    5441                                         &newname_last_component,
    5442                                         &sbuf);
     5430                                &newname,
     5431                                &newname_last_component,
     5432                                &sbuf);
    54435433
    54445434                /* If an error we expect this to be
     
    54505440                        return status;
    54515441                }
    5452 
     5442        }
     5443
     5444        if (fsp) {
    54535445                DEBUG(10,("smb_file_rename_information: SMB_FILE_RENAME_INFORMATION (fnum %d) %s -> %s\n",
    54545446                        fsp->fnum, fsp->fsp_name, base_name ));
Note: See TracChangeset for help on using the changeset viewer.