[OpenAFS-devel] Window Client Patch for Win2K

Dave Koziol dkoziol@dragonflymobile.com
Fri, 19 Jan 2001 10:35:27 -0500


Attached is a patch, in an effort to try to find a non hack solution to the
"make logins work" patch.  I'm not 100% sure this will work with terminal
server, but it appears to work both with and without integrated login.  I
haven't submitted this to the gatekeepers, because I'd like others to take a
look and make sure this isn't just a different hack.

Many thanks to Michael Nelson, his patches really helped get me going!


*** c:\afs\openafs\src\winnt\afsd\smb.c	Sat Nov 04 10:01:43 2000
--- c:\openafs\src\winnt\afsd\smb.c	Fri Jan 19 00:19:48 2001
***************
*** 548,553 ****
--- 548,569 ----
          return uidp;
  }

+ // Allows you to find an smb_user_t record by the name field
+ smb_user_t *smb_FindUserByName(smb_vc_t *vcp, char *name)
+ {
+ 	smb_user_t *uidp= NULL;
+
+ 	lock_ObtainWrite(&smb_rctLock);
+ 	for(uidp = vcp->usersp; uidp; uidp = uidp->nextp) {
+ 		if (stricmp(uidp->name, name) == 0) {
+ 			uidp->refCount++;
+                 	break;
+ 		}
+         }
+         lock_ReleaseWrite(&smb_rctLock);
+         return uidp;
+ }
+
  void smb_ReleaseUID(smb_user_t *uidp)
  {
  	smb_user_t *up;


*** c:\afs\openafs\src\winnt\afsd\smb.h	Sat Nov 04 10:01:44 2000
--- c:\openafs\src\winnt\afsd\smb.h	Fri Jan 19 00:23:40 2001
***************
*** 307,312 ****
--- 307,314 ----

  extern smb_user_t *smb_FindUID(smb_vc_t *vcp, unsigned short uid, int
flags);

+ extern smb_user_t *smb_FindUserByName(smb_vc_t *vcp, char *name);
+
  extern void smb_ReleaseUID(smb_user_t *uidp);

  extern cm_user_t *smb_GetUser(smb_vc_t *vcp, smb_packet_t *inp);


*** c:\afs\openafs\src\winnt\afsd\smb3.c	Sat Nov 04 10:01:44 2000
--- c:\openafs\src\winnt\afsd\smb3.c	Fri Jan 19 14:38:20 2001
***************
*** 132,150 ****
  	pwd = smb_ParseString(tp, &tp);
  	usern = smb_ParseString(tp, &tp);

! 	/* Create a new UID and cm_user_t structure */
! 	userp = cm_NewUser();
! 	lock_ObtainMutex(&vcp->mx);
! 	newUid = vcp->uidCounter++;
! 	lock_ReleaseMutex(&vcp->mx);

! 	/* Create a new smb_user_t structure and connect them up */
! 	uidp = smb_FindUID(vcp, newUid, SMB_FLAG_CREATE);
! 	lock_ObtainMutex(&uidp->mx);
! 	uidp->userp = userp;
! 	uidp->name = strdup(usern);
! 	lock_ReleaseMutex(&uidp->mx);
! 	smb_ReleaseUID(uidp);

  	if (dead_vcp) {
  		dead_uidp = dead_vcp->usersp;
--- 132,164 ----
  	pwd = smb_ParseString(tp, &tp);
  	usern = smb_ParseString(tp, &tp);

! 	// On Windows 2000, this function appears to be called more often than
! 	// it is expected to be called. This resulted in multiple smb_user_t
! 	// records existing all for the same user session which results in all
! 	// of the users tokens disappearing.
! 	//
! 	// To avoid this problem, we look for an existing smb_user_t record
! 	// based on the users name, and use that one if we find it.
! 	if (uidp = smb_FindUserByName(vcp, usern)) {
! 		userp = uidp->userp;
! 		newUid = (unsigned short)uidp->userID;	// For some reason these are
different types!
! 		smb_ReleaseUID(uidp);
! 	}
! 	else {
! 		/* Create a new UID and cm_user_t structure */
! 		userp = cm_NewUser();
! 		lock_ObtainMutex(&vcp->mx);
! 		newUid = vcp->uidCounter++;
! 		lock_ReleaseMutex(&vcp->mx);

! 		/* Create a new smb_user_t structure and connect them up */
! 		uidp = smb_FindUID(vcp, newUid, SMB_FLAG_CREATE);
! 		lock_ObtainMutex(&uidp->mx);
! 		uidp->userp = userp;
! 		uidp->name = strdup(usern);
! 		lock_ReleaseMutex(&uidp->mx);
! 		smb_ReleaseUID(uidp);
! 	}

  	if (dead_vcp) {
  		dead_uidp = dead_vcp->usersp;

Dave Koziol                  | koziol@dragonflymobile.com
Software Engineering Manager |
Dragonfly Mobile             | http://www.dragonflymobile.com