Fix bug #7781 (Samba transforms "ShareName" to lowercase when adding new share via...
[samba.git] / source3 / smbd / msdfs.c
index f4376d49ced83d23dbd4e20a3d39ca6befdbfc93..718d0def7214514c4660ef825f409745deb9bb0f 100644 (file)
@@ -268,11 +268,11 @@ NTSTATUS create_conn_struct(TALLOC_CTX *ctx,
        if (!smbd_vfs_init(conn)) {
                NTSTATUS status = map_nt_error_from_unix(errno);
                DEBUG(0,("create_conn_struct: smbd_vfs_init failed.\n"));
-               conn_free_internal(conn);
+               conn_free(conn);
                return status;
        }
 
-       conn->fs_capabilities = SMB_VFS_FS_CAPABILITIES(conn);
+       conn->fs_capabilities = SMB_VFS_FS_CAPABILITIES(conn, &conn->ts_res);
 
        /*
         * Windows seems to insist on doing trans2getdfsreferral() calls on
@@ -284,7 +284,7 @@ NTSTATUS create_conn_struct(TALLOC_CTX *ctx,
        if (oldcwd == NULL) {
                NTSTATUS status = map_nt_error_from_unix(errno);
                DEBUG(3, ("vfs_GetWd failed: %s\n", strerror(errno)));
-               conn_free_internal(conn);
+               conn_free(conn);
                return status;
        }
 
@@ -293,7 +293,7 @@ NTSTATUS create_conn_struct(TALLOC_CTX *ctx,
                DEBUG(3,("create_conn_struct: Can't ChDir to new conn path %s. "
                        "Error was %s\n",
                        conn->connectpath, strerror(errno) ));
-               conn_free_internal(conn);
+               conn_free(conn);
                return status;
        }
 
@@ -419,8 +419,7 @@ static bool is_msdfs_link_internal(TALLOC_CTX *ctx,
 #endif
        size_t bufsize = 0;
        char *link_target = NULL;
-       struct smb_filename *smb_fname = NULL;
-       NTSTATUS status;
+       struct smb_filename smb_fname;
 
        if (pp_link_target) {
                bufsize = 1024;
@@ -434,28 +433,22 @@ static bool is_msdfs_link_internal(TALLOC_CTX *ctx,
                link_target = link_target_buf;
        }
 
-       status = create_synthetic_smb_fname(talloc_tos(), path, NULL, NULL,
-                                           &smb_fname);
-       if (!NT_STATUS_IS_OK(status)) {
-               goto err;
-       }
+       ZERO_STRUCT(smb_fname);
+       smb_fname.base_name = discard_const_p(char, path);
 
-       if (SMB_VFS_LSTAT(conn, smb_fname) != 0) {
+       if (SMB_VFS_LSTAT(conn, &smb_fname) != 0) {
                DEBUG(5,("is_msdfs_link_read_target: %s does not exist.\n",
                        path));
-               TALLOC_FREE(smb_fname);
                goto err;
        }
-       if (!S_ISLNK(smb_fname->st.st_ex_mode)) {
+       if (!S_ISLNK(smb_fname.st.st_ex_mode)) {
                DEBUG(5,("is_msdfs_link_read_target: %s is not a link.\n",
                                        path));
-               TALLOC_FREE(smb_fname);
                goto err;
        }
        if (sbufp != NULL) {
-               *sbufp = smb_fname->st;
+               *sbufp = smb_fname.st;
        }
-       TALLOC_FREE(smb_fname);
 
        referral_len = SMB_VFS_READLINK(conn, path, link_target, bufsize - 1);
        if (referral_len == -1) {
@@ -532,30 +525,21 @@ static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx,
                conn->connectpath, pdp->reqpath));
 
        /*
-        * Note the unix path conversion here we're doing we can
+        * Note the unix path conversion here we're doing we
         * throw away. We're looking for a symlink for a dfs
         * resolution, if we don't find it we'll do another
         * unix_convert later in the codepath.
-        * If we needed to remember what we'd resolved in
-        * dp->reqpath (as the original code did) we'd
-        * copy (localhost, dp->reqpath) on any code
-        * path below that returns True - but I don't
-        * think this is needed. JRA.
         */
 
        status = unix_convert(ctx, conn, pdp->reqpath, &smb_fname,
-                             search_flag ? UCF_ALLOW_WCARD_LCOMP : 0);
+                             search_flag ? UCF_ALWAYS_ALLOW_WCARD_LCOMP : 0);
 
        if (!NT_STATUS_IS_OK(status)) {
                if (!NT_STATUS_EQUAL(status,
                                     NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
                        return status;
                }
-
-               /* Create an smb_fname to use below. */
-               status = create_synthetic_smb_fname(ctx, pdp->reqpath, NULL,
-                                                   NULL, &smb_fname);
-               if (!NT_STATUS_IS_OK(status)) {
+               if (smb_fname == NULL || smb_fname->base_name == NULL) {
                        return status;
                }
        }
@@ -802,6 +786,7 @@ static NTSTATUS self_ref(TALLOC_CTX *ctx,
 **********************************************************************/
 
 NTSTATUS get_referred_path(TALLOC_CTX *ctx,
+                       struct auth_serversupplied_info *server_info,
                        const char *dfs_path,
                        struct junction_map *jucn,
                        int *consumedcntp,
@@ -837,8 +822,7 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
        snum = lp_servicenumber(jucn->service_name);
        if(snum < 0) {
                fstring service_name;
-               fstrcpy(service_name, jucn->service_name);
-               if ((snum = find_service(service_name)) < 0) {
+               if ((snum = find_service(jucn->service_name, service_name)) < 0) {
                        return NT_STATUS_NOT_FOUND;
                }
                TALLOC_FREE(jucn->service_name);
@@ -923,7 +907,7 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
        }
 
        status = create_conn_struct(ctx, &conn, snum, lp_pathname(snum),
-                                   NULL, &oldpath);
+                                   server_info, &oldpath);
        if (!NT_STATUS_IS_OK(status)) {
                TALLOC_FREE(pdp);
                return status;
@@ -939,7 +923,7 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
                DEBUG(3,("get_referred_path: No valid referrals for path %s\n",
                        dfs_path));
                vfs_ChDir(conn, oldpath);
-               conn_free_internal(conn);
+               conn_free(conn);
                TALLOC_FREE(pdp);
                return status;
        }
@@ -951,13 +935,13 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
                DEBUG(3,("get_referred_path: failed to parse symlink "
                        "target %s\n", targetpath ));
                vfs_ChDir(conn, oldpath);
-               conn_free_internal(conn);
+               conn_free(conn);
                TALLOC_FREE(pdp);
                return NT_STATUS_NOT_FOUND;
        }
 
        vfs_ChDir(conn, oldpath);
-       conn_free_internal(conn);
+       conn_free(conn);
        TALLOC_FREE(pdp);
        return NT_STATUS_OK;
 }
@@ -1228,8 +1212,9 @@ int setup_dfs_referral(connection_struct *orig_conn,
        }
 
        /* The following call can change cwd. */
-       *pstatus = get_referred_path(ctx, pathnamep, junction,
-                       &consumedcnt, &self_referral);
+       *pstatus = get_referred_path(ctx, orig_conn->server_info,
+                                    pathnamep, junction,
+                                    &consumedcnt, &self_referral);
        if (!NT_STATUS_IS_OK(*pstatus)) {
                vfs_ChDir(orig_conn,orig_conn->connectpath);
                talloc_destroy(ctx);
@@ -1374,7 +1359,7 @@ static bool junction_to_local_path(const struct junction_map *jucn,
                        jucn->volume_name);
        if (!*pp_path_out) {
                vfs_ChDir(*conn_out, *oldpath);
-               conn_free_internal(*conn_out);
+               conn_free(*conn_out);
                return False;
        }
        return True;
@@ -1462,7 +1447,7 @@ bool create_msdfs_link(const struct junction_map *jucn)
 
 out:
        vfs_ChDir(conn, cwd);
-       conn_free_internal(conn);
+       conn_free(conn);
        return ret;
 }
 
@@ -1493,7 +1478,7 @@ bool remove_msdfs_link(const struct junction_map *jucn)
 
        TALLOC_FREE(smb_fname);
        vfs_ChDir(conn, cwd);
-       conn_free_internal(conn);
+       conn_free(conn);
        return ret;
 }
 
@@ -1505,7 +1490,8 @@ static int count_dfs_links(TALLOC_CTX *ctx, int snum)
 {
        size_t cnt = 0;
        SMB_STRUCT_DIR *dirp = NULL;
-       char *dname = NULL;
+       const char *dname = NULL;
+       char *talloced = NULL;
        const char *connect_path = lp_pathname(snum);
        const char *msdfs_proxy = lp_msdfs_proxy(snum);
        connection_struct *conn;
@@ -1542,19 +1528,21 @@ static int count_dfs_links(TALLOC_CTX *ctx, int snum)
                goto out;
        }
 
-       while ((dname = vfs_readdirname(conn, dirp, NULL)) != NULL) {
+       while ((dname = vfs_readdirname(conn, dirp, NULL, &talloced))
+              != NULL) {
                if (is_msdfs_link(conn,
                                dname,
                                NULL)) {
                        cnt++;
                }
+               TALLOC_FREE(talloced);
        }
 
        SMB_VFS_CLOSEDIR(conn,dirp);
 
 out:
        vfs_ChDir(conn, cwd);
-       conn_free_internal(conn);
+       conn_free(conn);
        return cnt;
 }
 
@@ -1568,7 +1556,8 @@ static int form_junctions(TALLOC_CTX *ctx,
 {
        size_t cnt = 0;
        SMB_STRUCT_DIR *dirp = NULL;
-       char *dname = NULL;
+       const char *dname = NULL;
+       char *talloced = NULL;
        const char *connect_path = lp_pathname(snum);
        char *service_name = lp_servicename(snum);
        const char *msdfs_proxy = lp_msdfs_proxy(snum);
@@ -1642,11 +1631,13 @@ static int form_junctions(TALLOC_CTX *ctx,
                goto out;
        }
 
-       while ((dname = vfs_readdirname(conn, dirp, NULL)) != NULL) {
+       while ((dname = vfs_readdirname(conn, dirp, NULL, &talloced))
+              != NULL) {
                char *link_target = NULL;
                if (cnt >= jn_remain) {
                        DEBUG(2, ("form_junctions: ran out of MSDFS "
                                "junction slots"));
+                       TALLOC_FREE(talloced);
                        goto out;
                }
                if (is_msdfs_link_internal(ctx,
@@ -1664,6 +1655,7 @@ static int form_junctions(TALLOC_CTX *ctx,
                                                                dname);
                                if (!jucn[cnt].service_name ||
                                                !jucn[cnt].volume_name) {
+                                       TALLOC_FREE(talloced);
                                        goto out;
                                }
                                jucn[cnt].comment = "";
@@ -1671,6 +1663,7 @@ static int form_junctions(TALLOC_CTX *ctx,
                        }
                        TALLOC_FREE(link_target);
                }
+               TALLOC_FREE(talloced);
        }
 
 out:
@@ -1680,7 +1673,7 @@ out:
        }
 
        vfs_ChDir(conn, cwd);
-       conn_free_internal(conn);
+       conn_free(conn);
        return cnt;
 }
 
@@ -1737,6 +1730,7 @@ NTSTATUS resolve_dfspath_wcard(TALLOC_CTX *ctx,
                                connection_struct *conn,
                                bool dfs_pathnames,
                                const char *name_in,
+                               bool allow_wcards,
                                char **pp_name_out,
                                bool *ppath_contains_wcard)
 {
@@ -1747,7 +1741,7 @@ NTSTATUS resolve_dfspath_wcard(TALLOC_CTX *ctx,
                status = dfs_redirect(ctx,
                                        conn,
                                        name_in,
-                                       True,
+                                       allow_wcards,
                                        pp_name_out,
                                        &path_contains_wcard);