Windows: permit aklog to build with krb4 support and roken
[openafs.git] / src / WINNT / afsadmsvr / TaAfsAdmSvrClientUser.cpp
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 <winsock2.h>
11 #include <ws2tcpip.h>
12
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
16 }
17
18 #include "TaAfsAdmSvrClientInternal.h"
19
20
21 /*
22  * ROUTINES ___________________________________________________________________
23  *
24  */
25
26 BOOL ADMINAPI asc_UserChange (UINT_PTR idClient, ASID idCell, ASID idUser, LPAFSADMSVR_CHANGEUSER_PARAMS pChange, ULONG *pStatus)
27 {
28    BOOL rc = TRUE;
29    ULONG status = 0;
30
31    RpcTryExcept
32       {
33       if ((rc = AfsAdmSvr_ChangeUser (idClient, idCell, idUser, pChange, &status)) != FALSE)
34          {
35          // If we succeeded in changing this user's properties, get the
36          // newest values for our cache.
37          //
38          ASOBJPROP Properties;
39          rc = asc_ObjectPropertiesGet (idClient, GET_ALL_DATA, idCell, idUser, &Properties, &status);
40          }
41       }
42    RpcExcept(1)
43       {
44       rc = FALSE;
45       status = RPC_S_CALL_FAILED_DNE;
46       }
47    RpcEndExcept
48
49    if (!rc && pStatus)
50       *pStatus = status;
51    return rc;
52 }
53
54
55 BOOL ADMINAPI asc_UserPasswordSet (UINT_PTR idClient, ASID idCell, ASID idUser, int keyVersion, LPCTSTR pkeyString, PBYTE pkeyData, ULONG *pStatus)
56 {
57    BOOL rc = TRUE;
58    ULONG status = 0;
59
60    RpcTryExcept
61       {
62       BYTE keyData[ ENCRYPTIONKEYLENGTH ];
63       if (pkeyData)
64          memcpy (keyData, pkeyData, sizeof(keyData));
65       else
66          memset (keyData, 0x00, sizeof(keyData));
67
68       STRING keyString;
69       if (pkeyString)
70          lstrcpy (keyString, pkeyString);
71       else
72          memset (keyString, 0x00, sizeof(keyString));
73
74       if ((rc = AfsAdmSvr_SetUserPassword (idClient, idCell, idUser, keyVersion, keyString, keyData, &status)) == TRUE)
75          {
76          // If we succeeded in changing this user's password, get the
77          // newest user properties for our cache.
78          //
79          ASOBJPROP Properties;
80          rc = asc_ObjectPropertiesGet (idClient, GET_ALL_DATA, idCell, idUser, &Properties, &status);
81          }
82       }
83    RpcExcept(1)
84       {
85       rc = FALSE;
86       status = RPC_S_CALL_FAILED_DNE;
87       }
88    RpcEndExcept
89
90    if (!rc && pStatus)
91       *pStatus = status;
92    return rc;
93 }
94
95
96 BOOL ADMINAPI asc_UserUnlock (UINT_PTR idClient, ASID idCell, ASID idUser, ULONG *pStatus)
97 {
98    BOOL rc = TRUE;
99    ULONG status = 0;
100
101    RpcTryExcept
102       {
103       if ((rc = AfsAdmSvr_UnlockUser (idClient, idCell, idUser, &status)) == TRUE)
104          {
105          // If we succeeded in unlocking this user's account, get the
106          // newest user properties for our cache.
107          //
108          ASOBJPROP Properties;
109          rc = asc_ObjectPropertiesGet (idClient, GET_ALL_DATA, idCell, idUser, &Properties, &status);
110          }
111       }
112    RpcExcept(1)
113       {
114       rc = FALSE;
115       status = RPC_S_CALL_FAILED_DNE;
116       }
117    RpcEndExcept
118
119    if (!rc && pStatus)
120       *pStatus = status;
121    return rc;
122 }
123
124
125 BOOL ADMINAPI asc_UserCreate (UINT_PTR idClient, ASID idCell, LPAFSADMSVR_CREATEUSER_PARAMS pCreate, ASID *pidUser, ULONG *pStatus)
126 {
127    BOOL rc = TRUE;
128    ULONG status = 0;
129
130    RpcTryExcept
131       {
132       if ((rc = AfsAdmSvr_CreateUser (idClient, idCell, pCreate, pidUser, &status)) == TRUE)
133          {
134          // If we succeeded in creating this user's account, get the
135          // initial user properties for our cache.
136          //
137          ASOBJPROP Properties;
138          rc = asc_ObjectPropertiesGet (idClient, GET_ALL_DATA, idCell, *pidUser, &Properties, &status);
139          }
140       }
141    RpcExcept(1)
142       {
143       rc = FALSE;
144       status = RPC_S_CALL_FAILED_DNE;
145       }
146    RpcEndExcept
147
148    if (!rc && pStatus)
149       *pStatus = status;
150    return rc;
151 }
152
153
154 BOOL ADMINAPI asc_UserDelete (UINT_PTR idClient, ASID idCell, ASID idUser, LPAFSADMSVR_DELETEUSER_PARAMS pDelete, ULONG *pStatus)
155 {
156    BOOL rc = TRUE;
157    ULONG status = 0;
158
159    RpcTryExcept
160       {
161       if ((rc = AfsAdmSvr_DeleteUser (idClient, idCell, idUser, pDelete, &status)) == TRUE)
162          {
163          // If we succeeded in deleting this user's account, clean up our cache.
164          // Expect this call to fail (the user's deleted, right?)
165          //
166          ASOBJPROP Properties;
167          ULONG dummy;
168          (void)asc_ObjectPropertiesGet (idClient, GET_ALL_DATA, idCell, idUser, &Properties, &dummy);
169          }
170       }
171    RpcExcept(1)
172       {
173       rc = FALSE;
174       status = RPC_S_CALL_FAILED_DNE;
175       }
176    RpcEndExcept
177
178    if (!rc && pStatus)
179       *pStatus = status;
180    return rc;
181 }
182