40050a3e99dab3536406508050cd55ee772029da
[openafs.git] / src / WINNT / afssvrcfg / validation.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 /*
11 * INCLUDES _________________________________________________________________
12 *
13 */
14 #include "afscfg.h"
15 #include "resource.h"
16 #include "validation.h"
17
18
19 /*
20  * DEFINITIONS _________________________________________________________________
21  *
22  */
23
24
25 /*
26  * PROTOTYPES _________________________________________________________________
27  *
28  */
29 BOOL Validation_IsValid(TCHAR *pszInput, VALIDATION_TYPE type, BOOL bShowError);
30
31 static BOOL CheckAfsPartitionName(TCHAR *pszInput, int &nErrorMsgResID);
32 static BOOL CheckAfsCellName(TCHAR *pszInput, int &nErrorMsgResID);
33 static BOOL CheckAfsPassword(TCHAR *pszInput, int &nErrorMsgResID);
34 static BOOL CheckAfsUid(TCHAR *pszInput, int &nErrorMsgResID);
35 static BOOL CheckAfsServerName(TCHAR *pszInput, int &nErrorMsgResID);
36 static BOOL CheckFileName(TCHAR *pszInput, int &nErrorMsgResID);
37 static BOOL CheckPath(TCHAR *pszInput, int &nErrorMsgResID);
38 static void ShowError(int nErrorMsgResID);
39
40
41 /*
42  * EXPORTED FUNCTIONS _________________________________________________________________
43  *
44  */
45 BOOL Validation_IsValid(TCHAR *pszInput, VALIDATION_TYPE type, BOOL bShowError)
46 {
47     BOOL bValid;
48     int nErrorMsgResID;
49
50         switch (type) {
51                 case VALID_AFS_PARTITION_NAME:  bValid = CheckAfsPartitionName(pszInput, nErrorMsgResID);
52                                         break;
53
54         case VALID_AFS_CELL_NAME:               bValid = CheckAfsCellName(pszInput, nErrorMsgResID);
55                                         break;
56
57                 case VALID_AFS_PASSWORD:                bValid = CheckAfsPassword(pszInput, nErrorMsgResID);
58                                         break;
59
60                 case VALID_AFS_UID:                             bValid = CheckAfsUid(pszInput, nErrorMsgResID);
61                                         break;
62
63                 case VALID_AFS_SERVER_NAME:             bValid = CheckAfsServerName(pszInput, nErrorMsgResID);
64                                         break;
65
66                 default:                                                nErrorMsgResID = 0;
67                                                                                 ASSERT(FALSE);
68                                                                                 return FALSE;
69         }
70
71     if (!bValid && bShowError)
72         ShowError(nErrorMsgResID);
73
74     return bValid;
75 }
76
77
78
79 /*
80  * STATIC FUNCTIONS _________________________________________________________________
81  *
82  */
83
84  /*
85   * Utility Functions _________________________________________________________________
86   *
87   */
88 static BOOL CheckAfsPartitionName(TCHAR *pszPartitionName, int &nErrorMsgResID)
89 {
90     short bIsValid;
91     afs_status_t nStatus;
92
93     char *pszName = new char[strlen("/vicpe") + lstrlen(pszPartitionName) + 1];
94     if (!pszName) {
95         ASSERT(FALSE);
96         return TRUE;
97     }
98
99     strcpy(pszName, "/vicep");
100     strcat(pszName, S2A(pszPartitionName));
101
102     int nResult = cfg_HostPartitionNameValid(pszName, &bIsValid, &nStatus);
103     ASSERT(nResult);
104
105     if (!bIsValid)
106         nErrorMsgResID = IDS_PARTITION_NAME_VALIDATION_TYPE;
107
108     delete pszName;
109
110         return bIsValid;
111 }
112
113 static BOOL CheckAfsCellName(TCHAR *pszInput, int &nErrorMsgResID)
114 {
115         nErrorMsgResID = 0;
116
117         return TRUE;
118 }
119
120 static BOOL CheckAfsPassword(TCHAR *pszInput, int &nErrorMsgResID)
121 {
122         nErrorMsgResID = 0;
123
124         return TRUE;
125 }
126
127 static BOOL CheckAfsUid(TCHAR *pszInput, int &nErrorMsgResID)
128 {
129         nErrorMsgResID = 0;
130
131         return TRUE;
132 }
133
134 static BOOL CheckAfsServerName(TCHAR *pszInput, int &nErrorMsgResID)
135 {
136         nErrorMsgResID = 0;
137
138         return TRUE;
139 }
140
141 static void ShowError(int nErrorMsgResID)
142 {
143     Message(MB_ICONSTOP | MB_OK, GetAppTitleID(), IDS_VALIDATION_ERROR_TEMPLATE, TEXT("%m%m"), nErrorMsgResID, nErrorMsgResID);
144 }