svn commit: samba r23988 - in branches: SAMBA_3_2/source/smbd SAMBA_3_2_0/source/smbd

vlendec at samba.org vlendec at samba.org
Sat Jul 21 22:29:55 GMT 2007


Author: vlendec
Date: 2007-07-21 22:29:55 +0000 (Sat, 21 Jul 2007)
New Revision: 23988

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=23988

Log:
Looks a lot more scary than it is: This just unwraps the else-branch of 
if (smb_messages[type].fn == NULL) { into the function top-level. Makes
this function a bit easier to understand IMO.

Volker

Modified:
   branches/SAMBA_3_2/source/smbd/process.c
   branches/SAMBA_3_2_0/source/smbd/process.c


Changeset:
Modified: branches/SAMBA_3_2/source/smbd/process.c
===================================================================
--- branches/SAMBA_3_2/source/smbd/process.c	2007-07-21 22:00:09 UTC (rev 23987)
+++ branches/SAMBA_3_2/source/smbd/process.c	2007-07-21 22:29:55 UTC (rev 23988)
@@ -899,6 +899,10 @@
 static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize)
 {
 	int outsize = 0;
+	int flags;
+	static uint16 last_session_tag = UID_FIELD_INVALID;
+	uint16 session_tag;
+	connection_struct *conn;
 
 	type &= 0xff;
 
@@ -917,97 +921,100 @@
 		DEBUG(0,("Unknown message type %d!\n",type));
 		smb_dump("Unknown", 1, inbuf, size);
 		outsize = reply_unknown(inbuf,outbuf);
-	} else {
-		int flags = smb_messages[type].flags;
-		static uint16 last_session_tag = UID_FIELD_INVALID;
-		/* In share mode security we must ignore the vuid. */
-		uint16 session_tag = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID : SVAL(inbuf,smb_uid);
-		connection_struct *conn = conn_find(SVAL(inbuf,smb_tid));
+		goto done;
+	}
 
-		DEBUG(3,("switch message %s (pid %d) conn 0x%lx\n",
-			 smb_fn_name(type), (int)sys_getpid(),
-			 (unsigned long)conn));
+	flags = smb_messages[type].flags;
 
-		smb_dump(smb_fn_name(type), 1, inbuf, size);
+	/* In share mode security we must ignore the vuid. */
+	session_tag = (lp_security() == SEC_SHARE)
+		? UID_FIELD_INVALID : SVAL(inbuf,smb_uid);
 
-		/* Ensure this value is replaced in the incoming packet. */
-		SSVAL(inbuf,smb_uid,session_tag);
+	conn = conn_find(SVAL(inbuf,smb_tid));
 
-		/*
-		 * Ensure the correct username is in current_user_info.
-		 * This is a really ugly bugfix for problems with
-		 * multiple session_setup_and_X's being done and
-		 * allowing %U and %G substitutions to work correctly.
-		 * There is a reason this code is done here, don't
-		 * move it unless you know what you're doing... :-).
-		 * JRA.
-		 */
+	DEBUG(3,("switch message %s (pid %d) conn 0x%lx\n",
+		 smb_fn_name(type), (int)sys_getpid(),
+		 (unsigned long)conn));
 
-		if (session_tag != last_session_tag) {
-			user_struct *vuser = NULL;
+	smb_dump(smb_fn_name(type), 1, inbuf, size);
 
-			last_session_tag = session_tag;
-			if(session_tag != UID_FIELD_INVALID) {
-				vuser = get_valid_user_struct(session_tag);           
-				if (vuser) {
-					set_current_user_info(&vuser->user);
-				}
-			}
-		}
+	/* Ensure this value is replaced in the incoming packet. */
+	SSVAL(inbuf,smb_uid,session_tag);
 
-		/* Does this call need to be run as the connected user? */
-		if (flags & AS_USER) {
+	/*
+	 * Ensure the correct username is in current_user_info.  This is a
+	 * really ugly bugfix for problems with multiple session_setup_and_X's
+	 * being done and allowing %U and %G substitutions to work correctly.
+	 * There is a reason this code is done here, don't move it unless you
+	 * know what you're doing... :-).  JRA.
+	 */
 
-			/* Does this call need a valid tree connection? */
-			if (!conn) {
-				/* Amazingly, the error code depends on the command (from Samba4). */
-				if (type == SMBntcreateX) {
-					return ERROR_NT(NT_STATUS_INVALID_HANDLE);
-				} else {
-					return ERROR_DOS(ERRSRV, ERRinvnid);
-				}
-			}
+	if (session_tag != last_session_tag) {
+		user_struct *vuser = NULL;
 
-			if (!change_to_user(conn,session_tag)) {
-				return(ERROR_NT(NT_STATUS_DOS(ERRSRV,ERRbaduid)));
+		last_session_tag = session_tag;
+		if(session_tag != UID_FIELD_INVALID) {
+			vuser = get_valid_user_struct(session_tag);           
+			if (vuser) {
+				set_current_user_info(&vuser->user);
 			}
+		}
+	}
 
-			/* All NEED_WRITE and CAN_IPC flags must also have AS_USER. */
+	/* Does this call need to be run as the connected user? */
+	if (flags & AS_USER) {
 
-			/* Does it need write permission? */
-			if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) {
-				return ERROR_NT(NT_STATUS_MEDIA_WRITE_PROTECTED);
+		/* Does this call need a valid tree connection? */
+		if (!conn) {
+			/* Amazingly, the error code depends on the command (from Samba4). */
+			if (type == SMBntcreateX) {
+				return ERROR_NT(NT_STATUS_INVALID_HANDLE);
+			} else {
+				return ERROR_DOS(ERRSRV, ERRinvnid);
 			}
+		}
 
-			/* IPC services are limited */
-			if (IS_IPC(conn) && !(flags & CAN_IPC)) {
-				return(ERROR_DOS(ERRSRV,ERRaccess));
-			}
-		} else {
-			/* This call needs to be run as root */
-			change_to_root_user();
+		if (!change_to_user(conn,session_tag)) {
+			return(ERROR_NT(NT_STATUS_DOS(ERRSRV,ERRbaduid)));
 		}
 
-		/* load service specific parameters */
-		if (conn) {
-			if (!set_current_service(conn,SVAL(inbuf,smb_flg),(flags & (AS_USER|DO_CHDIR)?True:False))) {
-				return(ERROR_DOS(ERRSRV,ERRaccess));
-			}
-			conn->num_smb_operations++;
+		/* All NEED_WRITE and CAN_IPC flags must also have AS_USER. */
+
+		/* Does it need write permission? */
+		if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) {
+			return ERROR_NT(NT_STATUS_MEDIA_WRITE_PROTECTED);
 		}
 
-		/* does this protocol need to be run as guest? */
-		if ((flags & AS_GUEST) && (!change_to_guest() || 
-				!check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) {
+		/* IPC services are limited */
+		if (IS_IPC(conn) && !(flags & CAN_IPC)) {
 			return(ERROR_DOS(ERRSRV,ERRaccess));
 		}
+	} else {
+		/* This call needs to be run as root */
+		change_to_root_user();
+	}
 
-		current_inbuf = inbuf; /* In case we need to defer this message in open... */
-		outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize);
+	/* load service specific parameters */
+	if (conn) {
+		if (!set_current_service(conn,SVAL(inbuf,smb_flg),(flags & (AS_USER|DO_CHDIR)?True:False))) {
+			return(ERROR_DOS(ERRSRV,ERRaccess));
+		}
+		conn->num_smb_operations++;
 	}
 
+	/* does this protocol need to be run as guest? */
+	if ((flags & AS_GUEST)
+	    && (!change_to_guest() || 
+		!check_access(smbd_server_fd(), lp_hostsallow(-1),
+			      lp_hostsdeny(-1)))) {
+		return(ERROR_DOS(ERRSRV,ERRaccess));
+	}
+
+	current_inbuf = inbuf; /* In case we need to defer this message in open... */
+	outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize);
+
+ done:
 	smb_dump(smb_fn_name(type), 0, outbuf, outsize);
-
 	return(outsize);
 }
 

Modified: branches/SAMBA_3_2_0/source/smbd/process.c
===================================================================
--- branches/SAMBA_3_2_0/source/smbd/process.c	2007-07-21 22:00:09 UTC (rev 23987)
+++ branches/SAMBA_3_2_0/source/smbd/process.c	2007-07-21 22:29:55 UTC (rev 23988)
@@ -891,6 +891,10 @@
 static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize)
 {
 	int outsize = 0;
+	int flags;
+	static uint16 last_session_tag = UID_FIELD_INVALID;
+	uint16 session_tag;
+	connection_struct *conn;
 
 	type &= 0xff;
 
@@ -909,97 +913,100 @@
 		DEBUG(0,("Unknown message type %d!\n",type));
 		smb_dump("Unknown", 1, inbuf, size);
 		outsize = reply_unknown(inbuf,outbuf);
-	} else {
-		int flags = smb_messages[type].flags;
-		static uint16 last_session_tag = UID_FIELD_INVALID;
-		/* In share mode security we must ignore the vuid. */
-		uint16 session_tag = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID : SVAL(inbuf,smb_uid);
-		connection_struct *conn = conn_find(SVAL(inbuf,smb_tid));
+		goto done;
+	}
 
-		DEBUG(3,("switch message %s (pid %d) conn 0x%lx\n",
-			 smb_fn_name(type), (int)sys_getpid(),
-			 (unsigned long)conn));
+	flags = smb_messages[type].flags;
 
-		smb_dump(smb_fn_name(type), 1, inbuf, size);
+	/* In share mode security we must ignore the vuid. */
+	session_tag = (lp_security() == SEC_SHARE)
+		? UID_FIELD_INVALID : SVAL(inbuf,smb_uid);
 
-		/* Ensure this value is replaced in the incoming packet. */
-		SSVAL(inbuf,smb_uid,session_tag);
+	conn = conn_find(SVAL(inbuf,smb_tid));
 
-		/*
-		 * Ensure the correct username is in current_user_info.
-		 * This is a really ugly bugfix for problems with
-		 * multiple session_setup_and_X's being done and
-		 * allowing %U and %G substitutions to work correctly.
-		 * There is a reason this code is done here, don't
-		 * move it unless you know what you're doing... :-).
-		 * JRA.
-		 */
+	DEBUG(3,("switch message %s (pid %d) conn 0x%lx\n",
+		 smb_fn_name(type), (int)sys_getpid(),
+		 (unsigned long)conn));
 
-		if (session_tag != last_session_tag) {
-			user_struct *vuser = NULL;
+	smb_dump(smb_fn_name(type), 1, inbuf, size);
 
-			last_session_tag = session_tag;
-			if(session_tag != UID_FIELD_INVALID) {
-				vuser = get_valid_user_struct(session_tag);           
-				if (vuser) {
-					set_current_user_info(&vuser->user);
-				}
-			}
-		}
+	/* Ensure this value is replaced in the incoming packet. */
+	SSVAL(inbuf,smb_uid,session_tag);
 
-		/* Does this call need to be run as the connected user? */
-		if (flags & AS_USER) {
+	/*
+	 * Ensure the correct username is in current_user_info.  This is a
+	 * really ugly bugfix for problems with multiple session_setup_and_X's
+	 * being done and allowing %U and %G substitutions to work correctly.
+	 * There is a reason this code is done here, don't move it unless you
+	 * know what you're doing... :-).  JRA.
+	 */
 
-			/* Does this call need a valid tree connection? */
-			if (!conn) {
-				/* Amazingly, the error code depends on the command (from Samba4). */
-				if (type == SMBntcreateX) {
-					return ERROR_NT(NT_STATUS_INVALID_HANDLE);
-				} else {
-					return ERROR_DOS(ERRSRV, ERRinvnid);
-				}
-			}
+	if (session_tag != last_session_tag) {
+		user_struct *vuser = NULL;
 
-			if (!change_to_user(conn,session_tag)) {
-				return(ERROR_NT(NT_STATUS_DOS(ERRSRV,ERRbaduid)));
+		last_session_tag = session_tag;
+		if(session_tag != UID_FIELD_INVALID) {
+			vuser = get_valid_user_struct(session_tag);           
+			if (vuser) {
+				set_current_user_info(&vuser->user);
 			}
+		}
+	}
 
-			/* All NEED_WRITE and CAN_IPC flags must also have AS_USER. */
+	/* Does this call need to be run as the connected user? */
+	if (flags & AS_USER) {
 
-			/* Does it need write permission? */
-			if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) {
-				return ERROR_NT(NT_STATUS_MEDIA_WRITE_PROTECTED);
+		/* Does this call need a valid tree connection? */
+		if (!conn) {
+			/* Amazingly, the error code depends on the command (from Samba4). */
+			if (type == SMBntcreateX) {
+				return ERROR_NT(NT_STATUS_INVALID_HANDLE);
+			} else {
+				return ERROR_DOS(ERRSRV, ERRinvnid);
 			}
+		}
 
-			/* IPC services are limited */
-			if (IS_IPC(conn) && !(flags & CAN_IPC)) {
-				return(ERROR_DOS(ERRSRV,ERRaccess));
-			}
-		} else {
-			/* This call needs to be run as root */
-			change_to_root_user();
+		if (!change_to_user(conn,session_tag)) {
+			return(ERROR_NT(NT_STATUS_DOS(ERRSRV,ERRbaduid)));
 		}
 
-		/* load service specific parameters */
-		if (conn) {
-			if (!set_current_service(conn,SVAL(inbuf,smb_flg),(flags & (AS_USER|DO_CHDIR)?True:False))) {
-				return(ERROR_DOS(ERRSRV,ERRaccess));
-			}
-			conn->num_smb_operations++;
+		/* All NEED_WRITE and CAN_IPC flags must also have AS_USER. */
+
+		/* Does it need write permission? */
+		if ((flags & NEED_WRITE) && !CAN_WRITE(conn)) {
+			return ERROR_NT(NT_STATUS_MEDIA_WRITE_PROTECTED);
 		}
 
-		/* does this protocol need to be run as guest? */
-		if ((flags & AS_GUEST) && (!change_to_guest() || 
-				!check_access(smbd_server_fd(), lp_hostsallow(-1), lp_hostsdeny(-1)))) {
+		/* IPC services are limited */
+		if (IS_IPC(conn) && !(flags & CAN_IPC)) {
 			return(ERROR_DOS(ERRSRV,ERRaccess));
 		}
+	} else {
+		/* This call needs to be run as root */
+		change_to_root_user();
+	}
 
-		current_inbuf = inbuf; /* In case we need to defer this message in open... */
-		outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize);
+	/* load service specific parameters */
+	if (conn) {
+		if (!set_current_service(conn,SVAL(inbuf,smb_flg),(flags & (AS_USER|DO_CHDIR)?True:False))) {
+			return(ERROR_DOS(ERRSRV,ERRaccess));
+		}
+		conn->num_smb_operations++;
 	}
 
+	/* does this protocol need to be run as guest? */
+	if ((flags & AS_GUEST)
+	    && (!change_to_guest() || 
+		!check_access(smbd_server_fd(), lp_hostsallow(-1),
+			      lp_hostsdeny(-1)))) {
+		return(ERROR_DOS(ERRSRV,ERRaccess));
+	}
+
+	current_inbuf = inbuf; /* In case we need to defer this message in open... */
+	outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize);
+
+ done:
 	smb_dump(smb_fn_name(type), 0, outbuf, outsize);
-
 	return(outsize);
 }
 



More information about the samba-cvs mailing list