int main(int argc, char *argv[]) { int rc; afs_status_t st = 0; struct rx_connection *conn; char *srvrName; long srvrPort; void *cellHandle; afs_RPCStatsState_t state; ParseArgs(argc, argv, &srvrName, &srvrPort); rc = afsclient_Init(&st); if (!rc) { fprintf(stderr, "afsclient_Init, status %d\n", st); exit(1); } rc = afsclient_NullCellOpen(&cellHandle, &st); if (!rc) { fprintf(stderr, "afsclient_NullCellOpen, status %d\n", st); exit(1); } rc = afsclient_RPCStatOpenPort(cellHandle, srvrName, srvrPort, &conn, &st); if (!rc) { fprintf(stderr, "afsclient_RPCStatOpenPort, status %d\n", st); exit(1); } rc = util_RPCStatsStateGet(conn, RXSTATS_QueryProcessRPCStats, &state, &st); if (!rc) { fprintf(stderr, "util_RPCStatsStateGet, status %d\n", st); exit(1); } rc = afsclient_RPCStatClose(conn, &st); if (!rc) { fprintf(stderr, "afsclient_RPCStatClose, status %d\n", st); exit(1); } rc = afsclient_CellClose(cellHandle, &st); if (!rc) { fprintf(stderr, "afsclient_CellClose, status %d\n", st); exit(1); } printf("\n"); printf("Process RPC stats are "); switch (state) { case AFS_RPC_STATS_DISABLED: printf("disabled\n"); break; case AFS_RPC_STATS_ENABLED: printf("enabled\n"); break; default: printf("INVALID\n"); break; } printf("\n"); exit(0); }
int main(int argc, char *argv[]) { int rc; afs_status_t st = 0; struct rx_connection *conn; char *srvrName; long srvrPort; char *cellName; void *tokenHandle; void *cellHandle; ParseArgs(argc, argv, &cellName, &srvrName, &srvrPort); rc = afsclient_Init(&st); if (!rc) { fprintf(stderr, "afsclient_Init, status %d\n", st); exit(1); } rc = afsclient_TokenGetExisting(cellName, &tokenHandle, &st); if (!rc) { fprintf(stderr, "afsclient_TokenGetExisting, status %d\n", st); exit(1); } rc = afsclient_CellOpen(cellName, tokenHandle, &cellHandle, &st); if (!rc) { fprintf(stderr, "afsclient_CellOpen, status %d\n", st); exit(1); } rc = afsclient_RPCStatOpenPort(cellHandle, srvrName, srvrPort, &conn, &st); if (!rc) { fprintf(stderr, "afsclient_RPCStatOpenPort, status %d\n", st); exit(1); } rc = util_RPCStatsStateDisable(conn, RXSTATS_DisablePeerRPCStats, &st); if (!rc) { fprintf(stderr, "util_RPCStatsStateDisable, status %d\n", st); exit(1); } rc = afsclient_RPCStatClose(conn, &st); if (!rc) { fprintf(stderr, "afsclient_RPCStatClose, status %d\n", st); exit(1); } rc = afsclient_CellClose(cellHandle, &st); if (!rc) { fprintf(stderr, "afsclient_CellClose, status %d\n", st); exit(1); } rc = afsclient_TokenClose(tokenHandle, &st); if (!rc) { fprintf(stderr, "afsclient_TokenClose, status %d\n", st); exit(1); } exit(0); }
/* * cfg_HostSetAfsPrincipal() -- Put AFS server principal (afs) key in * host's KeyFile; principal is created if it does not exist. * * If first server host in cell, passwd must be initial password for * the afs principal; the afs principal is created. * * If additional server host, passwd can be specified or NULL; the * afs principal must already exist by definition. If passwd is NULL * then an attempt is made to fetch the afs key. If the key fetch fails * because pre 3.5 database servers are in use (which will only return a * key checksum) then the function fails with a return status of * ADMCFGAFSKEYNOTAVAILABLE; in this case the function should be called * again with passwd specified. If passwd is specified (not NULL) but the * password key fails a checksum comparison with the current afs key * then the function fails with a return status of ADMCFGAFSPASSWDINVALID. * * ASSUMPTIONS: Client configured and BOS server started; if first host in * cell then Authentication server must be started as well. */ int ADMINAPI cfg_HostSetAfsPrincipal(void *hostHandle, /* host config handle */ short isFirst, /* first server in cell flag */ const char *passwd, /* afs initial password */ afs_status_p st) { /* completion status */ int rc = 1; afs_status_t tst2, tst = 0; cfg_host_p cfg_host = (cfg_host_p) hostHandle; /* validate parameters */ if (!cfgutil_HostHandleValidate(cfg_host, &tst2)) { tst = tst2; } else if ((isFirst && passwd == NULL) || (passwd != NULL && *passwd == '\0')) { tst = ADMCFGPASSWDNULL; } /* put afs key in host's KeyFile */ if (tst == 0) { kas_identity_t afsIdentity; kas_encryptionKey_t afsKey; int afsKvno = 0; strcpy(afsIdentity.principal, "afs"); afsIdentity.instance[0] = '\0'; if (isFirst) { /* create afs principal */ if (!kas_PrincipalCreate (cfg_host->cellHandle, NULL, &afsIdentity, passwd, &tst2) && tst2 != KAEXIST) { /* failed to create principal (and not because existed) */ tst = tst2; } } if (tst == 0) { /* retrive afs principal information to verify or obtain key */ kas_principalEntry_t afsEntry; if (!kas_PrincipalGet (cfg_host->cellHandle, NULL, &afsIdentity, &afsEntry, &tst2)) { tst = tst2; } else { if (passwd != NULL) { /* password given; form key and verify as most recent */ kas_encryptionKey_t passwdKey; unsigned int passwdKeyCksum; if (!kas_StringToKey (cfg_host->cellName, passwd, &passwdKey, &tst2) || !kas_KeyCheckSum(&passwdKey, &passwdKeyCksum, &tst2)) { /* failed to form key or key checksum */ tst = tst2; } else if (passwdKeyCksum != afsEntry.keyCheckSum) { /* passwd string does not generate most recent key; * check if passwd string embeds key directly. */ if (KasKeyEmbeddedInString(passwd, &passwdKey)) { /* passwd string embeds kas key */ if (!kas_KeyCheckSum (&passwdKey, &passwdKeyCksum, &tst2)) { tst = tst2; } else if (passwdKeyCksum != afsEntry.keyCheckSum) { /* passwd string does not embed valid key */ tst = ADMCFGAFSPASSWDINVALID; } } else { /* passwd string does NOT embed key */ tst = ADMCFGAFSPASSWDINVALID; } } if (tst == 0) { /* passwd seems to generate/embed most recent key */ afsKey = passwdKey; afsKvno = afsEntry.keyVersion; } } else { /* password NOT given; check if key retrieved since * pre 3.5 database servers only return key checksum */ if (KasKeyIsZero(&afsEntry.key)) { tst = ADMCFGAFSKEYNOTAVAILABLE; } else { afsKey = afsEntry.key; afsKvno = afsEntry.keyVersion; } } } } if (tst == 0) { /* add key to host's KeyFile; RPC must be unauthenticated; * bosserver is presumed to be in noauth mode. */ void *cellHandle, *bosHandle; if (!afsclient_NullCellOpen(&cellHandle, &tst2)) { tst = tst2; } else { if (!bos_ServerOpen (cellHandle, cfg_host->hostName, &bosHandle, &tst2)) { tst = tst2; } else { if (!bos_KeyCreate(bosHandle, afsKvno, &afsKey, &tst2) && tst2 != BZKEYINUSE) { /* failed to add key (and not because existed) */ tst = tst2; } if (!bos_ServerClose(bosHandle, &tst2)) { tst = tst2; } } if (!afsclient_CellClose(cellHandle, &tst2)) { tst = tst2; } } } } if (tst != 0) { rc = 0; } if (st != NULL) { *st = tst; } return rc; }
int main(int argc, char *argv[]) { int rc; afs_status_t st = 0; struct rx_connection *conn; char *srvrName; long srvrPort; void *cellHandle; void *iterator; afs_RPCStats_t stats; char ifName[128]; char role[8]; const char **funcList; int funcListLen; int index; ParseArgs(argc, argv, &srvrName, &srvrPort); rc = afsclient_Init(&st); if (!rc) { fprintf(stderr, "afsclient_Init, status %d\n", st); exit(1); } rc = afsclient_NullCellOpen(&cellHandle, &st); if (!rc) { fprintf(stderr, "afsclient_NullCellOpen, status %d\n", st); exit(1); } rc = afsclient_RPCStatOpenPort(cellHandle, srvrName, srvrPort, &conn, &st); if (!rc) { fprintf(stderr, "afsclient_RPCStatOpenPort, status %d\n", st); exit(1); } rc = util_RPCStatsGetBegin(conn, RXSTATS_RetrieveProcessRPCStats, &iterator, &st); if (!rc) { fprintf(stderr, "util_RPCStatsGetBegin, status %d\n", st); exit(1); } while (util_RPCStatsGetNext(iterator, &stats, &st)) { index = stats.s.stats_v1.func_index; if (index == 0) { GetPrintStrings(&stats, ifName, role, &funcList, &funcListLen); printf("\nProcess RPC stats for %s accessed as a %s\n\n", ifName, role); } if (index >= funcListLen) { printf(" Function index %d\n", index); } else { printf(" %s\n", funcList[index]); } if (stats.s.stats_v1.invocations != 0) { printf("\tinvoc %"AFS_UINT64_FMT " bytes_sent %"AFS_UINT64_FMT " bytes_rcvd %"AFS_UINT64_FMT"\n", stats.s.stats_v1.invocations, stats.s.stats_v1.bytes_sent, stats.s.stats_v1.bytes_rcvd); printf("\tqsum %d.%06d qsqr %d.%06d" " qmin %d.%06d qmax %d.%06d\n", stats.s.stats_v1.queue_time_sum.sec, stats.s.stats_v1.queue_time_sum.usec, stats.s.stats_v1.queue_time_sum_sqr.sec, stats.s.stats_v1.queue_time_sum_sqr.usec, stats.s.stats_v1.queue_time_min.sec, stats.s.stats_v1.queue_time_min.usec, stats.s.stats_v1.queue_time_max.sec, stats.s.stats_v1.queue_time_max.usec); printf("\txsum %d.%06d xsqr %d.%06d" " xmin %d.%06d xmax %d.%06d\n", stats.s.stats_v1.execution_time_sum.sec, stats.s.stats_v1.execution_time_sum.usec, stats.s.stats_v1.execution_time_sum_sqr.sec, stats.s.stats_v1.execution_time_sum_sqr.usec, stats.s.stats_v1.execution_time_min.sec, stats.s.stats_v1.execution_time_min.usec, stats.s.stats_v1.execution_time_max.sec, stats.s.stats_v1.execution_time_max.usec); } else { printf("\tNever invoked\n"); } } if (st != ADMITERATORDONE) { fprintf(stderr, "util_RPCStatsGetNext, status %d\n", st); exit(1); } printf("\n"); rc = util_RPCStatsGetDone(iterator, &st); if (!rc) { fprintf(stderr, "util_RPCStatsGetDone, status %d\n", st); exit(1); } rc = afsclient_RPCStatClose(conn, &st); if (!rc) { fprintf(stderr, "afsclient_RPCStatClose, status %d\n", st); exit(1); } rc = afsclient_CellClose(cellHandle, &st); if (!rc) { fprintf(stderr, "afsclient_CellClose, status %d\n", st); exit(1); } exit(0); }
BOOL AfsAppLib_IsUserAdmin (UINT_PTR hCreds, LPTSTR pszUser) { #ifndef USE_KASERVER return TRUE; #else BOOL rc = FALSE; afs_status_t status; UINT_PTR idClient; if ((idClient = AfsAppLib_GetAdminServerClientID()) != 0) { TCHAR szCell[ cchRESOURCE ]; TCHAR szUser[ cchRESOURCE ]; SYSTEMTIME stExpire; if (asc_CredentialsCrack (idClient, hCreds, szCell, szUser, &stExpire, (ULONG*)&status)) { ASID idCell; if (asc_CellOpen (idClient, hCreds, szCell, AFSADMSVR_SCOPE_USERS, &idCell, (ULONG*)&status)) { ASID idUser; if (asc_ObjectFind (idClient, idCell, TYPE_USER, pszUser, &idUser, (ULONG*)&status)) { ASOBJPROP Info; if (asc_ObjectPropertiesGet (idClient, GET_ALL_DATA, idCell, idUser, &Info, (ULONG*)&status)) { if (Info.u.UserProperties.fHaveKasInfo) { rc = Info.u.UserProperties.KASINFO.fIsAdmin; } } } asc_CellClose (idClient, idCell, (ULONG*)&status); } } } else if (OpenClientLibrary()) { if (OpenKasLibrary()) { char szUserA[ cchRESOURCE ], szUser2A[ cchRESOURCE ]; char szCellA[ cchRESOURCE ]; unsigned long dateExpire; int fHasKasToken; if (afsclient_TokenQuery (hCreds, &dateExpire, szUserA, szUser2A, szCellA, &fHasKasToken, (afs_status_p)&status)) { PVOID hCell; if (afsclient_CellOpen (szCellA, hCreds, &hCell, &status)) { kas_identity_t Identity; memset (&Identity, 0x00, sizeof(Identity)); CopyStringToAnsi (Identity.principal, pszUser); kas_principalEntry_t Entry; if (kas_PrincipalGet (hCell, NULL, &Identity, &Entry, &status)) { if (Entry.adminSetting == KAS_ADMIN) rc = TRUE; } afsclient_CellClose (hCell, (afs_status_p)&status); } } CloseKasLibrary(); } CloseClientLibrary(); } return rc; #endif /* USE_KASERVER */ }