~ubuntu-branches/ubuntu/warty/openafs/warty

« back to all changes in this revision

Viewing changes to src/WINNT/afsusrmgr/usr_cpw.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hartman
  • Date: 2004-01-10 16:37:33 UTC
  • Revision ID: james.westby@ubuntu.com-20040110163733-jvr0n1uahshlb1uu
Tags: upstream-1.2.11
ImportĀ upstreamĀ versionĀ 1.2.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
extern "C" {
 
11
#include <afs/param.h>
 
12
#include <afs/stds.h>
 
13
}
 
14
 
 
15
#include "TaAfsUsrMgr.h"
 
16
#include "usr_cpw.h"
 
17
#include "usr_col.h"
 
18
 
 
19
 
 
20
/*
 
21
 * DEFINITIONS ________________________________________________________________
 
22
 *
 
23
 */
 
24
 
 
25
 
 
26
/*
 
27
 * PROTOTYPES _________________________________________________________________
 
28
 *
 
29
 */
 
30
 
 
31
BOOL CALLBACK User_Password_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
 
32
void User_Password_OnInitDialog (HWND hDlg);
 
33
BOOL User_Password_OnOK (HWND hDlg);
 
34
void User_Password_OnSelectVer (HWND hDlg);
 
35
void User_Password_OnSelectType (HWND hDlg);
 
36
void User_Password_OnType (HWND hDlg);
 
37
void User_Password_OnRandom (HWND hDlg);
 
38
void User_Password_OnEndTask_Random (HWND hDlg, LPTASKPACKET ptp);
 
39
 
 
40
 
 
41
/*
 
42
 * ROUTINES ___________________________________________________________________
 
43
 *
 
44
 */
 
45
 
 
46
void User_ShowChangePassword (HWND hParent, ASID idUser)
 
47
{
 
48
   ModalDialogParam (IDD_USER_PASSWORD, hParent, (DLGPROC)User_Password_DlgProc, (LPARAM)idUser);
 
49
}
 
50
 
 
51
 
 
52
BOOL CALLBACK User_Password_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
 
53
{
 
54
   if (AfsAppLib_HandleHelp (IDD_USER_PASSWORD, hDlg, msg, wp, lp))
 
55
      return TRUE;
 
56
 
 
57
   switch (msg)
 
58
      {
 
59
      case WM_INITDIALOG:
 
60
         SetWindowLong (hDlg, DWL_USER, lp);
 
61
         User_Password_OnInitDialog (hDlg);
 
62
         break;
 
63
 
 
64
      case WM_ENDTASK:
 
65
         LPTASKPACKET ptp;
 
66
         if ((ptp = (LPTASKPACKET)lp) != NULL)
 
67
            {
 
68
            if (ptp->idTask == taskGET_RANDOM_KEY)
 
69
               User_Password_OnEndTask_Random (hDlg, ptp);
 
70
            FreeTaskPacket (ptp);
 
71
            }
 
72
         break;
 
73
 
 
74
      case WM_COMMAND:
 
75
         switch (LOWORD(wp))
 
76
            {
 
77
            case IDOK:
 
78
               if (User_Password_OnOK (hDlg))
 
79
                  EndDialog (hDlg, IDOK);
 
80
               break;
 
81
 
 
82
            case IDCANCEL:
 
83
               EndDialog (hDlg, IDCANCEL);
 
84
               break;
 
85
 
 
86
            case IDC_CPW_VERSION_AUTO:
 
87
            case IDC_CPW_VERSION_MANUAL:
 
88
               User_Password_OnSelectVer (hDlg);
 
89
               break;
 
90
 
 
91
            case IDC_CPW_BYSTRING:
 
92
            case IDC_CPW_BYDATA:
 
93
               User_Password_OnSelectType (hDlg);
 
94
               break;
 
95
 
 
96
            case IDC_CPW_STRING:
 
97
            case IDC_CPW_DATA:
 
98
               User_Password_OnType (hDlg);
 
99
               break;
 
100
 
 
101
            case IDC_CPW_RANDOM:
 
102
               User_Password_OnRandom (hDlg);
 
103
               break;
 
104
            }
 
105
         break;
 
106
      }
 
107
 
 
108
   return FALSE;
 
109
}
 
110
 
 
111
 
 
112
void User_Password_OnInitDialog (HWND hDlg)
 
113
{
 
114
   ASID idUser = (ASID)GetWindowLong (hDlg, DWL_USER);
 
115
 
 
116
   // Get the current properties for this user
 
117
   //
 
118
   ULONG status;
 
119
   TCHAR szName[ cchNAME ];
 
120
   User_GetDisplayName (szName, idUser);
 
121
 
 
122
   ASOBJPROP Properties;
 
123
   if (!asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, idUser, &Properties, &status))
 
124
      {
 
125
      ErrorDialog (status, IDS_ERROR_CANT_GET_USERPROP, TEXT("%s"), szName);
 
126
      EndDialog (hDlg, IDCANCEL);
 
127
      return;
 
128
      }
 
129
 
 
130
   // Fill in the text at the top of the dialog
 
131
   //
 
132
   TCHAR szOld[ cchRESOURCE ];
 
133
   GetDlgItemText (hDlg, IDC_CPW_TITLE, szOld, cchRESOURCE);
 
134
 
 
135
   LPTSTR pszText = FormatString (szOld, TEXT("%s"), szName);
 
136
   SetDlgItemText (hDlg, IDC_CPW_TITLE, pszText);
 
137
   FreeString (pszText);
 
138
 
 
139
   // Check the appropriate radio buttons, etc
 
140
   //
 
141
   CheckDlgButton (hDlg, IDC_CPW_VERSION_AUTO, TRUE);
 
142
   CheckDlgButton (hDlg, IDC_CPW_BYSTRING, TRUE);
 
143
   CreateSpinner (GetDlgItem (hDlg, IDC_CPW_VERSION), 10, FALSE, 1, 1+Properties.u.UserProperties.KASINFO.keyVersion, 255);
 
144
   User_Password_OnSelectType (hDlg);
 
145
   User_Password_OnSelectVer (hDlg);
 
146
}
 
147
 
 
148
 
 
149
void User_Password_OnSelectVer (HWND hDlg)
 
150
{
 
151
   EnableWindow (GetDlgItem (hDlg, IDC_CPW_VERSION), IsDlgButtonChecked (hDlg, IDC_CPW_VERSION_MANUAL));
 
152
}
 
153
 
 
154
 
 
155
void User_Password_OnSelectType (HWND hDlg)
 
156
{
 
157
   EnableWindow (GetDlgItem (hDlg, IDC_CPW_STRING), IsDlgButtonChecked (hDlg, IDC_CPW_BYSTRING));
 
158
   EnableWindow (GetDlgItem (hDlg, IDC_CPW_DATA),   IsDlgButtonChecked (hDlg, IDC_CPW_BYDATA));
 
159
   EnableWindow (GetDlgItem (hDlg, IDC_CPW_RANDOM), IsDlgButtonChecked (hDlg, IDC_CPW_BYDATA));
 
160
   User_Password_OnType (hDlg);
 
161
}
 
162
 
 
163
 
 
164
void User_Password_OnType (HWND hDlg)
 
165
{
 
166
   BOOL fEnable = FALSE;
 
167
 
 
168
   if (IsDlgButtonChecked (hDlg, IDC_CPW_BYSTRING))
 
169
      {
 
170
      TCHAR szKey[ cchRESOURCE ];
 
171
      GetDlgItemText (hDlg, IDC_CPW_STRING, szKey, cchRESOURCE);
 
172
      if (szKey[0] != TEXT('\0'))
 
173
         fEnable = TRUE;
 
174
      }
 
175
   else // (IsDlgButtonChecked (hDlg, IDC_CPW_BYDATA))
 
176
      {
 
177
      TCHAR szKey[ cchRESOURCE ];
 
178
      GetDlgItemText (hDlg, IDC_CPW_DATA, szKey, cchRESOURCE);
 
179
 
 
180
      BYTE key[ ENCRYPTIONKEYLENGTH ];
 
181
      if (ScanServerKey (key, szKey))
 
182
         fEnable = TRUE;
 
183
      }
 
184
 
 
185
   EnableWindow (GetDlgItem (hDlg, IDOK), fEnable);
 
186
}
 
187
 
 
188
 
 
189
void User_Password_OnRandom (HWND hDlg)
 
190
{
 
191
   StartTask (taskGET_RANDOM_KEY, hDlg, 0);
 
192
}
 
193
 
 
194
 
 
195
BOOL User_Password_OnOK (HWND hDlg)
 
196
{
 
197
   ASID idUser = (ASID)GetWindowLong (hDlg, DWL_USER);
 
198
 
 
199
   LPUSER_CPW_PARAMS lpp = New (USER_CPW_PARAMS);
 
200
   memset (lpp, 0x00, sizeof(USER_CPW_PARAMS));
 
201
   lpp->idUser = idUser;
 
202
 
 
203
   if (IsDlgButtonChecked (hDlg, IDC_CPW_VERSION_MANUAL))
 
204
      lpp->keyVersion = SP_GetPos (GetDlgItem (hDlg, IDC_CPW_VERSION));
 
205
   else // (IsDlgButtonChecked (hDlg, IDC_CPW_VERSION_AUTO))
 
206
      lpp->keyVersion = 0;
 
207
 
 
208
   if (IsDlgButtonChecked (hDlg, IDC_CPW_BYSTRING))
 
209
      {
 
210
      GetDlgItemText (hDlg, IDC_CPW_STRING, lpp->keyString, cchRESOURCE);
 
211
      }
 
212
   else // (IsDlgButtonChecked (hDlg, IDC_CPW_BYDATA))
 
213
      {
 
214
      TCHAR szKey[ cchRESOURCE ];
 
215
      GetDlgItemText (hDlg, IDC_CPW_DATA, szKey, cchRESOURCE);
 
216
 
 
217
      if (!ScanServerKey (lpp->keyData, szKey))
 
218
         {
 
219
         Delete (lpp);
 
220
         return FALSE;
 
221
         }
 
222
      }
 
223
 
 
224
   StartTask (taskUSER_CPW, NULL, lpp);
 
225
   return TRUE;
 
226
}
 
227
 
 
228
 
 
229
void User_Password_OnEndTask_Random (HWND hDlg, LPTASKPACKET ptp)
 
230
{
 
231
   if (!ptp->rc)
 
232
      {
 
233
      ErrorDialog (ptp->status, IDS_ERROR_CANT_GET_RANDOM_KEY);
 
234
      EnableWindow (GetDlgItem (hDlg, IDC_CPW_RANDOM), FALSE);
 
235
      }
 
236
   else
 
237
      {
 
238
      TCHAR szKey[ cchRESOURCE ];
 
239
      FormatServerKey (szKey, TASKDATA(ptp)->key);
 
240
      SetDlgItemText (hDlg, IDC_CPW_DATA, szKey);
 
241
      }
 
242
}
 
243