diff -uPr samba-3.0.24/source/rpc_server/srv_dfs_nt.c samba-3.0.24.msdfs/source/rpc_server/srv_dfs_nt.c
--- samba-3.0.24/source/rpc_server/srv_dfs_nt.c	2007-02-04 13:59:21.000000000 -0500
+++ samba-3.0.24.msdfs/source/rpc_server/srv_dfs_nt.c	2007-04-05 13:23:04.000000000 -0400
@@ -67,7 +67,7 @@
 	pstrcat(altpath, sharename);
 
 	/* The following call can change the cwd. */
-	if(get_referred_path(p->mem_ctx, dfspath, &jn, NULL, NULL)) {
+	if(NT_STATUS_IS_OK(get_referred_path(p->mem_ctx, dfspath, &jn, NULL, NULL))) {
 		exists = True;
 		jn.referral_count += 1;
 		old_referral_list = jn.referral_list;
@@ -137,7 +137,7 @@
 	DEBUG(5,("init_reply_dfs_remove: Request to remove %s -> %s\\%s.\n",
 		dfspath, servername, sharename));
 
-	if(!get_referred_path(p->mem_ctx, dfspath, &jn, NULL, NULL)) {
+	if(!NT_STATUS_IS_OK(get_referred_path(p->mem_ctx, dfspath, &jn, NULL, NULL))) {
 		return WERR_DFS_NO_SUCH_VOL;
 	}
 
@@ -353,7 +353,7 @@
 		return WERR_DFS_NO_SUCH_SERVER;
   
 	/* The following call can change the cwd. */
-	if(!get_referred_path(p->mem_ctx, path, &jn, &consumedcnt, NULL) || consumedcnt < strlen(path)) {
+	if(!NT_STATUS_IS_OK(get_referred_path(p->mem_ctx, path, &jn, &consumedcnt, NULL)) || consumedcnt < strlen(path)) {
 		vfs_ChDir(p->conn,p->conn->connectpath);
 		return WERR_DFS_NO_SUCH_VOL;
 	}
diff -uPr samba-3.0.24/source/smbd/msdfs.c samba-3.0.24.msdfs/source/smbd/msdfs.c
--- samba-3.0.24/source/smbd/msdfs.c	2007-02-04 13:59:13.000000000 -0500
+++ samba-3.0.24.msdfs/source/smbd/msdfs.c	2007-04-05 12:58:18.000000000 -0400
@@ -129,7 +129,7 @@
  Note this CHANGES CWD !!!! JRA.
 *********************************************************/
 
-static BOOL create_conn_struct(connection_struct *conn, int snum, char *path)
+static NTSTATUS create_conn_struct(connection_struct *conn, int snum, char *path)
 {
 	pstring connpath;
 
@@ -143,15 +143,16 @@
 	
         if ( (conn->mem_ctx=talloc_init("connection_struct")) == NULL ) {
                 DEBUG(0,("talloc_init(connection_struct) failed!\n"));
-                return False;
+                return NT_STATUS_NO_MEMORY;
         }
 	
 	set_conn_connectpath(conn, connpath);
 
 	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);
-		return False;
+		return status;
 	}
 
 	/*
@@ -161,13 +162,14 @@
 	 */
 
 	if (vfs_ChDir(conn,conn->connectpath) != 0) {
+		NTSTATUS status = map_nt_error_from_unix(errno);
 		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);
-		return False;
+		return status;
 	}
 
-	return True;
+	return NT_STATUS_OK;
 }
 
 /**********************************************************************
@@ -478,7 +480,7 @@
  junction_map structure.
 **********************************************************************/
 
-BOOL get_referred_path(TALLOC_CTX *ctx, char *pathname, struct junction_map *jucn,
+NTSTATUS get_referred_path(TALLOC_CTX *ctx, char *pathname, struct junction_map *jucn,
 		       int *consumedcntp, BOOL *self_referralp)
 {
 	struct dfs_path dp;
@@ -487,11 +489,11 @@
 	struct connection_struct *conn = &conns;
 	pstring conn_path;
 	int snum;
-	BOOL ret = False;
+	NTSTATUS status = NT_STATUS_NOT_FOUND;
 	BOOL self_referral = False;
 
 	if (!pathname || !jucn) {
-		return False;
+		return NT_STATUS_NOT_FOUND;
 	}
 
 	ZERO_STRUCT(conns);
@@ -508,7 +510,7 @@
 	if (!is_myname_or_ipaddr(dp.hostname)) {
 		DEBUG(3, ("get_referred_path: Invalid hostname %s in path %s\n",
 			dp.hostname, pathname));
-		return False;
+		return NT_STATUS_NOT_FOUND;
 	}
 
 	pstrcpy(jucn->service_name, dp.servicename);
@@ -518,14 +520,14 @@
 	snum = lp_servicenumber(jucn->service_name);
 	if(snum < 0) {
 		if ((snum = find_service(jucn->service_name)) < 0) {
-			return False;
+			return NT_STATUS_NOT_FOUND;
 		}
 	}
 
 	if (!lp_msdfs_root(snum)) {
 		DEBUG(3,("get_referred_path: .%s. in dfs path %s is not a dfs root.\n",
 			 dp.servicename, pathname));
-		goto out;
+		return NT_STATUS_NOT_FOUND;
 	}
 
 	/*
@@ -540,13 +542,17 @@
 		struct referral* ref;
 
 		if (*lp_msdfs_proxy(snum) == '\0') {
-			return self_ref(ctx, pathname, jucn, consumedcntp, self_referralp);
+			if (self_ref(ctx, pathname, jucn, consumedcntp, self_referralp)) {
+				return NT_STATUS_OK;
+			} else {
+				return NT_STATUS_NOT_FOUND;
+			}
 		}
 
 		jucn->referral_count = 1;
 		if ((ref = TALLOC_P(ctx, struct referral)) == NULL) {
 			DEBUG(0, ("malloc failed for referral\n"));
-			goto out;
+			return NT_STATUS_NO_MEMORY;
 		}
 
 		pstrcpy(ref->alternate_path, lp_msdfs_proxy(snum));
@@ -559,13 +565,13 @@
 		if (consumedcntp) {
 			*consumedcntp = strlen(pathname);
 		}
-		ret = True;
-		goto out;
+		return NT_STATUS_OK;
 	}
 
 	pstrcpy(conn_path, lp_pathname(snum));
-	if (!create_conn_struct(conn, snum, conn_path)) {
-		return False;
+	status = create_conn_struct(conn, snum, conn_path);
+	if (!NT_STATUS_IS_OK(status)) {
+		return status;
 	}
 
 	/* If not remote & not a self referral, return False */
@@ -585,12 +591,12 @@
 		}
 	}
 	
-	ret = True;
+	status = NT_STATUS_OK;
 
 out:
 
 	conn_free_internal(conn);
-	return ret;
+	return status;
 }
 
 static int setup_ver2_dfs_referral(char *pathname, char **ppdata, 
@@ -780,7 +786,7 @@
  Set up the Dfs referral for the dfs pathname
 ******************************************************************/
 
-int setup_dfs_referral(connection_struct *orig_conn, char *pathname, int max_referral_level, char **ppdata)
+int setup_dfs_referral(connection_struct *orig_conn, char *pathname, int max_referral_level, char **ppdata, NTSTATUS *pstatus)
 {
 	struct junction_map junction;
 	int consumedcnt;
@@ -791,6 +797,7 @@
 	TALLOC_CTX *ctx;
 
 	if (!(ctx=talloc_init("setup_dfs_referral"))) {
+		*pstatus = NT_STATUS_NO_MEMORY;
 		return -1;
 	}
 
@@ -799,6 +806,7 @@
 	/* get the junction entry */
 	if (!pathnamep) {
 		talloc_destroy(ctx);
+		*pstatus = NT_STATUS_NO_MEMORY;
 		return -1;
 	}
 
@@ -811,7 +819,8 @@
 
 	pstrcpy(buf, pathnamep);
 	/* The following call can change cwd. */
-	if (!get_referred_path(ctx, buf, &junction, &consumedcnt, &self_referral)) {
+	*pstatus = get_referred_path(ctx, buf, &junction, &consumedcnt, &self_referral);
+	if(!NT_STATUS_IS_OK(*pstatus)) {
 		vfs_ChDir(orig_conn,orig_conn->connectpath);
 		talloc_destroy(ctx);
 		return -1;
@@ -848,6 +857,7 @@
 	default:
 		DEBUG(0,("setup_dfs_referral: Invalid dfs referral version: %d\n", max_referral_level));
 		talloc_destroy(ctx);
+		*pstatus = NT_STATUS_INVALID_LEVEL;
 		return -1;
 	}
       
@@ -857,6 +867,7 @@
 	}
 
 	talloc_destroy(ctx);
+	*pstatus = NT_STATUS_OK;
 	return reply_size;
 }
 
@@ -917,7 +928,7 @@
 	safe_strcat(path, jucn->volume_name, max_pathlen-1);
 
 	pstrcpy(conn_path, lp_pathname(snum));
-	if (!create_conn_struct(conn, snum, conn_path)) {
+	if (!NT_STATUS_IS_OK(create_conn_struct(conn, snum, conn_path))) {
 		return False;
 	}
 
@@ -1031,7 +1042,7 @@
 	 * Fake up a connection struct for the VFS layer.
 	 */
 
-	if (!create_conn_struct(&conn, snum, connect_path)) {
+	if (!NT_STATUS_IS_OK(create_conn_struct(&conn, snum, connect_path))) {
 		return 0;
 	}
 
diff -uPr samba-3.0.24/source/smbd/trans2.c samba-3.0.24.msdfs/source/smbd/trans2.c
--- samba-3.0.24/source/smbd/trans2.c	2007-02-04 14:09:01.000000000 -0500
+++ samba-3.0.24.msdfs/source/smbd/trans2.c	2007-04-05 12:57:22.000000000 -0400
@@ -4934,6 +4934,7 @@
   	pstring pathname;
 	int reply_size = 0;
 	int max_referral_level;
+	NTSTATUS status = NT_STATUS_OK;
 
 	DEBUG(10,("call_trans2getdfsreferral\n"));
 
@@ -4947,8 +4948,8 @@
 		return ERROR_DOS(ERRDOS,ERRbadfunc);
 
 	srvstr_pull(inbuf, pathname, &params[2], sizeof(pathname), -1, STR_TERMINATE);
-	if((reply_size = setup_dfs_referral(conn, pathname,max_referral_level,ppdata)) < 0)
-		return UNIXERROR(ERRDOS,ERRbadfile);
+	if((reply_size = setup_dfs_referral(conn, pathname,max_referral_level,ppdata,&status)) < 0)
+		return ERROR_NT(status);
     
 	SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2) | FLAGS2_DFS_PATHNAMES);
 	send_trans2_replies(outbuf,bufsize,0,0,*ppdata,reply_size);
