Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

252 lines
6.7 KiB

  1. /*************************************************************************
  2. *
  3. * QATTACH.C
  4. *
  5. * Do any neccessary attach user queries
  6. *
  7. * Copyright (c) 1995 Microsoft Corporation
  8. *
  9. * $Log: N:\NT\PRIVATE\NW4\NWSCRIPT\VCS\MAPLIST.C $
  10. *
  11. * Rev 1.1 10 Apr 1996 14:22:42 terryt
  12. * Hotfix for 21181hq
  13. *
  14. * Rev 1.1 12 Mar 1996 19:53:58 terryt
  15. * Relative NDS names and merge
  16. *
  17. * Rev 1.0 22 Jan 1996 16:49:24 terryt
  18. * Initial revision.
  19. *
  20. *************************************************************************/
  21. #include "common.h"
  22. //
  23. // 4X login script behavior for map commands to servers not in the
  24. // logged in NDS tree that have not been ATTACH'ed is different from
  25. // the 3X behavior.
  26. //
  27. // The 4X behavior is to always ask for a user name and password for
  28. // these servers, doing the attach at that point. The user gets
  29. // two trys.
  30. //
  31. // Since NT doesn't have an list of attached servers, and will try
  32. // to connect to a volume with the default user name and password,
  33. // a wrapper must be put around the MAP commands. This code
  34. // must determine that a bindery connection will be made and that
  35. // this server has not previously been MAP'ed or ATTACH'ed.
  36. // The user will be always prompted for user name and password.
  37. // The server will then be logged into with those credentials.
  38. //
  39. // One problem with the below is that it's not easy to tell that
  40. // a connection "will be" made with the bindery, this is done in
  41. // the redirector. So to simplify things the assumption is that
  42. // only 3X servers use bindery connections. This means that
  43. // 4X servers using bindery emulation on a different NDS tree will
  44. // not always be asked for the user name and password.
  45. //
  46. // Already processed servers are kept in a list and marked as 4X or 3X
  47. // for possible future use.
  48. //
  49. // The behavior for a 3X login depends on the LOGIN.EXE version.
  50. // The old behavior is that you must always ATTACH before mapping.
  51. // However, if you login to a 3X server with a 4X version LOGIN.EXE
  52. // it will try to authenticate using your user name (and password)
  53. // on the first attempt and ask for a password if that fails. The
  54. // second attempt will ask for your user name. Since this 4X behavior
  55. // is more forgiving (more scripts "work") that is the one being
  56. // emulated.
  57. //
  58. typedef struct _SERVERLIST
  59. {
  60. char * ServerName;
  61. unsigned int ServerType;
  62. struct _SERVERLIST *pNextServer;
  63. } SERVERLIST, *PSERVERLIST;
  64. PSERVERLIST pMainList = NULL;
  65. BOOL IsServerInAttachList( char *, unsigned int );
  66. void AddServerToAttachList( char *, unsigned int );
  67. int DoAttachProcessing( char * );
  68. /*
  69. * Scan the list for the server
  70. */
  71. BOOL
  72. IsServerInAttachList( char * Server, unsigned int ServerType )
  73. {
  74. PSERVERLIST pServerList = pMainList;
  75. while ( pServerList != NULL )
  76. {
  77. if ( !_strcmpi( Server, pServerList->ServerName ) &&
  78. ( ServerType & pServerList->ServerType ) )
  79. return TRUE;
  80. pServerList = pServerList->pNextServer;
  81. }
  82. return FALSE;
  83. }
  84. /*
  85. * Add the server to the list of attached servers
  86. *
  87. * This is used during MAP's and ATTACH's
  88. */
  89. void
  90. AddServerToAttachList( char * Server, unsigned int ServerType )
  91. {
  92. PSERVERLIST pServerList;
  93. pServerList = (PSERVERLIST) malloc( sizeof( SERVERLIST ) );
  94. if ( pServerList == NULL )
  95. {
  96. DisplayMessage( IDR_NOT_ENOUGH_MEMORY );
  97. return;
  98. }
  99. pServerList->ServerName = _strdup( Server );
  100. pServerList->ServerType = ServerType;
  101. pServerList->pNextServer = pMainList;
  102. pMainList = pServerList;
  103. }
  104. /*
  105. * Do any Attach processing
  106. * Return error code. 0 is success.
  107. * 880F is the special "attached failed" error
  108. */
  109. int
  110. DoAttachProcessing( char * PossibleServer )
  111. {
  112. unsigned int iRet = 0;
  113. unsigned int conn;
  114. char userName[MAX_NAME_LEN] = "";
  115. char password[MAX_PASSWORD_LEN] = "";
  116. BOOL AlreadyConnected = FALSE;
  117. //
  118. // Must have a server to process
  119. //
  120. if ( !*PossibleServer )
  121. return iRet;
  122. // See if this server has been processed before
  123. // No since in doing a 4X server twice, and you only ask
  124. // for the user name and password once.
  125. if ( IsServerInAttachList( PossibleServer,
  126. LIST_4X_SERVER | LIST_3X_SERVER ) )
  127. return iRet;
  128. // See if there is already a connection to the server
  129. if ( NTIsConnected( PossibleServer ) )
  130. AlreadyConnected = TRUE;
  131. else
  132. AlreadyConnected = FALSE;
  133. // Try and attach to the server
  134. iRet = NTAttachToFileServer( PossibleServer, &conn );
  135. // If attach failed, return
  136. if ( iRet )
  137. return iRet;
  138. // If this is a 4X server then add it to the list of attached
  139. // servers. We don't want to do this again. 4X servers must
  140. // use the NDS attachment anyway (or at least I don't see a
  141. // way of telling that it's going to be a bindery emulation
  142. // connection ahead of time).
  143. if ( fNDS && Is40Server( conn ) )
  144. {
  145. AddServerToAttachList( PossibleServer, LIST_4X_SERVER );
  146. DetachFromFileServer ( conn );
  147. return iRet;
  148. }
  149. // Close that first connection
  150. DetachFromFileServer ( conn );
  151. // If we are already connected, don't mess with things
  152. // The credentials can't be changed anyway
  153. if ( AlreadyConnected )
  154. {
  155. AddServerToAttachList( PossibleServer, LIST_3X_SERVER );
  156. return iRet;
  157. }
  158. // Ask for user name on an NDS login
  159. //
  160. // Use the current login name for a 3X login on the first attempt
  161. if ( fNDS )
  162. {
  163. DisplayMessage(IDR_ENTER_LOGIN_NAME, PossibleServer);
  164. if (!ReadName(userName))
  165. return 0x880F;
  166. }
  167. else
  168. {
  169. strncpy( userName, LOGIN_NAME, sizeof( userName ) );
  170. }
  171. // Try to log the user in, asking for a password
  172. iRet = Login( userName,
  173. PossibleServer,
  174. password,
  175. TRUE );
  176. // Clear out the password
  177. // We don't need it again
  178. memset( password, 0, sizeof( password ) );
  179. // If failed, give the user one more chance
  180. if ( iRet )
  181. {
  182. // Ask for user name
  183. DisplayMessage(IDR_ENTER_LOGIN_NAME, PossibleServer);
  184. if (!ReadName(userName))
  185. return 0x880F;
  186. // Try to log the user in
  187. iRet = Login( userName,
  188. PossibleServer,
  189. password,
  190. TRUE );
  191. // Clear out the password
  192. memset( password, 0, sizeof( password ) );
  193. }
  194. // Add servername to list of attached servers, marked as 3X
  195. if ( !iRet )
  196. {
  197. AddServerToAttachList( PossibleServer, LIST_3X_SERVER );
  198. }
  199. else
  200. {
  201. iRet = 0x880F; // Special I am not attached error
  202. }
  203. return iRet;
  204. }