2 * Copyright 2000, International Business Machines Corporation and others.
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
10 /* Manual utility for testing registry access functions. Also serves
11 * as a pre Configuration Manager registry configuration utility.
14 #include <afs/param.h>
24 #include <afs/param.h>
26 #include <afs/com_err.h>
28 #include <afs/dirpath.h>
30 #include <WINNT/afsreg.h>
31 #include <WINNT/afssw.h>
32 #include <WINNT/vptab.h>
38 static int DoVptList(struct cmd_syndesc *as, void *arock)
40 struct vpt_iter vpiter;
43 if (!vpt_Start(&vpiter)) {
44 while (!vpt_NextEntry(&vpiter, &vpentry)) {
45 printf("Partition: %s Device: %s\n",
46 vpentry.vp_name, vpentry.vp_dev);
49 (void)vpt_Finish(&vpiter);
54 static int DoVptAdd(struct cmd_syndesc *as, void *arock)
59 vpName = as->parms[0].items->data;
60 vpDev = as->parms[1].items->data;
62 if (!vpt_PartitionNameValid(vpName)) {
63 afs_com_err(whoami, 0, "Partition name invalid");
67 if (!vpt_DeviceNameValid(vpDev)) {
68 afs_com_err(whoami, 0, "Device name invalid");
72 strcpy(vpentry.vp_name, vpName);
73 strcpy(vpentry.vp_dev, vpDev);
75 if (vpt_AddEntry(&vpentry)) {
76 afs_com_err(whoami, 0, "Unable to create vice partition table entry");
82 static int DoVptDel(struct cmd_syndesc *as, void *arock)
86 vpName = as->parms[0].items->data;
88 if (!vpt_PartitionNameValid(vpName)) {
89 afs_com_err(whoami, 0, "Partition name invalid");
93 if (vpt_RemoveEntry(vpName) && errno != ENOENT) {
94 afs_com_err(whoami, 0, "Unable to remove vice partition table entry");
101 static int DoDirGet(struct cmd_syndesc *as, void *arock)
105 if (afssw_GetServerInstallDir(&buf)) {
106 afs_com_err(whoami, 0,
107 "Failed reading AFS install dir entry (or does not exist)");
111 printf("AFS server installation directory: %s\n", buf);
118 static int DoDirSet(struct cmd_syndesc *as, void *arock)
124 afsPath = as->parms[0].items->data;
126 /* open AFS sw version key; create if does not exist */
127 status = RegOpenKeyAlt(AFSREG_NULL_KEY, AFSREG_SVR_SW_VERSION_KEY,
128 KEY_WRITE, 1 /* create */, &key, NULL);
130 if (status == ERROR_SUCCESS) {
131 /* write AFS directory value */
132 status = RegSetValueEx(key, AFSREG_SVR_SW_VERSION_DIR_VALUE,
133 0, REG_SZ, afsPath, strlen(afsPath) + 1);
139 afs_com_err(whoami, 0, "Unable to set AFS installation directory entry");
142 return (status ? 1 : 0);
146 static int DoBosCfg(struct cmd_syndesc *as, void *arock)
148 char *bosSvcPath = NULL;
149 SC_HANDLE scmHandle = NULL, svcHandle = NULL;
152 /* determine if using specified or default service binary path */
153 if (as->parms[0].items) {
154 /* BOS control service binary path specified */
155 if (asprintf(&bosSvcPath, "\"%s\"", as->parms[0].items->data) < 0) {
156 afs_com_err(whoami, 0, "out of memory building binary path");
160 /* no BOS control service binary path specified; check for default */
163 if (afssw_GetServerInstallDir(&dirBuf)) {
164 afs_com_err(whoami, 0,
165 "binary path not specified and AFS server installation directory not set");
168 if (asprintf(&bosSvcPath, "\"%s%s/%s\"",
170 AFSDIR_CANONICAL_SERVER_BIN_DIRPATH,
171 AFSREG_SVR_SVC_IMAGENAME_DATA) < 0) {
172 afs_com_err(whoami, 0, "out of memory building binary path");
177 /* create BOS control service */
178 scmHandle = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
180 if (scmHandle == NULL) {
181 DWORD status = GetLastError();
184 if (status == ERROR_ACCESS_DENIED) {
185 reason = "(insufficient privilege)";
187 afs_com_err(whoami, 0, "unable to connect to the SCM %s", reason);
192 svcHandle = CreateService(scmHandle,
194 AFSREG_SVR_SVC_DISPLAYNAME_DATA,
195 STANDARD_RIGHTS_REQUIRED,
196 SERVICE_WIN32_OWN_PROCESS,
198 SERVICE_ERROR_NORMAL,
200 NULL, /* load order group */
202 NULL, /* dependencies */
203 NULL, /* service start name */
204 NULL); /* password */
206 if (svcHandle == NULL) {
207 DWORD status = GetLastError();
210 if (status == ERROR_SERVICE_EXISTS || status == ERROR_DUP_NAME) {
211 reason = "(service or display name already exists)";
213 afs_com_err(whoami, 0, "unable to create service %s", reason);
221 if (svcHandle != NULL)
222 CloseServiceHandle(svcHandle);
223 if (scmHandle != NULL)
224 CloseServiceHandle(scmHandle);
229 static int DoBosDel(struct cmd_syndesc *as, void *arock)
232 SC_HANDLE scmHandle, svcHandle;
234 scmHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
236 if (scmHandle == NULL) {
237 DWORD status = GetLastError();
240 if (status == ERROR_ACCESS_DENIED) {
241 reason = "(insufficient privilege)";
243 afs_com_err(whoami, 0, "unable to connect to the SCM %s", reason);
247 svcHandle = OpenService(scmHandle,
248 AFSREG_SVR_SVC_NAME, STANDARD_RIGHTS_REQUIRED);
250 if (svcHandle == NULL) {
251 DWORD status = GetLastError();
253 if (status != ERROR_SERVICE_DOES_NOT_EXIST) {
254 afs_com_err(whoami, 0, "unable to open service");
257 CloseServiceHandle(scmHandle);
261 if (!DeleteService(svcHandle)) {
262 DWORD status = GetLastError();
264 if (status != ERROR_SERVICE_MARKED_FOR_DELETE) {
265 afs_com_err(whoami, 0, "service delete failed");
269 CloseServiceHandle(svcHandle);
270 CloseServiceHandle(scmHandle);
274 static int DoVersionGet(struct cmd_syndesc *as, void *arock)
276 unsigned major, minor, patch;
280 if (!afssw_GetClientVersion(&major, &minor, &patch)) {
281 printf("Client: major = %u, minor = %u, patch = %u\n",
282 major, minor, patch);
284 printf("Client version information not available.\n");
287 if (!afssw_GetServerVersion(&major, &minor, &patch)) {
288 printf("Server: major = %u, minor = %u, patch = %u\n",
289 major, minor, patch);
291 printf("Server version information not available.\n");
300 struct cmd_syndesc *ts;
302 ts = cmd_CreateSyntax("vptlist", DoVptList, NULL, 0,
303 "list vice partition table");
305 ts = cmd_CreateSyntax("vptadd", DoVptAdd, NULL, 0,
306 "add entry to vice partition table");
307 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_REQUIRED, "partition name");
308 cmd_AddParm(ts, "-dev", CMD_SINGLE, CMD_REQUIRED, "device name");
310 ts = cmd_CreateSyntax("vptdel", DoVptDel, NULL, 0,
311 "remove entry from vice partition table");
312 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_REQUIRED, "partition name");
318 struct cmd_syndesc *ts;
320 ts = cmd_CreateSyntax("dirget", DoDirGet, NULL, 0,
321 "display the AFS server installation directory");
323 ts = cmd_CreateSyntax("dirset", DoDirSet, NULL, 0,
324 "set the AFS server installation directory");
325 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_REQUIRED, "directory path");
331 struct cmd_syndesc *ts;
333 ts = cmd_CreateSyntax("boscfg", DoBosCfg, NULL, 0,
334 "configure the AFS BOS control service");
335 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "service binary path");
337 ts = cmd_CreateSyntax("bosdel", DoBosDel, NULL, 0,
338 "delete (unconfigure) the AFS BOS control service");
342 SetupVersionCmd(void)
344 struct cmd_syndesc *ts;
346 ts = cmd_CreateSyntax("version", DoVersionGet, NULL, 0,
347 "display AFS version information");
353 int main(int argc, char *argv[])
359 /* initialize command syntax */
360 initialize_CMD_error_table();
367 /* execute command */
368 code = cmd_Dispatch(argc, argv);