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>
47 pthread_mutex_t des_init_mutex = PTHREAD_MUTEX_INITIALIZER;
48 pthread_mutex_t des_random_mutex = PTHREAD_MUTEX_INITIALIZER;
49 pthread_mutex_t rxkad_random_mutex = PTHREAD_MUTEX_INITIALIZER;
50 #endif /* AFS_DARWIN_ENV */
53 * Before processing any command, process the common arguments and
54 * get an appropriate cell handle
58 MyBeforeProc(struct cmd_syndesc *as, void *arock)
62 char auth_cell[MAXCELLCHARS];
63 char exec_cell[MAXCELLCHARS];
66 * Check what kind of authentication is necessary based upon
67 * the arguments passed
71 * Check for noauth first
74 if (as->parms[NOAUTH_PARAM].items) {
76 if (as->parms[USER_PARAM].items) {
77 ERR_EXT("you can't specify both -noauth and -authuser");
79 if (as->parms[PASSWORD_PARAM].items) {
80 ERR_EXT("you can't specify both -noauth and -authpassword");
82 if (as->parms[AUTHCELL_PARAM].items) {
83 ERR_EXT("you can't specify both -noauth and -authcell");
88 * Check for user name password and auth cell
89 * It's ok to specify user name and password, but not auth cell
90 * in that case, we assume that the auth cell is the local cell.
93 if (as->parms[USER_PARAM].items) {
94 if (!as->parms[PASSWORD_PARAM].items) {
96 ("you must specify -authpassword if you specify -authuser");
98 if (as->parms[AUTHCELL_PARAM].items) {
99 strcpy(auth_cell, as->parms[AUTHCELL_PARAM].items->data);
101 if (!afsclient_LocalCellGet(auth_cell, &st)) {
102 ERR_ST_EXT("can't get local cell name", st);
108 * Get the execution cell. If this parameter wasn't passed, we
109 * assume the command should execute in the local cell.
112 if (as->parms[EXECCELL_PARAM].items) {
113 strcpy(exec_cell, as->parms[EXECCELL_PARAM].items->data);
115 if (!afsclient_LocalCellGet(exec_cell, &st)) {
116 ERR_ST_EXT("can't get local cell name", st);
121 * Get a token handle and a cell handle for this invocation
125 if (!afsclient_TokenGetNew
126 (auth_cell, (const char *)0, (const char *)0, &tokenHandle,
128 ERR_ST_EXT("can't get noauth tokens", st);
131 if (!afsclient_TokenGetNew
132 (auth_cell, (const char *)as->parms[USER_PARAM].items->data,
133 (const char *)as->parms[PASSWORD_PARAM].items->data,
134 &tokenHandle, &st)) {
135 ERR_ST_EXT("can't get tokens", st);
139 if (!afsclient_CellOpen(exec_cell, tokenHandle, &cellHandle, &st)) {
140 ERR_ST_EXT("can't open cell", st);
147 MyAfterProc(struct cmd_syndesc *as,void *arock)
150 afsclient_CellClose(cellHandle, (afs_status_p) 0);
151 afsclient_TokenClose(tokenHandle, (afs_status_p) 0);
158 SetupCommonCmdArgs(struct cmd_syndesc *as)
160 cmd_Seek(as, USER_PARAM);
161 cmd_AddParm(as, "-authuser", CMD_SINGLE, CMD_OPTIONAL,
162 "user name to use for authentication");
163 cmd_AddParm(as, "-authpassword", CMD_SINGLE, CMD_OPTIONAL,
164 "password to use for authentication");
165 cmd_AddParm(as, "-authcell", CMD_SINGLE, CMD_OPTIONAL,
166 "cell to use for authentication");
167 cmd_AddParm(as, "-execcell", CMD_SINGLE, CMD_OPTIONAL,
168 "cell where command will execute");
169 cmd_AddParm(as, "-noauth", CMD_FLAG, CMD_OPTIONAL,
170 "run this command unauthenticated");
174 main(int argc, char *argv[])
179 /* perform client initialization */
181 if (!afsclient_Init(&st)) {
182 ERR_ST_EXT("can't init afs client", st);
185 /* initialize command syntax and globals */
187 cmd_SetBeforeProc(MyBeforeProc, NULL);
188 cmd_SetAfterProc(MyAfterProc, NULL);
190 SetupClientAdminCmd();
196 /* execute command */
198 code = cmd_Dispatch(argc, argv);