1 /* Copyright (C) 1998 Transarc Corporation - All rights reserved.
5 /* Manual utility for testing registry access functions. Also serves
6 * as a pre Configuration Manager registry configuration utility.
19 #include <afs/param.h>
21 #include <afs/com_err.h>
23 #include <afs/dirpath.h>
25 #include <WINNT/afsreg.h>
26 #include <WINNT/afssw.h>
27 #include <WINNT/vptab.h>
33 static int DoVptList(struct cmd_syndesc *as, char *arock)
35 struct vpt_iter vpiter;
38 if (!vpt_Start(&vpiter)) {
39 while (!vpt_NextEntry(&vpiter, &vpentry)) {
40 printf("Partition: %s Device: %s\n",
41 vpentry.vp_name, vpentry.vp_dev);
44 (void)vpt_Finish(&vpiter);
49 static int DoVptAdd(struct cmd_syndesc *as, char *arock)
54 vpName = as->parms[0].items->data;
55 vpDev = as->parms[1].items->data;
57 if (!vpt_PartitionNameValid(vpName)) {
58 com_err(whoami, 0, "Partition name invalid");
62 if (!vpt_DeviceNameValid(vpDev)) {
63 com_err(whoami, 0, "Device name invalid");
67 strcpy(vpentry.vp_name, vpName);
68 strcpy(vpentry.vp_dev, vpDev);
70 if (vpt_AddEntry(&vpentry)) {
71 com_err(whoami, 0, "Unable to create vice partition table entry");
77 static int DoVptDel(struct cmd_syndesc *as, char *arock)
81 vpName = as->parms[0].items->data;
83 if (!vpt_PartitionNameValid(vpName)) {
84 com_err(whoami, 0, "Partition name invalid");
88 if (vpt_RemoveEntry(vpName) && errno != ENOENT) {
89 com_err(whoami, 0, "Unable to remove vice partition table entry");
96 static int DoDirGet(struct cmd_syndesc *as, char *arock)
100 if (afssw_GetServerInstallDir(&buf)) {
102 "Failed reading AFS install dir entry (or does not exist)");
106 printf("AFS server installation directory: %s\n", buf);
113 static int DoDirSet(struct cmd_syndesc *as, char *arock)
119 afsPath = as->parms[0].items->data;
121 /* open AFS sw version key; create if does not exist */
122 status = RegOpenKeyAlt(AFSREG_NULL_KEY, AFSREG_SVR_SW_VERSION_KEY,
123 KEY_WRITE, 1 /* create */, &key, NULL);
125 if (status == ERROR_SUCCESS) {
126 /* write AFS directory value */
127 status = RegSetValueEx(key, AFSREG_SVR_SW_VERSION_DIR_VALUE,
128 0, REG_SZ, afsPath, strlen(afsPath) + 1);
134 com_err(whoami, 0, "Unable to set AFS installation directory entry");
137 return (status ? 1 : 0);
141 static int DoBosCfg(struct cmd_syndesc *as, char *arock)
143 char bosSvcPath[AFSDIR_PATH_MAX];
144 SC_HANDLE scmHandle, svcHandle;
146 /* determine if using specified or default service binary path */
147 if (as->parms[0].items) {
148 /* BOS control service binary path specified */
149 sprintf(bosSvcPath, "\"%s\"", as->parms[0].items->data);
151 /* no BOS control service binary path specified; check for default */
154 if (afssw_GetServerInstallDir(&dirBuf)) {
156 "binary path not specified and AFS server installation directory not set");
159 sprintf(bosSvcPath, "\"%s%s/%s\"",
161 AFSDIR_CANONICAL_SERVER_BIN_DIRPATH,
162 AFSREG_SVR_SVC_IMAGENAME_DATA);
165 /* create BOS control service */
166 scmHandle = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
168 if (scmHandle == NULL) {
169 DWORD status = GetLastError();
172 if (status == ERROR_ACCESS_DENIED) {
173 reason = "(insufficient privilege)";
175 com_err(whoami, 0, "unable to connect to the SCM %s", reason);
179 svcHandle = CreateService(scmHandle,
181 AFSREG_SVR_SVC_DISPLAYNAME_DATA,
182 STANDARD_RIGHTS_REQUIRED,
183 SERVICE_WIN32_OWN_PROCESS,
185 SERVICE_ERROR_NORMAL,
187 NULL, /* load order group */
189 NULL, /* dependencies */
190 NULL, /* service start name */
191 NULL); /* password */
193 if (svcHandle == NULL) {
194 DWORD status = GetLastError();
197 if (status == ERROR_SERVICE_EXISTS || status == ERROR_DUP_NAME) {
198 reason = "(service or display name already exists)";
200 com_err(whoami, 0, "unable to create service %s", reason);
201 CloseServiceHandle(scmHandle);
205 CloseServiceHandle(svcHandle);
206 CloseServiceHandle(scmHandle);
211 static int DoBosDel(struct cmd_syndesc *as, char *arock)
214 SC_HANDLE scmHandle, svcHandle;
216 scmHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
218 if (scmHandle == NULL) {
219 DWORD status = GetLastError();
222 if (status == ERROR_ACCESS_DENIED) {
223 reason = "(insufficient privilege)";
225 com_err(whoami, 0, "unable to connect to the SCM %s", reason);
229 svcHandle = OpenService(scmHandle,
230 AFSREG_SVR_SVC_NAME, STANDARD_RIGHTS_REQUIRED);
232 if (svcHandle == NULL) {
233 DWORD status = GetLastError();
235 if (status != ERROR_SERVICE_DOES_NOT_EXIST) {
236 com_err(whoami, 0, "unable to open service");
239 CloseServiceHandle(scmHandle);
243 if (!DeleteService(svcHandle)) {
244 DWORD status = GetLastError();
246 if (status != ERROR_SERVICE_MARKED_FOR_DELETE) {
247 com_err(whoami, 0, "service delete failed");
251 CloseServiceHandle(svcHandle);
252 CloseServiceHandle(scmHandle);
256 static int DoVersionGet(struct cmd_syndesc *as, char *arock)
258 unsigned major, minor, patch;
262 if (!afssw_GetClientVersion(&major, &minor, &patch)) {
263 printf("Client: major = %u, minor = %u, patch = %u\n",
264 major, minor, patch);
266 printf("Client version information not available.\n");
269 if (!afssw_GetServerVersion(&major, &minor, &patch)) {
270 printf("Server: major = %u, minor = %u, patch = %u\n",
271 major, minor, patch);
273 printf("Server version information not available.\n");
282 struct cmd_syndesc *ts;
284 ts = cmd_CreateSyntax("vptlist", DoVptList, 0,
285 "list vice partition table");
287 ts = cmd_CreateSyntax("vptadd", DoVptAdd, 0,
288 "add entry to vice partition table");
289 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_REQUIRED, "partition name");
290 cmd_AddParm(ts, "-dev", CMD_SINGLE, CMD_REQUIRED, "device name");
292 ts = cmd_CreateSyntax("vptdel", DoVptDel, 0,
293 "remove entry from vice partition table");
294 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_REQUIRED, "partition name");
300 struct cmd_syndesc *ts;
302 ts = cmd_CreateSyntax("dirget", DoDirGet, 0,
303 "display the AFS server installation directory");
305 ts = cmd_CreateSyntax("dirset", DoDirSet, 0,
306 "set the AFS server installation directory");
307 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_REQUIRED, "directory path");
313 struct cmd_syndesc *ts;
315 ts = cmd_CreateSyntax("boscfg", DoBosCfg, 0,
316 "configure the AFS BOS control service");
317 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "service binary path");
319 ts = cmd_CreateSyntax("bosdel", DoBosDel, 0,
320 "delete (unconfigure) the AFS BOS control service");
324 SetupVersionCmd(void)
326 struct cmd_syndesc *ts;
328 ts = cmd_CreateSyntax("version", DoVersionGet, 0,
329 "display AFS version information");
335 int main(int argc, char *argv[])
341 /* initialize command syntax */
342 initialize_cmd_error_table();
349 /* execute command */
350 code = cmd_Dispatch(argc, argv);