fix-typo-20040316
[openafs.git] / src / WINNT / afsd / afslog95.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afs/param.h>
11 #include <afs/stds.h>
12
13 #include <windows.h>
14 #include <NETSPI.h>
15 #include <winsock2.h>
16 #include <afs/pioctl_nt.h>
17 #include <afs/kautils.h>
18 #include "cm_config.h"
19 #include "krb.h"
20
21 HANDLE hDLL;
22
23 WSADATA WSAjunk;
24
25 char NPName95[] = "System\\CurrentControlSet\\Services\\TransarcAFSDaemon\\NetworkProvider";
26
27 /*
28  * GetLogonScript
29  *
30  * We get a logon script pathname from the HKEY_LOCAL_MACHINE registry.
31  * I don't know what good this does; I just copied it from DFS.
32  *
33  * Returns NULL on failure.
34  */
35 WCHAR *GetLogonScript(void)
36 {
37         WCHAR *script;
38         DWORD code;
39         DWORD LSPtype, LSPsize;
40         HKEY NPKey;
41
42         /*
43          * Get Network Provider key.
44          * Assume this works or we wouldn't be here.
45          */
46         (void) RegOpenKeyEx(HKEY_LOCAL_MACHINE, NPName95,
47                             0, KEY_QUERY_VALUE, &NPKey);
48
49         /*
50          * Get Logon Script pathname length
51          */
52         code = RegQueryValueEx(NPKey, "LogonScript", NULL,
53                                 &LSPtype, NULL, &LSPsize);
54
55         if (code) {
56                 RegCloseKey (NPKey);
57                 return NULL;
58         }
59
60         if (LSPtype != REG_SZ) {        /* Maybe handle REG_EXPAND_SZ? */
61                 RegCloseKey (NPKey);
62                 return NULL;
63         }
64
65         script = (WCHAR *)LocalAlloc(LMEM_FIXED, LSPsize);
66
67         /*
68          * Explicitly call UNICODE version
69          * Assume it will succeed since it did before
70          */
71         (void) RegQueryValueExW(NPKey, L"LogonScript", NULL,
72                                 &LSPtype, (LPBYTE)script, &LSPsize);
73
74         RegCloseKey (NPKey);
75         return script;
76 }
77
78 DWORD MapAuthError(DWORD code)
79 {
80         switch (code) {
81                 case INTK_BADPW: return WN_BAD_PASSWORD;
82                 case KERB_ERR_PRINCIPAL_UNKNOWN: return WN_BAD_USER;
83                 default: return WN_NO_NETWORK;
84         }
85 }
86
87 BOOLEAN APIENTRY DllEntryPoint(HANDLE dll, DWORD reason, PVOID reserved)
88 {
89         hDLL = dll;
90         switch (reason) {
91                 case DLL_PROCESS_ATTACH:
92                         /* Initialize AFS libraries */
93                         rx_Init(0);
94                         ka_Init(0);
95                         break;
96
97                 /* Everything else succeeds but does nothing. */
98                 case DLL_PROCESS_DETACH:
99                 case DLL_THREAD_ATTACH:
100                 case DLL_THREAD_DETACH:
101                 default:
102                         break;
103         }
104
105         return TRUE;
106 }
107
108 DWORD APIENTRY NPGetCaps(DWORD index)
109 {
110         switch (index) {
111                 case WNNC_SPEC_VERSION:
112                         return WNNC_SPEC_VERSION51;
113                 case WNNC_NET_TYPE:
114                         /* Don't have our own type; use somebody else's. */
115                         return WNNC_NET_LANMAN;
116                 case WNNC_DRIVER_VERSION:
117                         return WNNC_DRIVER(1,1);
118                 case WNNC_START:
119                         return WNNC_START_DONE;
120                 case WNNC_AUTHENTICATION:
121                         return WNNC_AUTH_LOGON | WNNC_AUTH_LOGOFF;
122                 default:
123                         return 0;
124         }
125 }
126
127 DWORD APIENTRY NPLogon(
128         HWND hwndOwner,
129         LPLOGONINFO lpAuthentInfo,
130         LPLOGONINFO lpPreviousAuthentInfo,
131         LPTSTR lpLogonScript,
132         DWORD dwBufferSize,
133         DWORD dwFlags)
134 {
135         DWORD code;
136         int pw_exp;
137         char *reason;
138         char cell[256];
139
140         if (dwFlags & LOGON_DONE)
141                 return 0;
142
143         /* Check for zero length password */
144         if (lpAuthentInfo->lpUsername[0] == 0) {
145                 code = GT_PW_NULL;
146                 reason = "zero length password is illegal";
147                 goto checkauth;
148         }
149
150         /* Get cell name */
151         code = cm_GetRootCellName(cell);
152         if (code < 0) {
153                 code = KTC_NOCELL;
154                 reason = "unknown cell";
155                 goto checkauth;
156         }
157
158         code = ka_UserAuthenticateGeneral(
159                 KA_USERAUTH_VERSION + KA_USERAUTH_AUTHENT_LOGON,
160                 lpAuthentInfo->lpUsername,
161                 "", cell,
162                 lpAuthentInfo->lpPassword,
163                 0, &pw_exp, 0, &reason);
164
165 checkauth:
166         if (code) {
167                 MessageBox(hwndOwner, reason, "AFS logon", MB_OK);
168                 code = MapAuthError(code);
169         }
170
171         return code;
172 }
173
174 DWORD APIENTRY NPLogoff(
175         HWND hwndOwner,
176         LPLOGONINFO lpAuthentInfo,
177         DWORD dwReason)
178 {
179         return 0;
180 }