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, char *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, char *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, char *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, char *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, char *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, char *arock)
148 char bosSvcPath[AFSDIR_PATH_MAX];
149 SC_HANDLE scmHandle, svcHandle;
151 /* determine if using specified or default service binary path */
152 if (as->parms[0].items) {
153 /* BOS control service binary path specified */
154 sprintf(bosSvcPath, "\"%s\"", as->parms[0].items->data);
156 /* no BOS control service binary path specified; check for default */
159 if (afssw_GetServerInstallDir(&dirBuf)) {
160 afs_com_err(whoami, 0,
161 "binary path not specified and AFS server installation directory not set");
164 sprintf(bosSvcPath, "\"%s%s/%s\"",
166 AFSDIR_CANONICAL_SERVER_BIN_DIRPATH,
167 AFSREG_SVR_SVC_IMAGENAME_DATA);
170 /* create BOS control service */
171 scmHandle = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
173 if (scmHandle == NULL) {
174 DWORD status = GetLastError();
177 if (status == ERROR_ACCESS_DENIED) {
178 reason = "(insufficient privilege)";
180 afs_com_err(whoami, 0, "unable to connect to the SCM %s", reason);
184 svcHandle = CreateService(scmHandle,
186 AFSREG_SVR_SVC_DISPLAYNAME_DATA,
187 STANDARD_RIGHTS_REQUIRED,
188 SERVICE_WIN32_OWN_PROCESS,
190 SERVICE_ERROR_NORMAL,
192 NULL, /* load order group */
194 NULL, /* dependencies */
195 NULL, /* service start name */
196 NULL); /* password */
198 if (svcHandle == NULL) {
199 DWORD status = GetLastError();
202 if (status == ERROR_SERVICE_EXISTS || status == ERROR_DUP_NAME) {
203 reason = "(service or display name already exists)";
205 afs_com_err(whoami, 0, "unable to create service %s", reason);
206 CloseServiceHandle(scmHandle);
210 CloseServiceHandle(svcHandle);
211 CloseServiceHandle(scmHandle);
216 static int DoBosDel(struct cmd_syndesc *as, char *arock)
219 SC_HANDLE scmHandle, svcHandle;
221 scmHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
223 if (scmHandle == NULL) {
224 DWORD status = GetLastError();
227 if (status == ERROR_ACCESS_DENIED) {
228 reason = "(insufficient privilege)";
230 afs_com_err(whoami, 0, "unable to connect to the SCM %s", reason);
234 svcHandle = OpenService(scmHandle,
235 AFSREG_SVR_SVC_NAME, STANDARD_RIGHTS_REQUIRED);
237 if (svcHandle == NULL) {
238 DWORD status = GetLastError();
240 if (status != ERROR_SERVICE_DOES_NOT_EXIST) {
241 afs_com_err(whoami, 0, "unable to open service");
244 CloseServiceHandle(scmHandle);
248 if (!DeleteService(svcHandle)) {
249 DWORD status = GetLastError();
251 if (status != ERROR_SERVICE_MARKED_FOR_DELETE) {
252 afs_com_err(whoami, 0, "service delete failed");
256 CloseServiceHandle(svcHandle);
257 CloseServiceHandle(scmHandle);
261 static int DoVersionGet(struct cmd_syndesc *as, char *arock)
263 unsigned major, minor, patch;
267 if (!afssw_GetClientVersion(&major, &minor, &patch)) {
268 printf("Client: major = %u, minor = %u, patch = %u\n",
269 major, minor, patch);
271 printf("Client version information not available.\n");
274 if (!afssw_GetServerVersion(&major, &minor, &patch)) {
275 printf("Server: major = %u, minor = %u, patch = %u\n",
276 major, minor, patch);
278 printf("Server version information not available.\n");
287 struct cmd_syndesc *ts;
289 ts = cmd_CreateSyntax("vptlist", DoVptList, 0,
290 "list vice partition table");
292 ts = cmd_CreateSyntax("vptadd", DoVptAdd, 0,
293 "add entry to vice partition table");
294 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_REQUIRED, "partition name");
295 cmd_AddParm(ts, "-dev", CMD_SINGLE, CMD_REQUIRED, "device name");
297 ts = cmd_CreateSyntax("vptdel", DoVptDel, 0,
298 "remove entry from vice partition table");
299 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_REQUIRED, "partition name");
305 struct cmd_syndesc *ts;
307 ts = cmd_CreateSyntax("dirget", DoDirGet, 0,
308 "display the AFS server installation directory");
310 ts = cmd_CreateSyntax("dirset", DoDirSet, 0,
311 "set the AFS server installation directory");
312 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_REQUIRED, "directory path");
318 struct cmd_syndesc *ts;
320 ts = cmd_CreateSyntax("boscfg", DoBosCfg, 0,
321 "configure the AFS BOS control service");
322 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "service binary path");
324 ts = cmd_CreateSyntax("bosdel", DoBosDel, 0,
325 "delete (unconfigure) the AFS BOS control service");
329 SetupVersionCmd(void)
331 struct cmd_syndesc *ts;
333 ts = cmd_CreateSyntax("version", DoVersionGet, 0,
334 "display AFS version information");
340 int main(int argc, char *argv[])
346 /* initialize command syntax */
347 initialize_CMD_error_table();
354 /* execute command */
355 code = cmd_Dispatch(argc, argv);