Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afssvrcfg / validation.cpp
blob1790bfd134ca2a62865df7041dad201374074ae2
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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 */
11 * INCLUDES _________________________________________________________________
14 #include <winsock2.h>
15 #include <ws2tcpip.h>
17 #include "afscfg.h"
18 #include "resource.h"
19 #include "validation.h"
23 * DEFINITIONS _________________________________________________________________
29 * PROTOTYPES _________________________________________________________________
32 static BOOL CheckAfsPartitionName(TCHAR *pszInput, int &nErrorMsgResID);
33 static BOOL CheckAfsCellName(TCHAR *pszInput, int &nErrorMsgResID);
34 static BOOL CheckAfsPassword(TCHAR *pszInput, int &nErrorMsgResID);
35 static BOOL CheckAfsUid(TCHAR *pszInput, int &nErrorMsgResID);
36 static BOOL CheckAfsServerName(TCHAR *pszInput, int &nErrorMsgResID);
37 static void ShowError(int nErrorMsgResID);
41 * EXPORTED FUNCTIONS _________________________________________________________________
44 BOOL Validation_IsValid(TCHAR *pszInput, VALIDATION_TYPE type, BOOL bShowError)
46 BOOL bValid;
47 int nErrorMsgResID;
49 switch (type) {
50 case VALID_AFS_PARTITION_NAME:
51 bValid = CheckAfsPartitionName(pszInput, nErrorMsgResID);
52 break;
54 case VALID_AFS_CELL_NAME:
55 bValid = CheckAfsCellName(pszInput, nErrorMsgResID);
56 break;
58 case VALID_AFS_PASSWORD:
59 bValid = CheckAfsPassword(pszInput, nErrorMsgResID);
60 break;
62 case VALID_AFS_UID:
63 bValid = CheckAfsUid(pszInput, nErrorMsgResID);
64 break;
66 case VALID_AFS_SERVER_NAME:
67 bValid = CheckAfsServerName(pszInput, nErrorMsgResID);
68 break;
70 default:
71 nErrorMsgResID = 0;
72 ASSERT(FALSE);
73 return FALSE;
76 if (!bValid && bShowError)
77 ShowError(nErrorMsgResID);
79 return bValid;
85 * STATIC FUNCTIONS _________________________________________________________________
90 * Utility Functions _________________________________________________________________
93 static BOOL CheckAfsPartitionName(TCHAR *pszPartitionName, int &nErrorMsgResID)
95 short bIsValid;
96 afs_status_t nStatus;
98 char *pszName = new char[strlen("/vicpe") + lstrlen(pszPartitionName) + 1];
99 if (!pszName) {
100 ASSERT(FALSE);
101 return TRUE;
104 strcpy(pszName, "/vicep");
105 strcat(pszName, S2A(pszPartitionName));
107 int nResult = cfg_HostPartitionNameValid(pszName, &bIsValid, &nStatus);
108 ASSERT(nResult);
110 if (!bIsValid)
111 nErrorMsgResID = IDS_PARTITION_NAME_VALIDATION_TYPE;
113 delete pszName;
115 return bIsValid;
118 static BOOL CheckAfsCellName(TCHAR *pszInput, int &nErrorMsgResID)
120 nErrorMsgResID = 0;
122 return TRUE;
125 static BOOL CheckAfsPassword(TCHAR *pszInput, int &nErrorMsgResID)
127 nErrorMsgResID = 0;
129 return TRUE;
132 static BOOL CheckAfsUid(TCHAR *pszInput, int &nErrorMsgResID)
134 nErrorMsgResID = 0;
136 return TRUE;
139 static BOOL CheckAfsServerName(TCHAR *pszInput, int &nErrorMsgResID)
141 nErrorMsgResID = 0;
143 return TRUE;
146 static void ShowError(int nErrorMsgResID)
148 Message(MB_ICONSTOP | MB_OK, GetAppTitleID(), IDS_VALIDATION_ERROR_TEMPLATE, TEXT("%m%m"), nErrorMsgResID, nErrorMsgResID);