Ignore:
Timestamp:
May 12, 2014, 8:58:38 PM (11 years ago)
Author:
Silvan Scherrer
Message:

Samba 3.6: updated vendor to latest version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/smbd/dir.c

    r746 r860  
    5050        unsigned int name_cache_index;
    5151        unsigned int file_number;
     52        files_struct *fsp; /* Back pointer to containing fsp, only
     53                              set from OpenDir_fsp(). */
    5254};
    5355
     
    591593{
    592594        if (fsp->dptr) {
    593 /*
    594  * Ugly hack. We have defined fdopendir to return ENOSYS if dirfd also isn't
    595  * present. I hate Solaris. JRA.
    596  */
    597 #ifdef HAVE_DIRFD
    598                 if (fsp->fh->fd != -1 &&
    599                                 fsp->dptr->dir_hnd &&
    600                                 dirfd(fsp->dptr->dir_hnd->dir)) {
    601                         /* The call below closes the underlying fd. */
    602                         fsp->fh->fd = -1;
    603                 }
    604 #endif
     595                /*
     596                 * The destructor for the struct smb_Dir
     597                 * (fsp->dptr->dir_hnd) now handles
     598                 * all resource deallocation.
     599                 */
    605600                dptr_close_internal(fsp->dptr);
    606601                fsp->dptr = NULL;
     
    942937{
    943938        connection_struct *conn = dirptr->conn;
    944         bool needslash;
     939        size_t slashlen;
     940        size_t pathlen;
    945941
    946942        *_smb_fname = NULL;
    947943        *_mode = 0;
    948944
    949         needslash = ( dirptr->path[strlen(dirptr->path) -1] != '/');
     945        pathlen = strlen(dirptr->path);
     946        slashlen = ( dirptr->path[pathlen-1] != '/') ? 1 : 0;
    950947
    951948        while (true) {
     
    991988                }
    992989
    993                 pathreal = talloc_asprintf(ctx, "%s%s%s",
    994                                            dirptr->path,
    995                                            needslash?"/":"",
    996                                            dname);
     990                /*
     991                 * This used to be
     992                 * pathreal = talloc_asprintf(ctx, "%s%s%s", dirptr->path,
     993                 *                            needslash?"/":"", dname);
     994                 * but this was measurably slower than doing the memcpy.
     995                 */
     996
     997                pathreal = talloc_array(
     998                        ctx, char,
     999                        pathlen + slashlen + talloc_get_size(dname));
    9971000                if (!pathreal) {
    9981001                        TALLOC_FREE(dname);
     
    10001003                        return false;
    10011004                }
     1005
     1006                memcpy(pathreal, dirptr->path, pathlen);
     1007                pathreal[pathlen] = '/';
     1008                memcpy(pathreal + slashlen + pathlen, dname,
     1009                       talloc_get_size(dname));
    10021010
    10031011                /* Create smb_fname with NULL stream_name. */
     
    13331341static int smb_Dir_destructor(struct smb_Dir *dirp)
    13341342{
    1335         if (dirp->dir) {
    1336 #ifdef HAVE_DIRFD
    1337                 if (dirp->conn->sconn) {
    1338                         files_struct *fsp = file_find_fd(dirp->conn->sconn,
    1339                                                 dirfd(dirp->dir));
    1340                         if (fsp) {
    1341                                 /* The call below closes the underlying fd. */
    1342                                 fsp->fh->fd = -1;
     1343        if (dirp->dir != NULL) {
     1344                SMB_VFS_CLOSEDIR(dirp->conn,dirp->dir);
     1345                if (dirp->fsp != NULL) {
     1346                        /*
     1347                         * The SMB_VFS_CLOSEDIR above
     1348                         * closes the underlying fd inside
     1349                         * dirp->fsp.
     1350                         */
     1351                        dirp->fsp->fh->fd = -1;
     1352                        if (dirp->fsp->dptr != NULL) {
     1353                                SMB_ASSERT(dirp->fsp->dptr->dir_hnd == dirp);
     1354                                dirp->fsp->dptr->dir_hnd = NULL;
    13431355                        }
    1344                 }
    1345 #endif
    1346                 SMB_VFS_CLOSEDIR(dirp->conn,dirp->dir);
     1356                        dirp->fsp = NULL;
     1357                }
    13471358        }
    13481359        if (dirp->conn->sconn && !dirp->conn->sconn->using_smb2) {
     
    14281439        if (fsp->is_directory && fsp->fh->fd != -1) {
    14291440                dirp->dir = SMB_VFS_FDOPENDIR(fsp, mask, attr);
    1430                 if (dirp->dir == NULL) {
     1441                if (dirp->dir != NULL) {
     1442                        dirp->fsp = fsp;
     1443                } else {
    14311444                        DEBUG(10,("OpenDir_fsp: SMB_VFS_FDOPENDIR on %s returned "
    14321445                                "NULL (%s)\n",
     
    16441657*****************************************************************/
    16451658
    1646 NTSTATUS can_delete_directory(struct connection_struct *conn,
    1647                                 const char *dirname)
     1659NTSTATUS can_delete_directory_fsp(files_struct *fsp)
    16481660{
    16491661        NTSTATUS status = NT_STATUS_OK;
     
    16521664        char *talloced = NULL;
    16531665        SMB_STRUCT_STAT st;
    1654         struct smb_Dir *dir_hnd = OpenDir(talloc_tos(), conn,
    1655                                         dirname, NULL, 0);
     1666        struct connection_struct *conn = fsp->conn;
     1667        struct smb_Dir *dir_hnd = OpenDir_fsp(talloc_tos(),
     1668                                        conn,
     1669                                        fsp,
     1670                                        NULL,
     1671                                        0);
    16561672
    16571673        if (!dir_hnd) {
     
    16681684                }
    16691685
    1670                 if (!is_visible_file(conn, dirname, dname, &st, True)) {
     1686                if (!is_visible_file(conn, fsp->fsp_name->base_name, dname, &st, True)) {
    16711687                        TALLOC_FREE(talloced);
    16721688                        continue;
    16731689                }
    16741690
    1675                 DEBUG(10,("can_delete_directory: got name %s - can't delete\n",
     1691                DEBUG(10,("can_delete_directory_fsp: got name %s - can't delete\n",
    16761692                         dname ));
    16771693                status = NT_STATUS_DIRECTORY_NOT_EMPTY;
Note: See TracChangeset for help on using the changeset viewer.