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;
49 * Before processing any command, process the common arguments and
50 * get an appropriate cell handle
54 MyBeforeProc(struct cmd_syndesc
*as
, void *arock
)
58 char auth_cell
[MAXCELLCHARS
];
59 char exec_cell
[MAXCELLCHARS
];
62 * Check what kind of authentication is necessary based upon
63 * the arguments passed
67 * Check for noauth first
70 if (as
->parms
[NOAUTH_PARAM
].items
) {
72 if (as
->parms
[USER_PARAM
].items
) {
73 ERR_EXT("you can't specify both -noauth and -authuser");
75 if (as
->parms
[PASSWORD_PARAM
].items
) {
76 ERR_EXT("you can't specify both -noauth and -authpassword");
78 if (as
->parms
[AUTHCELL_PARAM
].items
) {
79 ERR_EXT("you can't specify both -noauth and -authcell");
81 if (as
->parms
[USEEXISTTOKENS_PARAM
].items
) {
82 ERR_EXT("you can't specify both -noauth and -usetokens");
90 if (as
->parms
[USEEXISTTOKENS_PARAM
].items
) {
92 if (as
->parms
[USER_PARAM
].items
) {
93 ERR_EXT("you can't specify both -usetokens and -authuser");
95 if (as
->parms
[PASSWORD_PARAM
].items
) {
96 ERR_EXT("you can't specify both -usetokens and -authpassword");
101 * Check for user name password and auth cell
102 * It's ok to specify user name and password, but not auth cell
103 * in that case, we assume that the auth cell is the local cell.
106 if (as
->parms
[USER_PARAM
].items
) {
107 if (!as
->parms
[PASSWORD_PARAM
].items
) {
109 ("you must specify -authpassword if you specify -authuser");
111 if (as
->parms
[AUTHCELL_PARAM
].items
) {
112 strcpy(auth_cell
, as
->parms
[AUTHCELL_PARAM
].items
->data
);
114 if (!afsclient_LocalCellGet(auth_cell
, &st
)) {
115 ERR_ST_EXT("can't get local cell name", st
);
121 * Get the execution cell. If this parameter wasn't passed, we
122 * assume the command should execute in the local cell.
125 if (as
->parms
[EXECCELL_PARAM
].items
) {
126 strcpy(exec_cell
, as
->parms
[EXECCELL_PARAM
].items
->data
);
128 if (!afsclient_LocalCellGet(exec_cell
, &st
)) {
129 ERR_ST_EXT("can't get local cell name", st
);
134 * Get a token handle and a cell handle for this invocation
138 if (!afsclient_TokenGetNew
139 (auth_cell
, (const char *)0, (const char *)0, &tokenHandle
,
141 ERR_ST_EXT("can't get noauth tokens", st
);
143 } else if (existing_tokens
) {
144 if (as
->parms
[AUTHCELL_PARAM
].items
) {
145 /* Look for existing tokens for this cell */
146 strcpy(auth_cell
, as
->parms
[AUTHCELL_PARAM
].items
->data
);
148 if (!afsclient_LocalCellGet(auth_cell
, &st
)) {
149 ERR_ST_EXT("can't get local cell name", st
);
152 if (!afsclient_TokenGetExisting((const char*)auth_cell
, &tokenHandle
, &st
)) {
153 ERR_ST_EXT("can't find existing tokens", st
);
156 if (!afsclient_TokenGetNew
157 (auth_cell
, (const char *)as
->parms
[USER_PARAM
].items
->data
,
158 (const char *)as
->parms
[PASSWORD_PARAM
].items
->data
,
159 &tokenHandle
, &st
)) {
160 ERR_ST_EXT("can't get tokens", st
);
164 if (!afsclient_CellOpen(exec_cell
, tokenHandle
, &cellHandle
, &st
)) {
165 ERR_ST_EXT("can't open cell", st
);
172 MyAfterProc(struct cmd_syndesc
*as
,void *arock
)
175 afsclient_CellClose(cellHandle
, (afs_status_p
) 0);
176 afsclient_TokenClose(tokenHandle
, (afs_status_p
) 0);
183 SetupCommonCmdArgs(struct cmd_syndesc
*as
)
185 cmd_Seek(as
, USER_PARAM
);
186 cmd_AddParm(as
, "-authuser", CMD_SINGLE
, CMD_OPTIONAL
,
187 "user name to use for authentication");
188 cmd_AddParm(as
, "-authpassword", CMD_SINGLE
, CMD_OPTIONAL
,
189 "password to use for authentication");
190 cmd_AddParm(as
, "-authcell", CMD_SINGLE
, CMD_OPTIONAL
,
191 "cell to use for authentication");
192 cmd_AddParm(as
, "-execcell", CMD_SINGLE
, CMD_OPTIONAL
,
193 "cell where command will execute");
194 cmd_AddParm(as
, "-noauth", CMD_FLAG
, CMD_OPTIONAL
,
195 "run this command unauthenticated");
196 cmd_AddParm(as
, "-usetokens", CMD_FLAG
, CMD_OPTIONAL
,
197 "use already existing tokens");
201 main(int argc
, char *argv
[])
206 /* perform client initialization */
208 if (!afsclient_Init(&st
)) {
209 ERR_ST_EXT("can't init afs client", st
);
212 /* initialize command syntax and globals */
214 cmd_SetBeforeProc(MyBeforeProc
, NULL
);
215 cmd_SetAfterProc(MyAfterProc
, NULL
);
217 SetupClientAdminCmd();
223 /* execute command */
225 code
= cmd_Dispatch(argc
, argv
);