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>
30 #include <rx/rxstat.h>
32 #include <afs/afs_Admin.h>
33 #include <afs/afs_utilAdmin.h>
34 #include <afs/afs_clientAdmin.h>
36 #include <afs/cellconfig.h>
53 pthread_mutex_t des_init_mutex = PTHREAD_MUTEX_INITIALIZER;
54 pthread_mutex_t des_random_mutex = PTHREAD_MUTEX_INITIALIZER;
55 pthread_mutex_t rxkad_random_mutex = PTHREAD_MUTEX_INITIALIZER;
56 #endif /* AFS_DARWIN_ENV */
59 * Before processing any command, process the common arguments and
60 * get an appropriate cell handle
64 MyBeforeProc(struct cmd_syndesc *as, void *arock)
68 char auth_cell[MAXCELLCHARS];
69 char exec_cell[MAXCELLCHARS];
72 * Check what kind of authentication is necessary based upon
73 * the arguments passed
77 * Check for noauth first
80 if (as->parms[NOAUTH_PARAM].items) {
82 if (as->parms[USER_PARAM].items) {
83 ERR_EXT("you can't specify both -noauth and -authuser");
85 if (as->parms[PASSWORD_PARAM].items) {
86 ERR_EXT("you can't specify both -noauth and -authpassword");
88 if (as->parms[AUTHCELL_PARAM].items) {
89 ERR_EXT("you can't specify both -noauth and -authcell");
94 * Check for user name password and auth cell
95 * It's ok to specify user name and password, but not auth cell
96 * in that case, we assume that the auth cell is the local cell.
99 if (as->parms[USER_PARAM].items) {
100 if (!as->parms[PASSWORD_PARAM].items) {
102 ("you must specify -authpassword if you specify -authuser");
104 if (as->parms[AUTHCELL_PARAM].items) {
105 strcpy(auth_cell, as->parms[AUTHCELL_PARAM].items->data);
107 if (!afsclient_LocalCellGet(auth_cell, &st)) {
108 ERR_ST_EXT("can't get local cell name", st);
114 * Get the execution cell. If this parameter wasn't passed, we
115 * assume the command should execute in the local cell.
118 if (as->parms[EXECCELL_PARAM].items) {
119 strcpy(exec_cell, as->parms[EXECCELL_PARAM].items->data);
121 if (!afsclient_LocalCellGet(exec_cell, &st)) {
122 ERR_ST_EXT("can't get local cell name", st);
127 * Get a token handle and a cell handle for this invocation
131 if (!afsclient_TokenGetNew
132 (auth_cell, (const char *)0, (const char *)0, &tokenHandle,
134 ERR_ST_EXT("can't get noauth tokens", st);
137 if (!afsclient_TokenGetNew
138 (auth_cell, (const char *)as->parms[USER_PARAM].items->data,
139 (const char *)as->parms[PASSWORD_PARAM].items->data,
140 &tokenHandle, &st)) {
141 ERR_ST_EXT("can't get tokens", st);
145 if (!afsclient_CellOpen(exec_cell, tokenHandle, &cellHandle, &st)) {
146 ERR_ST_EXT("can't open cell", st);
153 MyAfterProc(struct cmd_syndesc *as,void *arock)
156 afsclient_CellClose(cellHandle, (afs_status_p) 0);
157 afsclient_TokenClose(tokenHandle, (afs_status_p) 0);
164 SetupCommonCmdArgs(struct cmd_syndesc *as)
166 cmd_Seek(as, USER_PARAM);
167 cmd_AddParm(as, "-authuser", CMD_SINGLE, CMD_OPTIONAL,
168 "user name to use for authentication");
169 cmd_AddParm(as, "-authpassword", CMD_SINGLE, CMD_OPTIONAL,
170 "password to use for authentication");
171 cmd_AddParm(as, "-authcell", CMD_SINGLE, CMD_OPTIONAL,
172 "cell to use for authentication");
173 cmd_AddParm(as, "-execcell", CMD_SINGLE, CMD_OPTIONAL,
174 "cell where command will execute");
175 cmd_AddParm(as, "-noauth", CMD_FLAG, CMD_OPTIONAL,
176 "run this command unauthenticated");
180 main(int argc, char *argv[])
185 /* perform client initialization */
187 if (!afsclient_Init(&st)) {
188 ERR_ST_EXT("can't init afs client", st);
191 /* initialize command syntax and globals */
193 cmd_SetBeforeProc(MyBeforeProc, NULL);
194 cmd_SetAfterProc(MyAfterProc, NULL);
196 SetupClientAdminCmd();
202 /* execute command */
204 code = cmd_Dispatch(argc, argv);