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
9 * Portions Copyright (c) 2003 Apple Computer, Inc.
12 /* Test driver for admin functions. */
14 #include <afsconfig.h>
15 #include <afs/param.h>
23 #include <rx/rxstat.h>
25 #include <afs/afs_Admin.h>
26 #include <afs/afs_utilAdmin.h>
27 #include <afs/afs_clientAdmin.h>
29 #include <afs/cellconfig.h>
46 int existing_tokens = 0;
48 pthread_mutex_t des_init_mutex = PTHREAD_MUTEX_INITIALIZER;
49 pthread_mutex_t des_random_mutex = PTHREAD_MUTEX_INITIALIZER;
50 pthread_mutex_t rxkad_random_mutex = PTHREAD_MUTEX_INITIALIZER;
51 #endif /* AFS_DARWIN_ENV */
54 * Before processing any command, process the common arguments and
55 * get an appropriate cell handle
59 MyBeforeProc(struct cmd_syndesc *as, void *arock)
63 char auth_cell[MAXCELLCHARS];
64 char exec_cell[MAXCELLCHARS];
67 * Check what kind of authentication is necessary based upon
68 * the arguments passed
72 * Check for noauth first
75 if (as->parms[NOAUTH_PARAM].items) {
77 if (as->parms[USER_PARAM].items) {
78 ERR_EXT("you can't specify both -noauth and -authuser");
80 if (as->parms[PASSWORD_PARAM].items) {
81 ERR_EXT("you can't specify both -noauth and -authpassword");
83 if (as->parms[AUTHCELL_PARAM].items) {
84 ERR_EXT("you can't specify both -noauth and -authcell");
86 if (as->parms[USEEXISTTOKENS_PARAM].items) {
87 ERR_EXT("you can't specify both -noauth and -usetokens");
95 if (as->parms[USEEXISTTOKENS_PARAM].items) {
97 if (as->parms[USER_PARAM].items) {
98 ERR_EXT("you can't specify both -usetokens and -authuser");
100 if (as->parms[PASSWORD_PARAM].items) {
101 ERR_EXT("you can't specify both -usetokens and -authpassword");
106 * Check for user name password and auth cell
107 * It's ok to specify user name and password, but not auth cell
108 * in that case, we assume that the auth cell is the local cell.
111 if (as->parms[USER_PARAM].items) {
112 if (!as->parms[PASSWORD_PARAM].items) {
114 ("you must specify -authpassword if you specify -authuser");
116 if (as->parms[AUTHCELL_PARAM].items) {
117 strcpy(auth_cell, as->parms[AUTHCELL_PARAM].items->data);
119 if (!afsclient_LocalCellGet(auth_cell, &st)) {
120 ERR_ST_EXT("can't get local cell name", st);
126 * Get the execution cell. If this parameter wasn't passed, we
127 * assume the command should execute in the local cell.
130 if (as->parms[EXECCELL_PARAM].items) {
131 strcpy(exec_cell, as->parms[EXECCELL_PARAM].items->data);
133 if (!afsclient_LocalCellGet(exec_cell, &st)) {
134 ERR_ST_EXT("can't get local cell name", st);
139 * Get a token handle and a cell handle for this invocation
143 if (!afsclient_TokenGetNew
144 (auth_cell, (const char *)0, (const char *)0, &tokenHandle,
146 ERR_ST_EXT("can't get noauth tokens", st);
148 } else if (existing_tokens) {
149 if (as->parms[AUTHCELL_PARAM].items) {
150 /* Look for existing tokens for this cell */
151 strcpy(auth_cell, as->parms[AUTHCELL_PARAM].items->data);
153 if (!afsclient_LocalCellGet(auth_cell, &st)) {
154 ERR_ST_EXT("can't get local cell name", st);
157 if (!afsclient_TokenGetExisting((const char*)auth_cell, &tokenHandle, &st)) {
158 ERR_ST_EXT("can't find existing tokens", st);
161 if (!afsclient_TokenGetNew
162 (auth_cell, (const char *)as->parms[USER_PARAM].items->data,
163 (const char *)as->parms[PASSWORD_PARAM].items->data,
164 &tokenHandle, &st)) {
165 ERR_ST_EXT("can't get tokens", st);
169 if (!afsclient_CellOpen(exec_cell, tokenHandle, &cellHandle, &st)) {
170 ERR_ST_EXT("can't open cell", st);
177 MyAfterProc(struct cmd_syndesc *as,void *arock)
180 afsclient_CellClose(cellHandle, (afs_status_p) 0);
181 afsclient_TokenClose(tokenHandle, (afs_status_p) 0);
188 SetupCommonCmdArgs(struct cmd_syndesc *as)
190 cmd_Seek(as, USER_PARAM);
191 cmd_AddParm(as, "-authuser", CMD_SINGLE, CMD_OPTIONAL,
192 "user name to use for authentication");
193 cmd_AddParm(as, "-authpassword", CMD_SINGLE, CMD_OPTIONAL,
194 "password to use for authentication");
195 cmd_AddParm(as, "-authcell", CMD_SINGLE, CMD_OPTIONAL,
196 "cell to use for authentication");
197 cmd_AddParm(as, "-execcell", CMD_SINGLE, CMD_OPTIONAL,
198 "cell where command will execute");
199 cmd_AddParm(as, "-noauth", CMD_FLAG, CMD_OPTIONAL,
200 "run this command unauthenticated");
201 cmd_AddParm(as, "-usetokens", CMD_FLAG, CMD_OPTIONAL,
202 "use already existing tokens");
206 main(int argc, char *argv[])
211 /* perform client initialization */
213 if (!afsclient_Init(&st)) {
214 ERR_ST_EXT("can't init afs client", st);
217 /* initialize command syntax and globals */
219 cmd_SetBeforeProc(MyBeforeProc, NULL);
220 cmd_SetAfterProc(MyAfterProc, NULL);
222 SetupClientAdminCmd();
228 /* execute command */
230 code = cmd_Dispatch(argc, argv);