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>
29 #include <rx/rxstat.h>
31 #include <afs/afs_Admin.h>
32 #include <afs/afs_utilAdmin.h>
33 #include <afs/afs_clientAdmin.h>
35 #include <afs/cellconfig.h>
52 pthread_mutex_t des_init_mutex = PTHREAD_MUTEX_INITIALIZER;
53 pthread_mutex_t des_random_mutex = PTHREAD_MUTEX_INITIALIZER;
54 pthread_mutex_t rxkad_random_mutex = PTHREAD_MUTEX_INITIALIZER;
55 #endif /* AFS_DARWIN_ENV */
58 * Before processing any command, process the common arguments and
59 * get an appropriate cell handle
63 MyBeforeProc(struct cmd_syndesc *as, void *arock)
67 char auth_cell[MAXCELLCHARS];
68 char exec_cell[MAXCELLCHARS];
71 * Check what kind of authentication is necessary based upon
72 * the arguments passed
76 * Check for noauth first
79 if (as->parms[NOAUTH_PARAM].items) {
81 if (as->parms[USER_PARAM].items) {
82 ERR_EXT("you can't specify both -noauth and -authuser");
84 if (as->parms[PASSWORD_PARAM].items) {
85 ERR_EXT("you can't specify both -noauth and -authpassword");
87 if (as->parms[AUTHCELL_PARAM].items) {
88 ERR_EXT("you can't specify both -noauth and -authcell");
93 * Check for user name password and auth cell
94 * It's ok to specify user name and password, but not auth cell
95 * in that case, we assume that the auth cell is the local cell.
98 if (as->parms[USER_PARAM].items) {
99 if (!as->parms[PASSWORD_PARAM].items) {
101 ("you must specify -authpassword if you specify -authuser");
103 if (as->parms[AUTHCELL_PARAM].items) {
104 strcpy(auth_cell, as->parms[AUTHCELL_PARAM].items->data);
106 if (!afsclient_LocalCellGet(auth_cell, &st)) {
107 ERR_ST_EXT("can't get local cell name", st);
113 * Get the execution cell. If this parameter wasn't passed, we
114 * assume the command should execute in the local cell.
117 if (as->parms[EXECCELL_PARAM].items) {
118 strcpy(exec_cell, as->parms[EXECCELL_PARAM].items->data);
120 if (!afsclient_LocalCellGet(exec_cell, &st)) {
121 ERR_ST_EXT("can't get local cell name", st);
126 * Get a token handle and a cell handle for this invocation
130 if (!afsclient_TokenGetNew
131 (auth_cell, (const char *)0, (const char *)0, &tokenHandle,
133 ERR_ST_EXT("can't get noauth tokens", st);
136 if (!afsclient_TokenGetNew
137 (auth_cell, (const char *)as->parms[USER_PARAM].items->data,
138 (const char *)as->parms[PASSWORD_PARAM].items->data,
139 &tokenHandle, &st)) {
140 ERR_ST_EXT("can't get tokens", st);
144 if (!afsclient_CellOpen(exec_cell, tokenHandle, &cellHandle, &st)) {
145 ERR_ST_EXT("can't open cell", st);
152 MyAfterProc(struct cmd_syndesc *as,void *arock)
155 afsclient_CellClose(cellHandle, (afs_status_p) 0);
156 afsclient_TokenClose(tokenHandle, (afs_status_p) 0);
163 SetupCommonCmdArgs(struct cmd_syndesc *as)
165 cmd_Seek(as, USER_PARAM);
166 cmd_AddParm(as, "-authuser", CMD_SINGLE, CMD_OPTIONAL,
167 "user name to use for authentication");
168 cmd_AddParm(as, "-authpassword", CMD_SINGLE, CMD_OPTIONAL,
169 "password to use for authentication");
170 cmd_AddParm(as, "-authcell", CMD_SINGLE, CMD_OPTIONAL,
171 "cell to use for authentication");
172 cmd_AddParm(as, "-execcell", CMD_SINGLE, CMD_OPTIONAL,
173 "cell where command will execute");
174 cmd_AddParm(as, "-noauth", CMD_FLAG, CMD_OPTIONAL,
175 "run this command unauthenticated");
179 main(int argc, char *argv[])
184 /* perform client initialization */
186 if (!afsclient_Init(&st)) {
187 ERR_ST_EXT("can't init afs client", st);
190 /* initialize command syntax and globals */
192 cmd_SetBeforeProc(MyBeforeProc, NULL);
193 cmd_SetAfterProc(MyAfterProc, NULL);
195 SetupClientAdminCmd();
201 /* execute command */
203 code = cmd_Dispatch(argc, argv);