From 59b7132256a40f9a14f4d5bdf79f025a31bfcb68 Mon Sep 17 00:00:00 2001 From: Michael Meffie Date: Tue, 23 Aug 2016 21:12:22 -0400 Subject: [PATCH] libadmin: add rxstat_* -localauth option Add the -localauth option to the libadmin rxstat sample programs which require a token. This allows the use of these rxstat commands on the server when the cache manager is not available. Change-Id: If0d4d12abc80df73da5898ebb0052fb61d23cb48 Reviewed-on: https://gerrit.openafs.org/12376 Reviewed-by: Andrew Deason Reviewed-by: Cheyenne Wills Tested-by: BuildBot Reviewed-by: Michael Meffie --- src/libadmin/samples/rxstat_clear_peer.c | 22 +++++++++++++++---- src/libadmin/samples/rxstat_clear_process.c | 22 +++++++++++++++---- src/libadmin/samples/rxstat_disable_peer.c | 22 +++++++++++++++---- src/libadmin/samples/rxstat_disable_process.c | 22 +++++++++++++++---- src/libadmin/samples/rxstat_enable_peer.c | 22 +++++++++++++++---- src/libadmin/samples/rxstat_enable_process.c | 22 +++++++++++++++---- 6 files changed, 108 insertions(+), 24 deletions(-) diff --git a/src/libadmin/samples/rxstat_clear_peer.c b/src/libadmin/samples/rxstat_clear_peer.c index 641a84a28c..6173512c12 100644 --- a/src/libadmin/samples/rxstat_clear_peer.c +++ b/src/libadmin/samples/rxstat_clear_peer.c @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -34,6 +35,7 @@ enum optionsList { OPT_cell, OPT_server, OPT_port, + OPT_localauth, }; static int @@ -45,12 +47,15 @@ rxstat_clear_peer(struct cmd_syndesc *as, void *arock) char *srvrName = NULL; int srvrPort = 0; char *cellName = NULL; + int localauth = 0; + const char *confdir = AFSDIR_SERVER_ETC_DIR; void *tokenHandle; void *cellHandle; cmd_OptionAsString(as, OPT_cell, &cellName); cmd_OptionAsString(as, OPT_server, &srvrName); cmd_OptionAsInt(as, OPT_port, &srvrPort); + cmd_OptionAsFlag(as, OPT_localauth, &localauth); if (srvrPort <= 0 || srvrPort > USHRT_MAX) { fprintf(stderr, "Out of range -port value.\n"); @@ -63,10 +68,18 @@ rxstat_clear_peer(struct cmd_syndesc *as, void *arock) return 1; } - rc = afsclient_TokenGetExisting(cellName, &tokenHandle, &st); - if (!rc) { - fprintf(stderr, "afsclient_TokenGetExisting, status %d\n", st); - return 1; + if (localauth) { + rc = afsclient_TokenPrint(confdir, &tokenHandle, &st); + if (!rc) { + fprintf(stderr, "afsclient_TokenPrint, status %d\n", st); + return 1; + } + } else { + rc = afsclient_TokenGetExisting(cellName, &tokenHandle, &st); + if (!rc) { + fprintf(stderr, "afsclient_TokenGetExisting, status %d\n", st); + return 1; + } } rc = afsclient_CellOpen(cellName, tokenHandle, &cellHandle, &st); @@ -119,6 +132,7 @@ main(int argc, char *argv[]) cmd_AddParmAtOffset(ts, OPT_cell, "-cell", CMD_SINGLE, CMD_REQUIRED, "cell name"); cmd_AddParmAtOffset(ts, OPT_server, "-server", CMD_SINGLE, CMD_REQUIRED, "server"); cmd_AddParmAtOffset(ts, OPT_port, "-port", CMD_SINGLE, CMD_REQUIRED, "port"); + cmd_AddParmAtOffset(ts, OPT_localauth, "-localauth", CMD_FLAG, CMD_OPTIONAL, "use server tickets"); return cmd_Dispatch(argc, argv); } diff --git a/src/libadmin/samples/rxstat_clear_process.c b/src/libadmin/samples/rxstat_clear_process.c index b2260103d7..2ba248ceef 100644 --- a/src/libadmin/samples/rxstat_clear_process.c +++ b/src/libadmin/samples/rxstat_clear_process.c @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -34,6 +35,7 @@ enum optionsList { OPT_cell, OPT_server, OPT_port, + OPT_localauth, }; static int @@ -45,12 +47,15 @@ rxstat_clear_process(struct cmd_syndesc *as, void *arock) char *srvrName = NULL; int srvrPort = 0; char *cellName = NULL; + int localauth = 0; + const char *confdir = AFSDIR_SERVER_ETC_DIR; void *tokenHandle; void *cellHandle; cmd_OptionAsString(as, OPT_cell, &cellName); cmd_OptionAsString(as, OPT_server, &srvrName); cmd_OptionAsInt(as, OPT_port, &srvrPort); + cmd_OptionAsFlag(as, OPT_localauth, &localauth); if (srvrPort <= 0 || srvrPort > USHRT_MAX) { fprintf(stderr, "Out of range -port value.\n"); @@ -63,10 +68,18 @@ rxstat_clear_process(struct cmd_syndesc *as, void *arock) return 1; } - rc = afsclient_TokenGetExisting(cellName, &tokenHandle, &st); - if (!rc) { - fprintf(stderr, "afsclient_TokenGetExisting, status %d\n", st); - return 1; + if (localauth) { + rc = afsclient_TokenPrint(confdir, &tokenHandle, &st); + if (!rc) { + fprintf(stderr, "afsclient_TokenPrint, status %d\n", st); + return 1; + } + } else { + rc = afsclient_TokenGetExisting(cellName, &tokenHandle, &st); + if (!rc) { + fprintf(stderr, "afsclient_TokenGetExisting, status %d\n", st); + return 1; + } } rc = afsclient_CellOpen(cellName, tokenHandle, &cellHandle, &st); @@ -119,6 +132,7 @@ main(int argc, char *argv[]) cmd_AddParmAtOffset(ts, OPT_cell, "-cell", CMD_SINGLE, CMD_REQUIRED, "cell name"); cmd_AddParmAtOffset(ts, OPT_server, "-server", CMD_SINGLE, CMD_REQUIRED, "server"); cmd_AddParmAtOffset(ts, OPT_port, "-port", CMD_SINGLE, CMD_REQUIRED, "port"); + cmd_AddParmAtOffset(ts, OPT_localauth, "-localauth", CMD_FLAG, CMD_OPTIONAL, "use server tickets"); return cmd_Dispatch(argc, argv); } diff --git a/src/libadmin/samples/rxstat_disable_peer.c b/src/libadmin/samples/rxstat_disable_peer.c index e3d98cfa4d..f306c676c5 100644 --- a/src/libadmin/samples/rxstat_disable_peer.c +++ b/src/libadmin/samples/rxstat_disable_peer.c @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -34,6 +35,7 @@ enum optionsList { OPT_cell, OPT_server, OPT_port, + OPT_localauth, }; static int @@ -45,12 +47,15 @@ rxstat_disable_peer(struct cmd_syndesc *as, void *arock) char *srvrName = NULL; int srvrPort = 0; char *cellName = NULL; + int localauth = 0; + const char *confdir = AFSDIR_SERVER_ETC_DIR; void *tokenHandle; void *cellHandle; cmd_OptionAsString(as, OPT_cell, &cellName); cmd_OptionAsString(as, OPT_server, &srvrName); cmd_OptionAsInt(as, OPT_port, &srvrPort); + cmd_OptionAsFlag(as, OPT_localauth, &localauth); if (srvrPort <= 0 || srvrPort > USHRT_MAX) { fprintf(stderr, "Out of range -port value.\n"); @@ -63,10 +68,18 @@ rxstat_disable_peer(struct cmd_syndesc *as, void *arock) return 1; } - rc = afsclient_TokenGetExisting(cellName, &tokenHandle, &st); - if (!rc) { - fprintf(stderr, "afsclient_TokenGetExisting, status %d\n", st); - return 1; + if (localauth) { + rc = afsclient_TokenPrint(confdir, &tokenHandle, &st); + if (!rc) { + fprintf(stderr, "afsclient_TokenPrint, status %d\n", st); + return 1; + } + } else { + rc = afsclient_TokenGetExisting(cellName, &tokenHandle, &st); + if (!rc) { + fprintf(stderr, "afsclient_TokenGetExisting, status %d\n", st); + return 1; + } } rc = afsclient_CellOpen(cellName, tokenHandle, &cellHandle, &st); @@ -118,6 +131,7 @@ main(int argc, char *argv[]) cmd_AddParmAtOffset(ts, OPT_cell, "-cell", CMD_SINGLE, CMD_REQUIRED, "cell name"); cmd_AddParmAtOffset(ts, OPT_server, "-server", CMD_SINGLE, CMD_REQUIRED, "server"); cmd_AddParmAtOffset(ts, OPT_port, "-port", CMD_SINGLE, CMD_REQUIRED, "port"); + cmd_AddParmAtOffset(ts, OPT_localauth, "-localauth", CMD_FLAG, CMD_OPTIONAL, "use server tickets"); return cmd_Dispatch(argc, argv); } diff --git a/src/libadmin/samples/rxstat_disable_process.c b/src/libadmin/samples/rxstat_disable_process.c index 49673eb7a5..ca09d33e9b 100644 --- a/src/libadmin/samples/rxstat_disable_process.c +++ b/src/libadmin/samples/rxstat_disable_process.c @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -34,6 +35,7 @@ enum optionsList { OPT_cell, OPT_server, OPT_port, + OPT_localauth, }; static int @@ -45,12 +47,15 @@ rxstat_disable_process(struct cmd_syndesc *as, void *arock) char *srvrName = NULL; int srvrPort = 0; char *cellName = NULL; + int localauth = 0; + const char *confdir = AFSDIR_SERVER_ETC_DIR; void *tokenHandle; void *cellHandle; cmd_OptionAsString(as, OPT_cell, &cellName); cmd_OptionAsString(as, OPT_server, &srvrName); cmd_OptionAsInt(as, OPT_port, &srvrPort); + cmd_OptionAsFlag(as, OPT_localauth, &localauth); if (srvrPort <= 0 || srvrPort > USHRT_MAX) { fprintf(stderr, "Out of range -port value.\n"); @@ -63,10 +68,18 @@ rxstat_disable_process(struct cmd_syndesc *as, void *arock) return 1; } - rc = afsclient_TokenGetExisting(cellName, &tokenHandle, &st); - if (!rc) { - fprintf(stderr, "afsclient_TokenGetExisting, status %d\n", st); - return 1; + if (localauth) { + rc = afsclient_TokenPrint(confdir, &tokenHandle, &st); + if (!rc) { + fprintf(stderr, "afsclient_TokenPrint, status %d\n", st); + return 1; + } + } else { + rc = afsclient_TokenGetExisting(cellName, &tokenHandle, &st); + if (!rc) { + fprintf(stderr, "afsclient_TokenGetExisting, status %d\n", st); + return 1; + } } rc = afsclient_CellOpen(cellName, tokenHandle, &cellHandle, &st); @@ -118,6 +131,7 @@ main(int argc, char *argv[]) cmd_AddParmAtOffset(ts, OPT_cell, "-cell", CMD_SINGLE, CMD_REQUIRED, "cell name"); cmd_AddParmAtOffset(ts, OPT_server, "-server", CMD_SINGLE, CMD_REQUIRED, "server"); cmd_AddParmAtOffset(ts, OPT_port, "-port", CMD_SINGLE, CMD_REQUIRED, "port"); + cmd_AddParmAtOffset(ts, OPT_localauth, "-localauth", CMD_FLAG, CMD_OPTIONAL, "use server tickets"); return cmd_Dispatch(argc, argv); } diff --git a/src/libadmin/samples/rxstat_enable_peer.c b/src/libadmin/samples/rxstat_enable_peer.c index d83012295d..c81d48b819 100644 --- a/src/libadmin/samples/rxstat_enable_peer.c +++ b/src/libadmin/samples/rxstat_enable_peer.c @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -34,6 +35,7 @@ enum optionsList { OPT_cell, OPT_server, OPT_port, + OPT_localauth, }; static int @@ -45,12 +47,15 @@ rxstat_enable_peer(struct cmd_syndesc *as, void *arock) char *srvrName = NULL; int srvrPort = 0; char *cellName = NULL; + int localauth = 0; + const char *confdir = AFSDIR_SERVER_ETC_DIR; void *tokenHandle; void *cellHandle; cmd_OptionAsString(as, OPT_cell, &cellName); cmd_OptionAsString(as, OPT_server, &srvrName); cmd_OptionAsInt(as, OPT_port, &srvrPort); + cmd_OptionAsFlag(as, OPT_localauth, &localauth); if (srvrPort <= 0 || srvrPort > USHRT_MAX) { fprintf(stderr, "Out of range -port value.\n"); @@ -63,10 +68,18 @@ rxstat_enable_peer(struct cmd_syndesc *as, void *arock) return 1; } - rc = afsclient_TokenGetExisting(cellName, &tokenHandle, &st); - if (!rc) { - fprintf(stderr, "afsclient_TokenGetExisting, status %d\n", st); - return 1; + if (localauth) { + rc = afsclient_TokenPrint(confdir, &tokenHandle, &st); + if (!rc) { + fprintf(stderr, "afsclient_TokenPrint, status %d\n", st); + return 1; + } + } else { + rc = afsclient_TokenGetExisting(cellName, &tokenHandle, &st); + if (!rc) { + fprintf(stderr, "afsclient_TokenGetExisting, status %d\n", st); + return 1; + } } rc = afsclient_CellOpen(cellName, tokenHandle, &cellHandle, &st); @@ -118,6 +131,7 @@ main(int argc, char *argv[]) cmd_AddParmAtOffset(ts, OPT_cell, "-cell", CMD_SINGLE, CMD_REQUIRED, "cell name"); cmd_AddParmAtOffset(ts, OPT_server, "-server", CMD_SINGLE, CMD_REQUIRED, "server"); cmd_AddParmAtOffset(ts, OPT_port, "-port", CMD_SINGLE, CMD_REQUIRED, "port"); + cmd_AddParmAtOffset(ts, OPT_localauth, "-localauth", CMD_FLAG, CMD_OPTIONAL, "use server tickets"); return cmd_Dispatch(argc, argv); } diff --git a/src/libadmin/samples/rxstat_enable_process.c b/src/libadmin/samples/rxstat_enable_process.c index 940ecf2aa7..73c2e8b2c9 100644 --- a/src/libadmin/samples/rxstat_enable_process.c +++ b/src/libadmin/samples/rxstat_enable_process.c @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -33,6 +34,7 @@ enum optionsList { OPT_cell, OPT_server, OPT_port, + OPT_localauth, }; static int @@ -44,12 +46,15 @@ rxstat_enable_process(struct cmd_syndesc *as, void *arock) char *srvrName = NULL; int srvrPort = 0; char *cellName = NULL; + int localauth = 0; + const char *confdir = AFSDIR_SERVER_ETC_DIR; void *tokenHandle; void *cellHandle; cmd_OptionAsString(as, OPT_cell, &cellName); cmd_OptionAsString(as, OPT_server, &srvrName); cmd_OptionAsInt(as, OPT_port, &srvrPort); + cmd_OptionAsFlag(as, OPT_localauth, &localauth); if (srvrPort <= 0 || srvrPort > USHRT_MAX) { fprintf(stderr, "Out of range -port value.\n"); @@ -62,10 +67,18 @@ rxstat_enable_process(struct cmd_syndesc *as, void *arock) return 1; } - rc = afsclient_TokenGetExisting(cellName, &tokenHandle, &st); - if (!rc) { - fprintf(stderr, "afsclient_TokenGetExisting, status %d\n", st); - return 1; + if (localauth) { + rc = afsclient_TokenPrint(confdir, &tokenHandle, &st); + if (!rc) { + fprintf(stderr, "afsclient_TokenPrint, status %d\n", st); + return 1; + } + } else { + rc = afsclient_TokenGetExisting(cellName, &tokenHandle, &st); + if (!rc) { + fprintf(stderr, "afsclient_TokenGetExisting, status %d\n", st); + return 1; + } } rc = afsclient_CellOpen(cellName, tokenHandle, &cellHandle, &st); @@ -117,6 +130,7 @@ main(int argc, char *argv[]) cmd_AddParmAtOffset(ts, OPT_cell, "-cell", CMD_SINGLE, CMD_REQUIRED, "cell name"); cmd_AddParmAtOffset(ts, OPT_server, "-server", CMD_SINGLE, CMD_REQUIRED, "server"); cmd_AddParmAtOffset(ts, OPT_port, "-port", CMD_SINGLE, CMD_REQUIRED, "port"); + cmd_AddParmAtOffset(ts, OPT_localauth, "-localauth", CMD_FLAG, CMD_OPTIONAL, "use server tickets"); return cmd_Dispatch(argc, argv); }