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 /* Test driver for admin functions. */
12 #include <afsconfig.h>
13 #include <afs/param.h>
27 #include <afs/afs_Admin.h>
28 #include <afs/afs_utilAdmin.h>
29 #include <afs/afs_clientAdmin.h>
31 #include <afs/cellconfig.h>
49 * Before processing any command, process the common arguments and
50 * get an appropriate cell handle
55 struct cmd_syndesc *as,
61 char auth_cell[MAXCELLCHARS];
62 char exec_cell[MAXCELLCHARS];
65 * Check what kind of authentication is necessary based upon
66 * the arguments passed
70 * Check for noauth first
73 if (as->parms[NOAUTH_PARAM].items) {
75 if (as->parms[USER_PARAM].items) {
76 ERR_EXT("you can't specify both -noauth and -authuser");
78 if (as->parms[PASSWORD_PARAM].items) {
79 ERR_EXT("you can't specify both -noauth and -authpassword");
81 if (as->parms[AUTHCELL_PARAM].items) {
82 ERR_EXT("you can't specify both -noauth and -authcell");
87 * Check for user name password and auth cell
88 * It's ok to specify user name and password, but not auth cell
89 * in that case, we assume that the auth cell is the local cell.
92 if (as->parms[USER_PARAM].items) {
93 if (!as->parms[PASSWORD_PARAM].items) {
94 ERR_EXT("you must specify -authpassword if you specify -authuser");
96 if (as->parms[AUTHCELL_PARAM].items) {
97 strcpy(auth_cell, as->parms[AUTHCELL_PARAM].items->data);
99 if (!afsclient_LocalCellGet(auth_cell, &st)) {
100 ERR_ST_EXT("can't get local cell name", st);
106 * Get the execution cell. If this parameter wasn't passed, we
107 * assume the command should execute in the local cell.
110 if (as->parms[EXECCELL_PARAM].items) {
111 strcpy(exec_cell, as->parms[EXECCELL_PARAM].items->data);
113 if (!afsclient_LocalCellGet(exec_cell, &st)) {
114 ERR_ST_EXT("can't get local cell name", st);
119 * Get a token handle and a cell handle for this invocation
123 if (!afsclient_TokenGetNew(auth_cell,
128 ERR_ST_EXT("can't get noauth tokens", st);
131 if (!afsclient_TokenGetNew(auth_cell,
132 (const char *) as->parms[USER_PARAM].items->data,
133 (const char *) as->parms[PASSWORD_PARAM].items->data,
136 ERR_ST_EXT("can't get tokens", st);
140 if (!afsclient_CellOpen(exec_cell, tokenHandle, &cellHandle, &st)) {
141 ERR_ST_EXT("can't open cell", st);
147 static int MyAfterProc(
148 struct cmd_syndesc *as)
151 afsclient_CellClose(cellHandle, (afs_status_p) 0);
152 afsclient_TokenClose(tokenHandle, (afs_status_p) 0);
159 SetupCommonCmdArgs(struct cmd_syndesc *as)
161 cmd_Seek(as, USER_PARAM);
162 cmd_AddParm(as, "-authuser", CMD_SINGLE, CMD_OPTIONAL,
163 "user name to use for authentication");
164 cmd_AddParm(as, "-authpassword", CMD_SINGLE, CMD_OPTIONAL,
165 "password to use for authentication");
166 cmd_AddParm(as, "-authcell", CMD_SINGLE, CMD_OPTIONAL,
167 "cell to use for authentication");
168 cmd_AddParm(as, "-execcell", CMD_SINGLE, CMD_OPTIONAL,
169 "cell where command will execute");
170 cmd_AddParm(as, "-noauth", CMD_FLAG, CMD_OPTIONAL,
171 "run this command unauthenticated");
174 int main(int argc, char *argv[])
178 char *whoami = argv[0];
180 /* perform client initialization */
182 if (!afsclient_Init(&st)) {
183 ERR_ST_EXT("can't init afs client", st);
186 /* initialize command syntax and globals */
188 cmd_SetBeforeProc(MyBeforeProc, (char *) 0);
189 cmd_SetAfterProc(MyAfterProc, (char *) 0);
191 SetupClientAdminCmd();
197 /* execute command */
199 code = cmd_Dispatch(argc, argv);