s3: Simplify the code a bit: Catch (len==0) early
[samba.git] / source3 / modules / vfs_expand_msdfs.c
index 9d4883c08544c78d3fecc77f56e9ff925807ed39..0772215a284ac67b35a9c9e3c689e64c87893115 100644 (file)
@@ -22,8 +22,6 @@
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_VFS
 
-extern userdom_struct current_user_info;
-
 /**********************************************************
   Under mapfile we expect a table of the following format:
 
@@ -145,11 +143,11 @@ static char *expand_msdfs_target(TALLOC_CTX *ctx,
 
        targethost = talloc_sub_advanced(ctx,
                                lp_servicename(SNUM(conn)),
-                               conn->user,
+                               conn->server_info->unix_name,
                                conn->connectpath,
-                               conn->gid,
-                               get_current_username(),
-                               current_user_info.domain,
+                               conn->server_info->utok.gid,
+                               conn->server_info->sanitized_username,
+                               pdb_get_domain(conn->server_info->sam_account),
                                targethost);
 
        DEBUG(10, ("Expanded targethost to %s\n", targethost));
@@ -175,20 +173,26 @@ static int expand_msdfs_readlink(struct vfs_handle_struct *handle,
        TALLOC_CTX *ctx = talloc_tos();
        int result;
        char *target = TALLOC_ARRAY(ctx, char, PATH_MAX+1);
+       size_t len;
 
        if (!target) {
                errno = ENOMEM;
                return -1;
        }
+       if (bufsiz == 0) {
+               errno = EINVAL;
+               return -1;
+       }
+
        result = SMB_VFS_NEXT_READLINK(handle, path, target,
                                       PATH_MAX);
 
-       if (result < 0)
+       if (result <= 0)
                return result;
 
        target[result] = '\0';
 
-       if ((strncmp(target, "msdfs:", strlen("msdfs:")) == 0) &&
+       if ((strncmp(target, "msdfs:", 6) == 0) &&
            (strchr_m(target, '@') != NULL)) {
                target = expand_msdfs_target(ctx, handle->conn, target);
                if (!target) {
@@ -197,21 +201,21 @@ static int expand_msdfs_readlink(struct vfs_handle_struct *handle,
                }
        }
 
-       safe_strcpy(buf, target, bufsiz-1);
-       return strlen(buf);
-}
+       len = MIN(bufsiz, strlen(target));
+
+       memcpy(buf, target, len);
 
-/* VFS operations structure */
+       TALLOC_FREE(target);
+       return len;
+}
 
-static vfs_op_tuple expand_msdfs_ops[] = {
-       {SMB_VFS_OP(expand_msdfs_readlink), SMB_VFS_OP_READLINK,
-        SMB_VFS_LAYER_TRANSPARENT},
-       {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
+static struct vfs_fn_pointers vfs_expand_msdfs_fns = {
+       .vfs_readlink = expand_msdfs_readlink
 };
 
 NTSTATUS vfs_expand_msdfs_init(void);
 NTSTATUS vfs_expand_msdfs_init(void)
 {
        return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "expand_msdfs",
-                               expand_msdfs_ops);
+                               &vfs_expand_msdfs_fns);
 }