s3: smbd: msdfs: Change create_msdfs_link() to call SMB_VFS_CREATE_DFS_PATHAT().
authorJeremy Allison <jra@samba.org>
Thu, 9 Jan 2020 22:21:46 +0000 (14:21 -0800)
committerJeremy Allison <jra@samba.org>
Fri, 10 Jan 2020 21:05:25 +0000 (21:05 +0000)
No change in the (rather strange) logic.

First step in abstracting MSDFS storage from direct symlink calls.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Fri Jan 10 21:05:25 UTC 2020 on sn-devel-184

source3/smbd/msdfs.c

index ab345fa20011498b580029e958392564a3963852..75ad2d9223b40b33f61fa07614e0c2d8910386c4 100644 (file)
@@ -1421,68 +1421,56 @@ bool create_msdfs_link(const struct junction_map *jucn,
 {
        TALLOC_CTX *frame = talloc_stackframe();
        char *path = NULL;
-       char *msdfs_link = NULL;
        connection_struct *conn;
-       bool ret = False;
        struct smb_filename *smb_fname = NULL;
        bool ok;
-       int retval;
+       NTSTATUS status;
+       bool ret = false;
 
        ok = junction_to_local_path_tos(jucn, session_info, &path, &conn);
        if (!ok) {
-               TALLOC_FREE(frame);
-               return False;
-       }
-
-       /* Form the msdfs_link contents */
-       msdfs_link = msdfs_link_string(frame,
-                               jucn->referral_list,
-                               jucn->referral_count);
-       if (msdfs_link == NULL) {
                goto out;
        }
 
-       DEBUG(5,("create_msdfs_link: Creating new msdfs link: %s -> %s\n",
-               path, msdfs_link));
-
        smb_fname = synthetic_smb_fname(frame,
                                path,
                                NULL,
                                NULL,
                                0);
        if (smb_fname == NULL) {
-               errno = ENOMEM;
                goto out;
        }
 
-       retval = SMB_VFS_SYMLINKAT(conn,
-                       msdfs_link,
-                       conn->cwd_fsp,
-                       smb_fname);
-       if (retval < 0) {
-               if (errno == EEXIST) {
-                       retval = SMB_VFS_UNLINKAT(conn,
+       status = SMB_VFS_CREATE_DFS_PATHAT(conn,
+                               conn->cwd_fsp,
+                               smb_fname,
+                               jucn->referral_list,
+                               jucn->referral_count);
+       if (!NT_STATUS_IS_OK(status)) {
+               if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
+                       int retval = SMB_VFS_UNLINKAT(conn,
                                                conn->cwd_fsp,
                                                smb_fname,
                                                0);
                        if (retval != 0) {
-                               TALLOC_FREE(smb_fname);
                                goto out;
                        }
                }
-               retval = SMB_VFS_SYMLINKAT(conn,
-                               msdfs_link,
+               status = SMB_VFS_CREATE_DFS_PATHAT(conn,
                                conn->cwd_fsp,
-                               smb_fname);
-               if (retval < 0) {
-                       DEBUG(1,("create_msdfs_link: symlinkat failed "
-                                "%s -> %s\nError: %s\n",
-                                path, msdfs_link, strerror(errno)));
+                               smb_fname,
+                               jucn->referral_list,
+                               jucn->referral_count);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DBG_WARNING("SMB_VFS_CREATE_DFS_PATHAT failed "
+                               "%s - Error: %s\n",
+                               path,
+                               nt_errstr(status));
                        goto out;
                }
        }
 
-       ret = True;
+       ret = true;
 
 out:
        TALLOC_FREE(frame);