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.

359 lines
9.0 KiB

  1. /*************************************************************************
  2. *
  3. * NTSCRIPT.C
  4. *
  5. * Process all login scripts
  6. *
  7. * Copyright (c) 1995 Microsoft Corporation
  8. *
  9. * $Log: N:\NT\PRIVATE\NW4\NWSCRIPT\VCS\NTSCRIPT.C $
  10. *
  11. * Rev 1.8 10 Apr 1996 14:23:12 terryt
  12. * Hotfix for 21181hq
  13. *
  14. * Rev 1.9 12 Mar 1996 19:54:58 terryt
  15. * Relative NDS names and merge
  16. *
  17. * Rev 1.8 07 Mar 1996 18:36:56 terryt
  18. * Misc fixes
  19. *
  20. * Rev 1.7 22 Jan 1996 16:48:26 terryt
  21. * Add automatic attach query during map
  22. *
  23. * Rev 1.6 08 Jan 1996 13:57:58 terryt
  24. * Correct NDS Preferred Server
  25. *
  26. * Rev 1.5 05 Jan 1996 17:18:26 terryt
  27. * Ensure context is the correct login default
  28. *
  29. * Rev 1.4 04 Jan 1996 18:56:48 terryt
  30. * Bug fixes reported by MS
  31. *
  32. * Rev 1.3 22 Dec 1995 11:08:16 terryt
  33. * Fixes
  34. *
  35. * Rev 1.2 22 Nov 1995 15:43:52 terryt
  36. * Use proper NetWare user name call
  37. *
  38. * Rev 1.1 20 Nov 1995 15:09:38 terryt
  39. * Context and capture changes
  40. *
  41. * Rev 1.0 15 Nov 1995 18:07:28 terryt
  42. * Initial revision.
  43. *
  44. * Rev 1.2 25 Aug 1995 16:23:14 terryt
  45. * Capture support
  46. *
  47. * Rev 1.1 26 Jul 1995 16:02:00 terryt
  48. * Allow deletion of current drive
  49. *
  50. * Rev 1.0 15 May 1995 19:10:46 terryt
  51. * Initial revision.
  52. *
  53. *************************************************************************/
  54. #include <stdio.h>
  55. #include <stdlib.h>
  56. #include <time.h>
  57. #include <direct.h>
  58. #include <process.h>
  59. #include <string.h>
  60. #include <malloc.h>
  61. #include "common.h"
  62. #include "inc/ntnw.h"
  63. #include <nwapi.h>
  64. void ProcessLoginScripts(unsigned int conn, char * UserName, int argc, char **argv, char *lpScript);
  65. extern int SafeDisk;
  66. extern unsigned int ConvertNDSPathToNetWarePath(char *, char *, char *);
  67. /*************************************************************************
  68. *
  69. * NTNetWareLoginScripts
  70. * Main logon script processor
  71. *
  72. * ENTRY:
  73. *
  74. * EXIT
  75. *
  76. *************************************************************************/
  77. int
  78. NTNetWareLoginScripts( int argc, char ** argv )
  79. {
  80. unsigned int defConn;
  81. char UserName[MAX_NAME_LEN]="";
  82. WCHAR UserName_w[MAX_NAME_LEN * sizeof(WCHAR)]=L"";
  83. char MessageServer[NDS_NAME_CHARS]="";
  84. char *lpScript = NULL;
  85. DWORD PrintOptions;
  86. LPTSTR pszPreferredSrv;
  87. LPTSTR ptreeW;
  88. LPTSTR pcontextW;
  89. NTSTATUS ntstatus;
  90. char * lpC1;
  91. char * lpC2;
  92. unsigned int NewConn;
  93. unsigned int Result;
  94. if ( NwQueryInfo( &PrintOptions, &pszPreferredSrv ) || !pszPreferredSrv )
  95. {
  96. DisplayMessage(IDR_QUERY_INFO_FAILED);
  97. return( FALSE );
  98. }
  99. //
  100. // nwscript /S filename
  101. //
  102. // can be used to pass a local script file for testing
  103. //
  104. if ( ( argc >= 3 ) && !_strcmpi(argv[1], "/S") )
  105. {
  106. lpScript = argv[2];
  107. argc -= 2;
  108. argv += 2;
  109. }
  110. //
  111. // NDS preferred server format is:
  112. // *<tree name>\<context>
  113. fNDS = ( *pszPreferredSrv == L'*' );
  114. if ( fNDS )
  115. {
  116. // Get the NDS tree name
  117. ptreeW = pszPreferredSrv + 1;
  118. pcontextW = wcschr( pszPreferredSrv, L'\\' );
  119. if ( pcontextW )
  120. {
  121. *pcontextW++ = L'\0';
  122. }
  123. NDSTREE = malloc ( CONTEXT_MAX );
  124. if (NDSTREE == NULL) {
  125. goto ExitWithError;
  126. }
  127. NDSTREE_w = malloc ( CONTEXT_MAX * sizeof(WCHAR) );
  128. if (NDSTREE_w == NULL) {
  129. goto ExitWithError;
  130. }
  131. if ( ptreeW )
  132. {
  133. wcscpy( NDSTREE_w, ptreeW );
  134. RtlInitUnicodeString( &NDSTREE_u, NDSTREE_w );
  135. WideTosz( NDSTREE, ptreeW, CONTEXT_MAX );
  136. _strupr( NDSTREE );
  137. }
  138. else
  139. {
  140. strcpy( NDSTREE, "" );
  141. wcscpy( NDSTREE_w, L"" );
  142. }
  143. // Get the fully typed user name
  144. TYPED_USER_NAME_w = malloc ( sizeof(WCHAR) * NDS_NAME_CHARS );
  145. if (TYPED_USER_NAME_w == NULL) {
  146. goto ExitWithError;
  147. }
  148. TYPED_USER_NAME = malloc ( NDS_NAME_CHARS );
  149. if (TYPED_USER_NAME == NULL) {
  150. goto ExitWithError;
  151. }
  152. ntstatus = NTGetNWUserName( NDSTREE_w, TYPED_USER_NAME_w,
  153. sizeof(WCHAR) * NDS_NAME_CHARS );
  154. if ( !NT_SUCCESS( ntstatus ) ) {
  155. DisplayMessage(IDR_QUERY_INFO_FAILED);
  156. return ( FALSE );
  157. }
  158. WideTosz( TYPED_USER_NAME, TYPED_USER_NAME_w, NDS_NAME_CHARS );
  159. // Get the user name stripped of context and type
  160. lpC1 = strchr( TYPED_USER_NAME, '=' );
  161. if ( lpC1 )
  162. lpC1++;
  163. else
  164. lpC1 = TYPED_USER_NAME;
  165. lpC2 = strchr( TYPED_USER_NAME, '.' );
  166. while ( lpC2 ) // Handle usernames with embedded/escaped dots ("\.")
  167. {
  168. if (*(lpC2-1) == '\\')
  169. lpC2 = strchr(lpC2+1, '.');
  170. else
  171. break;
  172. }
  173. if ( lpC2 )
  174. strncpy( UserName, lpC1, (UINT)(lpC2 - lpC1) );
  175. else
  176. strcpy( UserName, lpC1 );
  177. // Get the default context
  178. // This should be where the user is
  179. REQUESTER_CONTEXT = malloc( CONTEXT_MAX );
  180. if (REQUESTER_CONTEXT == NULL) {
  181. goto ExitWithError;
  182. }
  183. if ( lpC2 )
  184. {
  185. strcpy( REQUESTER_CONTEXT, lpC2+1 );
  186. }
  187. else
  188. {
  189. strcpy( REQUESTER_CONTEXT, "" );
  190. }
  191. NDSTypeless( REQUESTER_CONTEXT, REQUESTER_CONTEXT );
  192. //
  193. // This finishes the NDS initialization
  194. //
  195. if ( NDSInitUserProperty () )
  196. return ( FALSE );
  197. }
  198. else
  199. {
  200. ntstatus = NTGetNWUserName( pszPreferredSrv, UserName_w,
  201. MAX_NAME_LEN * sizeof(WCHAR) );
  202. if ( !NT_SUCCESS( ntstatus ) ) {
  203. DisplayMessage(IDR_QUERY_INFO_FAILED);
  204. return ( FALSE );
  205. }
  206. WideTosz( UserName, UserName_w, MAX_NAME_LEN );
  207. _strupr( UserName );
  208. }
  209. //
  210. // If we map over a drive, the SafeDisk is used.
  211. //
  212. SafeDisk = _getdrive();
  213. NTInitProvider();
  214. //
  215. // Get the default connection handle.
  216. //
  217. // This is used to get the preferred server!
  218. if ( !CGetDefaultConnectionID (&defConn) )
  219. return( FALSE );
  220. PREFERRED_SERVER = malloc( NDS_NAME_CHARS );
  221. if (PREFERRED_SERVER == NULL) {
  222. goto ExitWithError;
  223. }
  224. GetFileServerName(defConn, PREFERRED_SERVER);
  225. //
  226. // By default we are "attached" to the default server
  227. //
  228. if ( fNDS )
  229. AddServerToAttachList( PREFERRED_SERVER, LIST_4X_SERVER );
  230. else
  231. AddServerToAttachList( PREFERRED_SERVER, LIST_3X_SERVER );
  232. //
  233. // Print out status
  234. //
  235. if ( fNDS )
  236. {
  237. DisplayMessage( IDR_CURRENT_CONTEXT, REQUESTER_CONTEXT );
  238. DisplayMessage( IDR_CURRENT_TREE, NDSTREE_w );
  239. }
  240. DisplayMessage( IDR_CURRENT_SERVER, PREFERRED_SERVER );
  241. //
  242. // We may want to change the Preferred Server based on the DS.
  243. // "MESSAGE_SERVER" should be the Preferred Server (if possible).
  244. //
  245. if ( fNDS )
  246. {
  247. NDSGetVar ( "MESSAGE_SERVER", MessageServer, NDS_NAME_CHARS );
  248. if ( strlen( MessageServer ) )
  249. {
  250. NDSAbbreviateName(FLAGS_NO_CONTEXT, MessageServer, MessageServer);
  251. lpC1 = strchr( MessageServer, '.' );
  252. if ( lpC1 )
  253. *lpC1 = '\0';
  254. if ( strcmp( MessageServer, PREFERRED_SERVER) )
  255. {
  256. DisplayMessage( IDR_AUTHENTICATING_SERVER, MessageServer );
  257. Result = NTAttachToFileServer( MessageServer, &NewConn );
  258. if ( Result )
  259. {
  260. DisplayMessage( IDR_SERVER_NOT_FOUND, MessageServer );
  261. }
  262. else
  263. {
  264. NWDetachFromFileServer( (NWCONN_HANDLE)NewConn );
  265. strncpy( PREFERRED_SERVER, MessageServer, NDS_NAME_CHARS);
  266. DisplayMessage( IDR_CURRENT_SERVER, PREFERRED_SERVER );
  267. // By default we are "attached" to the preferred server
  268. AddServerToAttachList( PREFERRED_SERVER, LIST_4X_SERVER );
  269. }
  270. }
  271. }
  272. }
  273. //
  274. // Just like login we ignore any errors from setting the login
  275. // directory.
  276. //
  277. SetLoginDirectory (PREFERRED_SERVER);
  278. // Process login scripts.
  279. ProcessLoginScripts(defConn, UserName, argc, argv, lpScript);
  280. return( TRUE );
  281. ExitWithError:
  282. if (NDSTREE) {
  283. free(NDSTREE);
  284. NDSTREE = NULL;
  285. }
  286. if (NDSTREE_w) {
  287. free(NDSTREE_w);
  288. NDSTREE_w = NULL;
  289. }
  290. if (TYPED_USER_NAME) {
  291. free(TYPED_USER_NAME);
  292. TYPED_USER_NAME = NULL;
  293. }
  294. if (TYPED_USER_NAME_w) {
  295. free(TYPED_USER_NAME_w);
  296. TYPED_USER_NAME_w = NULL;
  297. }
  298. if (REQUESTER_CONTEXT) {
  299. free(REQUESTER_CONTEXT);
  300. REQUESTER_CONTEXT = NULL;
  301. }
  302. if (PREFERRED_SERVER) {
  303. free(PREFERRED_SERVER);
  304. PREFERRED_SERVER = NULL;
  305. }
  306. return FALSE;
  307. }