/*
- * Copyright (C) 1998 Transarc Corporation. All rights reserved.
- *
+ * Copyright 2000, International Business Machines Corporation and others.
+ * All Rights Reserved.
+ *
+ * This software has been released under the terms of the IBM Public
+ * License. For details, see the LICENSE file in the top-level source
+ * directory or online at http://www.openafs.org/dl/license10.html
*/
+#include <afsconfig.h>
+#include <afs/param.h>
#include <afs/stds.h>
-#include "afs_clientAdmin.h"
-#include "../adminutil/afs_AdminInternal.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <afs/cellconfig.h>
+
+#include <roken.h>
+
#ifdef AFS_NT40_ENV
#include <afs/afssyscalls.h>
-#include <winsock2.h>
#include <afs/fs_utils.h>
+#define close(x) closesocket(x)
#else
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
#include <afs/venus.h>
-#include <errno.h>
-#include <strings.h>
#endif
-#include <string.h>
-#include <afs/kautils.h>
#include <rx/rx.h>
+#include <rx/rxstat.h>
#include <rx/rx_null.h>
#include <rx/rxkad.h>
+
+#include <afs/kautils.h>
#include <afs/dirpath.h>
#include <afs/afs_AdminErrors.h>
#include <afs/afs_vosAdmin.h>
#include <afs/ptserver.h>
#include <afs/vlserver.h>
#include <afs/pthread_glock.h>
+#include <afs/sys_prototypes.h>
-
-#include "../../permit_xprt.h"
+#include "afs_clientAdmin.h"
+#include "../adminutil/afs_AdminInternal.h"
/*
* AFS client administration functions.
*
*/
-static const unsigned long ADMIN_TICKET_LIFETIME = 24*3600;
+static const unsigned long ADMIN_TICKET_LIFETIME = 24 * 3600;
+
+static const unsigned long SERVER_TTL = 10 * 60;
/*
* We need a way to track whether or not the client library has been
static int client_init;
static pthread_once_t client_init_once = PTHREAD_ONCE_INIT;
-static void client_once(void) {
+static void
+client_once(void)
+{
client_init = 1;
}
* Returns != 0 upon successful completion.
*/
-static int IsTokenValid(
- const afs_token_handle_p token,
- afs_status_p st)
+static int
+IsTokenValid(const afs_token_handle_p token, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
-
+
if (token == NULL) {
tst = ADMCLIENTTOKENHANDLENULL;
goto fail_IsTokenValid;
goto fail_IsTokenValid;
}
- if ((token->begin_magic != BEGIN_MAGIC) ||
- (token->end_magic != END_MAGIC)) {
+ if ((token->begin_magic != BEGIN_MAGIC)
+ || (token->end_magic != END_MAGIC)) {
tst = ADMCLIENTTOKENHANDLEBADMAGIC;
goto fail_IsTokenValid;
}
rc = 1;
-fail_IsTokenValid:
+ fail_IsTokenValid:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
-
+
/*
* afsclient_TokenGetExisting - get tokens that already exist and
* are held by the cache manager.
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_TokenGetExisting(
- const char *cellName,
- void **tokenHandle,
- afs_status_p st)
+int ADMINAPI
+afsclient_TokenGetExisting(const char *cellName, void **tokenHandle,
+ afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
struct ktc_principal afs_server;
- afs_token_handle_p t_handle = (afs_token_handle_p) calloc(1, sizeof(afs_token_handle_t));
-
+ afs_token_handle_p t_handle =
+ (afs_token_handle_p) calloc(1, sizeof(afs_token_handle_t));
+
if (client_init == 0) {
tst = ADMCLIENTNOINIT;
goto fail_afsclient_TokenGetExisting;
afs_server.instance[0] = 0;
strcpy(afs_server.cell, cellName);
- if (!(tst = ktc_GetToken(&afs_server, &t_handle->afs_token,
- sizeof(t_handle->afs_token),
- &t_handle->client))) {
+ if (!
+ (tst =
+ ktc_GetToken(&afs_server, &t_handle->afs_token,
+ sizeof(t_handle->afs_token), &t_handle->client))) {
/*
* The token has been retrieved successfully, initialize
* the rest of the token handle structure
*/
- strcpy(t_handle->cell, cellName);
+ strncpy(t_handle->cell, cellName, MAXCELLCHARS);
+ t_handle->cell[MAXCELLCHARS - 1] = '\0';
t_handle->afs_token_set = 1;
t_handle->from_kernel = 1;
t_handle->kas_token_set = 0;
t_handle->sc_index = 2;
- t_handle->afs_sc[t_handle->sc_index] =
+ t_handle->afs_sc[t_handle->sc_index] =
rxkad_NewClientSecurityObject(rxkad_clear,
&t_handle->afs_token.sessionKey,
t_handle->afs_token.kvno,
t_handle->afs_token.ticketLen,
t_handle->afs_token.ticket);
- t_handle->afs_encrypt_sc[t_handle->sc_index] =
+ t_handle->afs_encrypt_sc[t_handle->sc_index] =
rxkad_NewClientSecurityObject(rxkad_crypt,
&t_handle->afs_token.sessionKey,
t_handle->afs_token.kvno,
t_handle->afs_token.ticketLen,
t_handle->afs_token.ticket);
- if ((t_handle->afs_sc[t_handle->sc_index] == NULL) ||
- (t_handle->afs_sc[t_handle->sc_index] == NULL)) {
+ if ((t_handle->afs_sc[t_handle->sc_index] == NULL)
+ || (t_handle->afs_sc[t_handle->sc_index] == NULL)) {
tst = ADMCLIENTTOKENHANDLENOSECURITY;
goto fail_afsclient_TokenGetExisting;
} else {
t_handle->begin_magic = BEGIN_MAGIC;
t_handle->is_valid = 1;
t_handle->end_magic = END_MAGIC;
- *tokenHandle = (void *) t_handle;
+ *tokenHandle = (void *)t_handle;
}
} else {
goto fail_afsclient_TokenGetExisting;
}
rc = 1;
-fail_afsclient_TokenGetExisting:
+ fail_afsclient_TokenGetExisting:
if ((rc == 0) && (t_handle != NULL)) {
free(t_handle);
}
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
-
+
/*
* afsclient_TokenSet - set the tokens represented by tokenHandle to be
* active in the kernel (aka ka_SetToken).
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_TokenSet(
- const void *tokenHandle,
- afs_status_p st)
+int ADMINAPI
+afsclient_TokenSet(const void *tokenHandle, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
struct ktc_principal afs_server;
afs_token_handle_p t_handle = (afs_token_handle_p) tokenHandle;
-
+
if (!IsTokenValid(t_handle, &tst)) {
goto fail_afsclient_TokenSet;
}
afs_server.instance[0] = 0;
strcpy(afs_server.cell, t_handle->cell);
- tst = ktc_SetToken(&afs_server, &t_handle->afs_token, &t_handle->client, 0);
+ tst =
+ ktc_SetToken(&afs_server, &t_handle->afs_token, &t_handle->client, 0);
if (!tst) {
rc = 1;
}
-fail_afsclient_TokenSet:
+ fail_afsclient_TokenSet:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
-
+
/*
* GetKASToken - get a KAS token and store it in the tokenHandle.
*
* Returns != 0 upon successful completion.
*/
-static int GetKASToken(
- const char *cellName,
- const char *principal,
- const char *password,
- afs_token_handle_p tokenHandle,
- afs_status_p st)
+static int
+GetKASToken(const char *cellName, const char *principal, const char *password,
+ afs_token_handle_p tokenHandle, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
char name[MAXKTCNAMELEN];
char inst[MAXKTCNAMELEN];
int have_server_conn = 0;
-
+
token = &tokenHandle->kas_token;
ka_StringToKey((char *)password, (char *)cellName, &key);
* Get an unauthenticated connection in the right cell to use for
* retrieving the token.
*/
-
- tst = ka_AuthServerConn((char *)cellName, KA_AUTHENTICATION_SERVICE, 0,
- &unauth_conn);
+
+ tst =
+ ka_AuthServerConn((char *)cellName, KA_AUTHENTICATION_SERVICE, 0,
+ &unauth_conn);
if (tst != 0) {
goto fail_GetKASToken;
}
have_server_conn = 1;
- tst = ka_ParseLoginName((char *)principal, name, inst, (char *) 0);
+ tst = ka_ParseLoginName((char *)principal, name, inst, NULL);
if (tst != 0) {
goto fail_GetKASToken;
}
- tst = ka_Authenticate(name, inst, (char *)cellName, unauth_conn,
- KA_MAINTENANCE_SERVICE, &key, now,
- now+ADMIN_TICKET_LIFETIME, token, &expire);
+ tst =
+ ka_Authenticate(name, inst, (char *)cellName, unauth_conn,
+ KA_MAINTENANCE_SERVICE, &key, now,
+ now + ADMIN_TICKET_LIFETIME, token, &expire);
if (tst != 0) {
goto fail_GetKASToken;
}
rc = 1;
-fail_GetKASToken:
+ fail_GetKASToken:
if (have_server_conn) {
ubik_ClientDestroy(unauth_conn);
}
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
-
+
/*
* GetAFSToken - get a AFS token and store it in the tokenHandle.
*
* Returns != 0 upon successful completion.
*/
-static int GetAFSToken(
- const char *cellName,
- const char *principal,
- const char *password,
- afs_token_handle_p tokenHandle,
- afs_status_p st)
+static int
+GetAFSToken(const char *cellName, const char *principal, const char *password,
+ afs_token_handle_p tokenHandle, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
struct ktc_token auth_token;
struct ktc_token *token;
unsigned long now = time(0);
-
+
token = &tokenHandle->afs_token;
ka_StringToKey((char *)password, (char *)cellName, &key);
* Get an unauthenticated connection in the right cell to use for
* retrieving the token.
*/
-
- tst = ka_AuthServerConn((char *)cellName, KA_AUTHENTICATION_SERVICE, 0,
- &unauth_conn);
+
+ tst =
+ ka_AuthServerConn((char *)cellName, KA_AUTHENTICATION_SERVICE, 0,
+ &unauth_conn);
if (tst) {
goto fail_GetAFSToken;
}
- tst = ka_ParseLoginName((char *)principal, tokenHandle->client.name,
- tokenHandle->client.instance, (char *) 0);
+ tst =
+ ka_ParseLoginName((char *)principal, tokenHandle->client.name,
+ tokenHandle->client.instance, NULL);
if (tst) {
goto fail_GetAFSToken;
}
- tst = ka_Authenticate(tokenHandle->client.name,
- tokenHandle->client.instance, (char *)cellName,
- unauth_conn, KA_TICKET_GRANTING_SERVICE,
- &key, now, now+ADMIN_TICKET_LIFETIME,
- &auth_token, &expire);
+ tst =
+ ka_Authenticate(tokenHandle->client.name,
+ tokenHandle->client.instance, (char *)cellName,
+ unauth_conn, KA_TICKET_GRANTING_SERVICE, &key, now,
+ now + ADMIN_TICKET_LIFETIME, &auth_token, &expire);
if (tst) {
goto fail_GetAFSToken;
}
- tst = ka_AuthServerConn((char *)cellName, KA_TICKET_GRANTING_SERVICE,
- 0, &auth_conn);
+ tst =
+ ka_AuthServerConn((char *)cellName, KA_TICKET_GRANTING_SERVICE, 0,
+ &auth_conn);
if (tst) {
goto fail_GetAFSToken;
}
- tst = ka_CellToRealm((char *)cellName, tokenHandle->client.cell, (int *) 0);
+ tst =
+ ka_CellToRealm((char *)cellName, tokenHandle->client.cell, (int *)0);
if (tst) {
goto fail_GetAFSToken;
}
- tst = ka_GetToken("afs", "", (char *)cellName,
- tokenHandle->client.name,
- tokenHandle->client.instance,
- auth_conn, now,
- now+ADMIN_TICKET_LIFETIME,
- &auth_token, tokenHandle->client.cell,
- token);
+ tst =
+ ka_GetToken("afs", "", (char *)cellName, tokenHandle->client.name,
+ tokenHandle->client.instance, auth_conn, now,
+ now + ADMIN_TICKET_LIFETIME, &auth_token,
+ tokenHandle->client.cell, token);
if (tst) {
goto fail_GetAFSToken;
}
rc = 1;
-fail_GetAFSToken:
+ fail_GetAFSToken:
if (auth_conn) {
ubik_ClientDestroy(auth_conn);
}
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
-
+
/*
* afsclient_TokenGetNew - get new tokens for a user and store them
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_TokenGetNew(
- const char *cellName,
- const char *principal,
- const char *password,
- void **tokenHandle,
- afs_status_p st)
+int ADMINAPI
+afsclient_TokenGetNew(const char *cellName, const char *principal,
+ const char *password, void **tokenHandle,
+ afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
- afs_token_handle_p t_handle = (afs_token_handle_p) calloc(1, sizeof(afs_token_handle_t));
-
+ afs_token_handle_p t_handle =
+ (afs_token_handle_p) calloc(1, sizeof(afs_token_handle_t));
+
if (client_init == 0) {
tst = ADMCLIENTNOINIT;
goto fail_afsclient_TokenGetNew;
}
-
+
if (t_handle == NULL) {
tst = ADMNOMEM;
goto fail_afsclient_TokenGetNew;
}
-
+
/*
* Check to see if the principal or password is missing. If it is,
* get unauthenticated tokens for the cell
*/
- if ((principal == NULL) || (*principal == 0) ||
- (password == NULL) || (*password == 0)) {
+ if ((principal == NULL) || (*principal == 0) || (password == NULL)
+ || (*password == 0)) {
t_handle->from_kernel = 0;
t_handle->afs_token_set = 1;
t_handle->kas_token_set = 1;
t_handle->sc_index = 0;
- t_handle->afs_sc[t_handle->sc_index] =
+ t_handle->afs_sc[t_handle->sc_index] =
rxnull_NewClientSecurityObject();
- t_handle->afs_encrypt_sc[t_handle->sc_index] =
+ t_handle->afs_encrypt_sc[t_handle->sc_index] =
rxnull_NewClientSecurityObject();
- t_handle->kas_sc[t_handle->sc_index] =
+ t_handle->kas_sc[t_handle->sc_index] =
rxnull_NewClientSecurityObject();
t_handle->begin_magic = BEGIN_MAGIC;
t_handle->is_valid = 1;
t_handle->afs_token.endTime = 0;
t_handle->end_magic = END_MAGIC;
- *tokenHandle = (void *) t_handle;
+ *tokenHandle = (void *)t_handle;
} else {
* create an authenticated token
*/
- if ((GetAFSToken(cellName, principal, password, t_handle, &tst)) &&
- (GetKASToken(cellName, principal, password, t_handle, &tst))) {
- strcpy(t_handle->cell, cellName);
+ if ((GetAFSToken(cellName, principal, password, t_handle, &tst))
+ && (GetKASToken(cellName, principal, password, t_handle, &tst))) {
+ strncpy(t_handle->cell, cellName, MAXCELLCHARS);
+ t_handle->cell[MAXCELLCHARS - 1] = '\0';
t_handle->from_kernel = 0;
t_handle->afs_token_set = 1;
t_handle->kas_token_set = 1;
t_handle->sc_index = 2;
- t_handle->afs_sc[t_handle->sc_index] =
+ t_handle->afs_sc[t_handle->sc_index] =
rxkad_NewClientSecurityObject(rxkad_clear,
&t_handle->afs_token.sessionKey,
t_handle->afs_token.kvno,
t_handle->afs_token.ticketLen,
t_handle->afs_token.ticket);
- t_handle->afs_encrypt_sc[t_handle->sc_index] =
+ t_handle->afs_encrypt_sc[t_handle->sc_index] =
rxkad_NewClientSecurityObject(rxkad_crypt,
&t_handle->afs_token.sessionKey,
t_handle->afs_token.kvno,
t_handle->afs_token.ticketLen,
t_handle->afs_token.ticket);
- t_handle->kas_sc[t_handle->sc_index] =
+ t_handle->kas_sc[t_handle->sc_index] =
rxkad_NewClientSecurityObject(rxkad_crypt,
&t_handle->kas_token.sessionKey,
t_handle->kas_token.kvno,
t_handle->kas_token.ticketLen,
t_handle->kas_token.ticket);
- if ((t_handle->afs_sc[t_handle->sc_index] != NULL) &&
- (t_handle->afs_encrypt_sc[t_handle->sc_index] != NULL) &&
- (t_handle->kas_sc[t_handle->sc_index] != NULL)) {
+ if ((t_handle->afs_sc[t_handle->sc_index] != NULL)
+ && (t_handle->afs_encrypt_sc[t_handle->sc_index] != NULL)
+ && (t_handle->kas_sc[t_handle->sc_index] != NULL)) {
t_handle->begin_magic = BEGIN_MAGIC;
t_handle->is_valid = 1;
t_handle->end_magic = END_MAGIC;
- *tokenHandle = (void *) t_handle;
+ *tokenHandle = (void *)t_handle;
} else {
tst = ADMCLIENTTOKENHANDLENOSECURITY;
goto fail_afsclient_TokenGetNew;
}
}
rc = 1;
-
- fail_afsclient_TokenGetNew:
+
+ fail_afsclient_TokenGetNew:
if ((rc == 0) && (t_handle != NULL)) {
free(t_handle);
}
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
-
+
/*
* afsclient_TokenQuery - get the expiration time of the tokens.
*
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_TokenQuery(
- void *tokenHandle,
- unsigned long *expirationDateP,
- char *principal,
- char *instance,
- char *cell,
- int *hasKasTokens,
- afs_status_p st)
+int ADMINAPI
+afsclient_TokenQuery(void *tokenHandle, unsigned long *expirationDateP,
+ char *principal, char *instance, char *cell,
+ int *hasKasTokens, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
afs_token_handle_p t_handle = (afs_token_handle_p) tokenHandle;
-
+
if (client_init == 0) {
tst = ADMCLIENTNOINIT;
rc = 0;
goto fail_afsclient_TokenQuery;
}
-
+
if (IsTokenValid(t_handle, &tst)) {
if (principal != NULL) {
strcpy(principal, t_handle->client.name);
rc = 1;
}
-fail_afsclient_TokenQuery:
+ fail_afsclient_TokenQuery:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
-
+
/*
* afsclient_TokenClose - close an existing token.
*
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_TokenClose(
- const void *tokenHandle,
- afs_status_p st)
+int ADMINAPI
+afsclient_TokenClose(const void *tokenHandle, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
afs_token_handle_p t_handle = (afs_token_handle_p) tokenHandle;
-
+
if (client_init == 0) {
tst = ADMCLIENTNOINIT;
goto fail_afsclient_TokenClose;
}
-
+
if (IsTokenValid(t_handle, &tst)) {
t_handle->is_valid = 0;
free(t_handle);
rc = 1;
}
-fail_afsclient_TokenClose:
+ fail_afsclient_TokenClose:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
-
+
#define NUM_SERVER_TYPES 3
-
+
/* must match NUM_SERVER_TYPES */
-typedef enum {KAS, PTS, VOS} afs_server_list_t;
-
+typedef enum { KAS, PTS, VOS } afs_server_list_t;
+
typedef struct afs_server {
char *serv;
int serviceId;
struct ubik_client **ubik;
struct rx_securityClass *sc;
int *valid;
-} afs_server_t, *afs_server_p;
-
-static afs_server_t servers[NUM_SERVER_TYPES]
- = { {AFSCONF_KAUTHSERVICE, KA_MAINTENANCE_SERVICE, 0, 0, 0},
- {AFSCONF_PROTSERVICE, PRSRV, 0, 0, 0},
- {AFSCONF_VLDBSERVICE, USER_SERVICE_ID, 0, 0, 0}};
-
+} afs_server_t, *afs_server_p;
+
/*
* afsclient_CellOpen - Open a particular cell for work as a particular
* user.
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_CellOpen(
- const char *cellName,
- const void *tokenHandle,
- void **cellHandleP,
- afs_status_p st)
+int ADMINAPI
+afsclient_CellOpen(const char *cellName, const void *tokenHandle,
+ void **cellHandleP, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
afs_token_handle_p t_handle = (afs_token_handle_p) tokenHandle;
- afs_cell_handle_p c_handle = (afs_cell_handle_p)
- calloc(1, sizeof(afs_cell_handle_t));
+ afs_cell_handle_p c_handle = (afs_cell_handle_p)
+ calloc(1, sizeof(afs_cell_handle_t));
struct afsconf_dir *tdir = NULL;
struct afsconf_cell info;
struct rx_connection *serverconns[MAXSERVERS];
struct rx_securityClass *sc[3];
int scIndex;
char copyCell[MAXCELLCHARS];
-
+
+ afs_server_t servers[NUM_SERVER_TYPES]
+ = { {AFSCONF_KAUTHSERVICE, KA_MAINTENANCE_SERVICE, 0, 0, 0},
+ {AFSCONF_PROTSERVICE, PRSRV, 0, 0, 0},
+ {AFSCONF_VLDBSERVICE, USER_SERVICE_ID, 0, 0, 0}
+ };
+
if (client_init == 0) {
tst = ADMCLIENTNOINIT;
goto fail_afsclient_CellOpen;
}
-
+
if (c_handle == NULL) {
tst = ADMNOMEM;
goto fail_afsclient_CellOpen;
}
-
+
if (t_handle == NULL) {
tst = ADMCLIENTTOKENHANDLENULL;
goto fail_afsclient_CellOpen;
}
-
+
if ((cellName == NULL) || (*cellName == 0)) {
tst = ADMCLIENTCELLNAMENULL;
goto fail_afsclient_CellOpen;
}
-
+
if (cellHandleP == NULL) {
tst = ADMCLIENTCELLHANDLEPNULL;
goto fail_afsclient_CellOpen;
}
-
+
/*
* Check that the token handle contains valid data and the calloc
* succeeded
* information for each server in the cell
*/
- strcpy(c_handle->working_cell, cellName);
+ strncpy(c_handle->working_cell, cellName, MAXCELLCHARS);
+ c_handle->working_cell[MAXCELLCHARS - 1] = '\0';
if (!(tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH))) {
tst = ADMCLIENTBADCLIENTCONFIG;
goto fail_afsclient_CellOpen;
* We must copy the cellName here because afsconf_GetCellInfo
* actually writes over the cell name it is passed.
*/
- strncpy(copyCell, cellName, MAXCELLCHARS - 1);
- for(i=0;(i<NUM_SERVER_TYPES);i++) {
+ strncpy(copyCell, cellName, MAXCELLCHARS);
+ copyCell[MAXCELLCHARS - 1] ='\0';
+ for (i = 0; (i < NUM_SERVER_TYPES); i++) {
if (i == KAS) {
- tst = ka_AuthServerConn((char *)cellName,servers[i].serviceId,
- ((t_handle->sc_index == 0) ||
- (!t_handle->kas_token_set)) ?
- 0 : &t_handle->kas_token,
- servers[i].ubik);
+ tst =
+ ka_AuthServerConn((char *)cellName, servers[i].serviceId,
+ ((t_handle->sc_index == 0)
+ || (!t_handle->
+ kas_token_set)) ? 0 : &t_handle->
+ kas_token, servers[i].ubik);
if (tst) {
goto fail_afsclient_CellOpen;
}
} else {
- tst = afsconf_GetCellInfo(tdir, copyCell,
- servers[i].serv, &info);
+ tst = afsconf_GetCellInfo(tdir, copyCell, servers[i].serv, &info);
if (!tst) {
/* create ubik client handles for each server */
scIndex = t_handle->sc_index;
sc[scIndex] = servers[i].sc;
- for(j=0;(j<info.numServers);j++) {
- serverconns[j] =
- rx_GetCachedConnection(
- info.hostAddr[j].sin_addr.s_addr,
- info.hostAddr[j].sin_port,
- servers[i].serviceId,
- sc[scIndex], scIndex);
+ for (j = 0; (j < info.numServers); j++) {
+ serverconns[j] =
+ rx_GetCachedConnection(info.hostAddr[j].sin_addr.
+ s_addr,
+ info.hostAddr[j].sin_port,
+ servers[i].serviceId,
+ sc[scIndex], scIndex);
}
serverconns[j] = 0;
- tst = ubik_ClientInit(serverconns,servers[i].ubik);
+ tst = ubik_ClientInit(serverconns, servers[i].ubik);
if (tst) {
goto fail_afsclient_CellOpen;
}
c_handle->tokens = t_handle;
rc = 1;
-fail_afsclient_CellOpen:
+ fail_afsclient_CellOpen:
if (tdir) {
afsconf_Close(tdir);
*/
if (rc == 0) {
if (c_handle != NULL) {
- if (c_handle->kas_valid) ubik_ClientDestroy(c_handle->kas);
- if (c_handle->pts_valid) ubik_ClientDestroy(c_handle->pts);
- if (c_handle->vos_valid) ubik_ClientDestroy(c_handle->vos);
+ if (c_handle->kas_valid)
+ ubik_ClientDestroy(c_handle->kas);
+ if (c_handle->pts_valid)
+ ubik_ClientDestroy(c_handle->pts);
+ if (c_handle->vos_valid)
+ ubik_ClientDestroy(c_handle->vos);
free(c_handle);
}
} else {
c_handle->begin_magic = BEGIN_MAGIC;
c_handle->is_valid = 1;
c_handle->is_null = 0;
+ c_handle->server_list = NULL;
+ c_handle->server_ttl = 0;
c_handle->end_magic = END_MAGIC;
- *cellHandleP = (void *) c_handle;
+ *cellHandleP = (void *)c_handle;
}
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
-
+
/*
* afsclient_NullCellOpen - open a null cell handle for access.
*
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_NullCellOpen(
- void **cellHandleP,
- afs_status_p st)
+int ADMINAPI
+afsclient_NullCellOpen(void **cellHandleP, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
- afs_cell_handle_p c_handle = (afs_cell_handle_p)
- calloc(1, sizeof(afs_cell_handle_t));
+ afs_cell_handle_p c_handle = (afs_cell_handle_p)
+ calloc(1, sizeof(afs_cell_handle_t));
+
-
/*
* Validate parameters
*/
tst = ADMCLIENTNOINIT;
goto fail_afsclient_NullCellOpen;
}
-
+
if (c_handle == NULL) {
tst = ADMNOMEM;
goto fail_afsclient_NullCellOpen;
}
-
+
/*
* Get unauthenticated tokens for any cell
*/
- if (!afsclient_TokenGetNew(0, 0, 0, (void *) &c_handle->tokens, &tst)) {
+ if (!afsclient_TokenGetNew(0, 0, 0, (void *)&c_handle->tokens, &tst)) {
goto fail_afsclient_NullCellOpen;
}
c_handle->kas_valid = 0;
c_handle->pts_valid = 0;
c_handle->vos_valid = 0;
- c_handle->kas = 0;
- c_handle->pts = 0;
- c_handle->vos = 0;
- *cellHandleP = (void *) c_handle;
+ c_handle->kas = NULL;
+ c_handle->pts = NULL;
+ c_handle->vos = NULL;
+ c_handle->server_list = NULL;
+ c_handle->server_ttl = 0;
+ *cellHandleP = (void *)c_handle;
rc = 1;
-
-fail_afsclient_NullCellOpen:
+
+ fail_afsclient_NullCellOpen:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_CellClose(
- const void *cellHandle,
- afs_status_p st)
+int ADMINAPI
+afsclient_CellClose(const void *cellHandle, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
-
+
if (client_init == 0) {
tst = ADMCLIENTNOINIT;
goto fail_afsclient_CellClose;
}
-
+
if (c_handle == NULL) {
tst = ADMCLIENTCELLHANDLENULL;
goto fail_afsclient_CellClose;
}
- if (c_handle->kas_valid) ubik_ClientDestroy(c_handle->kas);
- if (c_handle->pts_valid) ubik_ClientDestroy(c_handle->pts);
- if (c_handle->vos_valid) ubik_ClientDestroy(c_handle->vos);
- if (c_handle->is_null) afsclient_TokenClose(c_handle->tokens, 0);
+ if (c_handle->server_list)
+ free(c_handle->server_list);
+ if (c_handle->kas_valid)
+ ubik_ClientDestroy(c_handle->kas);
+ if (c_handle->pts_valid)
+ ubik_ClientDestroy(c_handle->pts);
+ if (c_handle->vos_valid)
+ ubik_ClientDestroy(c_handle->vos);
+ if (c_handle->is_null)
+ afsclient_TokenClose(c_handle->tokens, 0);
c_handle->kas_valid = 0;
c_handle->pts_valid = 0;
c_handle->vos_valid = 0;
free(c_handle);
rc = 1;
-fail_afsclient_CellClose:
+ fail_afsclient_CellClose:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
*
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_CellNameGet(
- const void *cellHandle,
- const char **cellNameP,
- afs_status_p st)
+int ADMINAPI
+afsclient_CellNameGet(const void *cellHandle, const char **cellNameP,
+ afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
*cellNameP = c_handle->working_cell;
rc = 1;
-fail_afsclient_CellNameGet:
+ fail_afsclient_CellNameGet:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
*
* Returns != 0 upon successful completion.
*/
-
-int ADMINAPI afsclient_LocalCellGet(
- char *cellName,
- afs_status_p st)
+
+int ADMINAPI
+afsclient_LocalCellGet(char *cellName, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
struct afsconf_dir *tdir = NULL;
-
+
if (client_init == 0) {
tst = ADMCLIENTNOINIT;
goto fail_afsclient_LocalCellGet;
}
-
+
if (cellName == NULL) {
- tst = ADMCLIENTCELLNAMENULL;
- goto fail_afsclient_LocalCellGet;
+ tst = ADMCLIENTCELLNAMENULL;
+ goto fail_afsclient_LocalCellGet;
}
tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
if (!tdir) {
tst = ADMCLIENTBADCLIENTCONFIG;
- goto fail_afsclient_LocalCellGet;
+ goto fail_afsclient_LocalCellGet;
}
- if (tst = afsconf_GetLocalCell(tdir, cellName, MAXCELLCHARS)) {
- goto fail_afsclient_LocalCellGet;
+ if ((tst = afsconf_GetLocalCell(tdir, cellName, MAXCELLCHARS))) {
+ goto fail_afsclient_LocalCellGet;
}
rc = 1;
-
-fail_afsclient_LocalCellGet:
-
+
+ fail_afsclient_LocalCellGet:
+
if (tdir != NULL) {
afsconf_Close(tdir);
}
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
-
+
#ifdef AFS_NT40_ENV
-
-static int client_ExtractDriveLetter(
- char *path)
+
+static int
+client_ExtractDriveLetter(char *path)
{
int rc = 0;
* Determine the parent directory of a give directory
*/
-static int Parent(
- char *directory,
- char *parentDirectory)
+static int
+Parent(char *directory, char *parentDirectory)
{
- register char *tp;
+ char *tp;
int rc = 0;
strcpy(parentDirectory, directory);
tp = strrchr(parentDirectory, '\\');
if (tp) {
/* lv trailing slash so Parent("k:\foo") is "k:\" not "k :" */
- *(tp+1) = 0;
+ *(tp + 1) = 0;
rc = 1;
- }
- else {
- if (client_ExtractDriveLetter(parentDirectory)) {
+ } else {
+ if (client_ExtractDriveLetter(parentDirectory)) {
strcat(parentDirectory, ".");
rc = 1;
}
/*
* Determine the parent directory of a give directory
*/
-static int Parent(
- const char *directory,
- char *parentDirectory)
+static int
+Parent(const char *directory, char *parentDirectory)
{
char *tp;
int rc = 0;
strcpy(parentDirectory, directory);
- tp = rindex(parentDirectory, '/');
+ tp = strrchr(parentDirectory, '/');
if (tp) {
- *tp = 0;
+ *tp = 0;
rc = 1;
- }
- else {
+ } else {
strcpy(parentDirectory, ".");
rc = 1;
}
#define TMP_DATA_SIZE 2048
-int ADMINAPI afsclient_MountPointCreate(
- const void *cellHandle,
- const char *directory,
- const char *volumeName,
- vol_type_t volType,
- vol_check_t volCheck,
- afs_status_p st)
+int ADMINAPI
+afsclient_MountPointCreate(const void *cellHandle, const char *directory,
+ const char *volumeName, vol_type_t volType,
+ vol_check_t volCheck, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
struct ViceIoctl idata;
int i;
vos_vldbEntry_t vldbEntry;
-
+
/*
* Validate arguments
*/
}
if ((directory == NULL) || (*directory == 0)) {
- tst = ADMCLIENTDIRECTORYNULL;
- goto fail_afsclient_MountPointCreate;
+ tst = ADMCLIENTDIRECTORYNULL;
+ goto fail_afsclient_MountPointCreate;
}
if ((volumeName == NULL) || (*volumeName == 0)) {
- tst = ADMCLIENTVOLUMENAME;
- goto fail_afsclient_MountPointCreate;
+ tst = ADMCLIENTVOLUMENAME;
+ goto fail_afsclient_MountPointCreate;
}
/*
if (!Parent(directory, parent_dir)) {
tst = ADMCLIENTBADDIRECTORY;
- goto fail_afsclient_MountPointCreate;
+ goto fail_afsclient_MountPointCreate;
}
idata.in_size = 0;
if (i) {
if ((errno == EINVAL) || (errno == ENOENT)) {
tst = ADMCLIENTNOAFSDIRECTORY;
- goto fail_afsclient_MountPointCreate;
+ goto fail_afsclient_MountPointCreate;
}
}
strcpy(directoryCell, space);
*/
if (volCheck == CHECK_VOLUME) {
- if (!vos_VLDBGet(cellHandle, 0, 0, volumeName, &vldbEntry, &tst)) {
+ if (!vos_VLDBGet(cellHandle, 0, 0, (char *)volumeName, &vldbEntry,
+ &tst)) {
goto fail_afsclient_MountPointCreate;
}
}
goto fail_afsclient_MountPointCreate;
}
#else
- if (tst = symlink(space, directory)) {
+ if ((tst = symlink(space, directory))) {
goto fail_afsclient_MountPointCreate;
}
#endif
rc = 1;
-
-fail_afsclient_MountPointCreate:
+
+ fail_afsclient_MountPointCreate:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
int nminus;
} Acl_t, *Acl_p;
-int ADMINAPI afsclient_ACLEntryAdd(
- const char *directory,
- const char *user,
- const acl_p acl,
- afs_status_p st)
+int ADMINAPI
+afsclient_ACLEntryAdd(const char *directory, const char *user,
+ const acl_p acl, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
char *ptr;
Acl_t cur_acl;
char cur_user[64];
- int cur_user_acl;
+ int cur_user_acl = 0;
int i;
- char tmp[64+35];
+ char tmp[64 + 35];
int is_dfs;
-
+
if (client_init == 0) {
tst = ADMCLIENTNOINIT;
goto fail_afsclient_ACLEntryAdd;
idata.out_size = 2048;
idata.in_size = 0;
idata.in = idata.out = old_acl_string;
- tst = pioctl(directory, VIOCGETAL, &idata, 1);
+ tst = pioctl((char *)directory, VIOCGETAL, &idata, 1);
if (tst != 0) {
goto fail_afsclient_ACLEntryAdd;
* file.
*/
- is_dfs = sscanf(old_acl_string, "%d dfs:%d %s", &cur_acl.nplus, &cur_acl.dfs, &cur_acl.cell);
+ is_dfs =
+ sscanf(old_acl_string, "%d dfs:%d %s", &cur_acl.nplus, &cur_acl.dfs,
+ cur_acl.cell);
ptr = strchr(old_acl_string, '\n');
ptr++;
sscanf(ptr, "%d", &cur_acl.nminus);
* adding a space in the new acl.
*/
- for(i=0;i<(cur_acl.nplus + cur_acl.nminus);i++) {
- sscanf(ptr, "%s%d\n", &cur_user, &cur_user_acl);
+ for (i = 0; i < (cur_acl.nplus + cur_acl.nminus); i++) {
+ sscanf(ptr, "%s%d\n", cur_user, &cur_user_acl);
/*
* Skip the entry for the user we are replacing/adding
*/
idata.out_size = 0;
idata.in_size = strlen(new_acl_string) + 1;
idata.in = idata.out = new_acl_string;
- tst = pioctl(directory, VIOCSETAL, &idata, 1);
+ tst = pioctl((char *) directory, VIOCSETAL, &idata, 1);
if (tst != 0) {
goto fail_afsclient_ACLEntryAdd;
}
rc = 1;
-fail_afsclient_ACLEntryAdd:
+ fail_afsclient_ACLEntryAdd:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_Init(
- afs_status_p st)
+int ADMINAPI
+afsclient_Init(afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
-
- (client_init || pthread_once(&client_init_once, client_once));
+
+ if (!client_init)
+ pthread_once(&client_init_once, client_once);
#ifdef AFS_NT40_ENV
if (afs_winsockInit() < 0) {
goto fail_afsclient_Init;
}
- if (tst = ka_CellConfig((char *)AFSDIR_CLIENT_ETC_DIRPATH)) {
+ if ((tst = ka_CellConfig((char *)AFSDIR_CLIENT_ETC_DIRPATH))) {
goto fail_afsclient_Init;
}
rc = 1;
-fail_afsclient_Init:
+ fail_afsclient_Init:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_AFSServerGet(
- const void *cellHandle,
- const char *serverName,
- afs_serverEntry_p serverEntryP,
- afs_status_p st)
+int ADMINAPI
+afsclient_AFSServerGet(const void *cellHandle, const char *serverName,
+ afs_serverEntry_p serverEntryP, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
void *iter;
int found_match = 0;
-
+
if ((serverName == NULL) || (*serverName == 0)) {
tst = ADMUTILSERVERNAMENULL;
goto fail_afsclient_AFSServerGet;
goto fail_afsclient_AFSServerGet;
}
- while(afsclient_AFSServerGetNext(iter, serverEntryP, &tst)) {
+ while (afsclient_AFSServerGetNext(iter, serverEntryP, &tst)) {
if (!strcmp(serverName, serverEntryP->serverName)) {
found_match = 1;
break;
}
rc = 1;
-fail_afsclient_AFSServerGet:
+ fail_afsclient_AFSServerGet:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
afs_serverEntry_t cache[CACHED_ITEMS];
} server_get_t, *server_get_p;
-static int GetServerRPC(
- void *rpc_specific,
- int slot,
- int *last_item,
- int *last_item_contains_data,
- afs_status_p st)
+static int
+GetServerRPC(void *rpc_specific, int slot, int *last_item,
+ int *last_item_contains_data, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
server_get_p serv = (server_get_p) rpc_specific;
-
+
memcpy(&serv->cache[slot], &serv->server[serv->index],
sizeof(afs_serverEntry_t));
-
+
serv->index++;
if (serv->index == serv->total) {
- *last_item = 1;
- *last_item_contains_data = 1;
+ *last_item = 1;
+ *last_item_contains_data = 1;
}
rc = 1;
-
-fail_GetServerRPC:
-
+
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
-static int GetServerFromCache(
- void *rpc_specific,
- int slot,
- void *dest,
- afs_status_p st)
+static int
+GetServerFromCache(void *rpc_specific, int slot, void *dest, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
server_get_p serv = (server_get_p) rpc_specific;
-
- memcpy(dest, (const void *) &serv->cache[slot], sizeof(afs_serverEntry_t));
+
+ memcpy(dest, (const void *)&serv->cache[slot], sizeof(afs_serverEntry_t));
rc = 1;
-
+
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
*
* Returns != 0 upon successful completion.
*/
-
-int ADMINAPI afsclient_AFSServerGetBegin(
- const void *cellHandle,
- void **iterationIdP,
- afs_status_p st)
+
+int ADMINAPI
+afsclient_AFSServerGetBegin(const void *cellHandle, void **iterationIdP,
+ afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
- afs_admin_iterator_p iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
- server_get_p serv = (server_get_p) calloc(1, sizeof(server_get_t));
- const char *cellName;
+ afs_admin_iterator_p iter =
+ (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
+ server_get_p serv = calloc(1, sizeof(server_get_t));
+ server_get_p serv_cache = NULL;
+ const char *cellName = NULL;
void *database_iter;
util_databaseServerEntry_t database_entry;
void *fileserver_iter;
vos_fileServerEntry_t fileserver_entry;
- int iserv,iservaddr,ientryaddr, is_dup;
+ int iserv, iservaddr, ientryaddr, is_dup;
struct hostent *host;
-
+
if (!CellHandleIsValid(c_handle, &tst)) {
goto fail_afsclient_AFSServerGetBegin;
}
goto fail_afsclient_AFSServerGetBegin;
}
- /*
- * Retrieve the list of database servers for this cell.
- */
-
- if (!afsclient_CellNameGet(cellHandle, &cellName, &tst)) {
- goto fail_afsclient_AFSServerGetBegin;
+ restart:
+ LOCK_GLOBAL_MUTEX;
+ if (c_handle->server_list != NULL && c_handle->server_ttl < time(NULL)) {
+ serv_cache = c_handle->server_list;
+ c_handle->server_list = NULL;
}
+ UNLOCK_GLOBAL_MUTEX;
- if (!util_DatabaseServerGetBegin(cellName, &database_iter, &tst)) {
- goto fail_afsclient_AFSServerGetBegin;
- }
+ if (c_handle->server_list == NULL) {
+ if (serv_cache == NULL) {
+ serv_cache = (server_get_p) calloc(1, sizeof(server_get_t));
- while(util_DatabaseServerGetNext(database_iter, &database_entry, &tst)) {
- serv->server[serv->total].serverAddress[0] = database_entry.serverAddress;
- serv->server[serv->total].serverType = DATABASE_SERVER;
- serv->total++;
- }
+ if (serv_cache == NULL) {
+ tst = ADMNOMEM;
+ goto fail_afsclient_AFSServerGetBegin;
+ }
+ }
- if (tst != ADMITERATORDONE) {
- util_DatabaseServerGetDone(database_iter, 0);
- goto fail_afsclient_AFSServerGetBegin;
- }
+ /*
+ * Retrieve the list of database servers for this cell.
+ */
- if (!util_DatabaseServerGetDone(database_iter, &tst)) {
- goto fail_afsclient_AFSServerGetBegin;
- }
+ if (!afsclient_CellNameGet(c_handle, &cellName, &tst)) {
+ goto fail_afsclient_AFSServerGetBegin;
+ }
- /*
- * Retrieve the list of file servers for this cell.
- */
+ if (!util_DatabaseServerGetBegin(cellName, &database_iter, &tst)) {
+ goto fail_afsclient_AFSServerGetBegin;
+ }
- if (!vos_FileServerGetBegin(cellHandle, 0, &fileserver_iter, &tst)) {
- goto fail_afsclient_AFSServerGetBegin;
- }
+ while (util_DatabaseServerGetNext(database_iter, &database_entry, &tst)) {
+ serv->server[serv->total].serverAddress[0] =
+ database_entry.serverAddress;
+ serv->server[serv->total].serverType = DATABASE_SERVER;
+ serv->total++;
+ }
+
+ if (tst != ADMITERATORDONE) {
+ util_DatabaseServerGetDone(database_iter, 0);
+ goto fail_afsclient_AFSServerGetBegin;
+ }
+
+ if (!util_DatabaseServerGetDone(database_iter, &tst)) {
+ goto fail_afsclient_AFSServerGetBegin;
+ }
- while(vos_FileServerGetNext(fileserver_iter, &fileserver_entry, &tst)) {
/*
- * See if any of the addresses returned in this fileserver_entry
- * structure already exist in the list of servers we're building.
- * If not, create a new record for this server.
+ * Retrieve the list of file servers for this cell.
*/
- is_dup = 0;
- for(iserv=0;iserv<serv->total;iserv++) {
- for(ientryaddr=0; ientryaddr<fileserver_entry.count; ientryaddr++) {
- for(iservaddr=0;iservaddr<AFS_MAX_SERVER_ADDRESS;iservaddr++) {
- if (serv->server[iserv].serverAddress[iservaddr] ==
- fileserver_entry.serverAddress[ientryaddr]) {
- is_dup = 1;
+
+ if (!vos_FileServerGetBegin(c_handle, 0, &fileserver_iter, &tst)) {
+ goto fail_afsclient_AFSServerGetBegin;
+ }
+
+ while (vos_FileServerGetNext(fileserver_iter, &fileserver_entry, &tst)) {
+ /*
+ * See if any of the addresses returned in this fileserver_entry
+ * structure already exist in the list of servers we're building.
+ * If not, create a new record for this server.
+ */
+ is_dup = 0;
+ for (iserv = 0; iserv < serv->total; iserv++) {
+ for (ientryaddr = 0; ientryaddr < fileserver_entry.count; ientryaddr++) {
+ for (iservaddr = 0; iservaddr < AFS_MAX_SERVER_ADDRESS; iservaddr++) {
+ if (serv->server[iserv].serverAddress[iservaddr] ==
+ fileserver_entry.serverAddress[ientryaddr]) {
+ is_dup = 1;
+ break;
+ }
+ }
+ if (is_dup) {
break;
}
}
break;
}
}
+
if (is_dup) {
- break;
+ serv->server[iserv].serverType |= FILE_SERVER;
+ } else {
+ iserv = serv->total++;
+ serv->server[iserv].serverType = FILE_SERVER;
}
- }
-
- if (is_dup) {
- serv->server[iserv].serverType |= FILE_SERVER;
- } else {
- iserv = serv->total++;
- serv->server[iserv].serverType = FILE_SERVER;
- }
- /*
- * Add the addresses from the vldb list to the serv->server[iserv]
- * record. Remember that VLDB's list-of-addrs is not guaranteed
- * to be unique in a particular entry, or to return only one entry
- * per machine--so when we add addresses, always check for
- * duplicate entries.
- */
+ /*
+ * Add the addresses from the vldb list to the serv->server[iserv]
+ * record. Remember that VLDB's list-of-addrs is not guaranteed
+ * to be unique in a particular entry, or to return only one entry
+ * per machine--so when we add addresses, always check for
+ * duplicate entries.
+ */
- for(ientryaddr=0;ientryaddr<fileserver_entry.count;ientryaddr++) {
- for(iservaddr=0;iservaddr<AFS_MAX_SERVER_ADDRESS;iservaddr++) {
- if (serv->server[iserv].serverAddress[iservaddr] ==
- fileserver_entry.serverAddress[ientryaddr]) {
- break;
- }
- }
- if (iservaddr == AFS_MAX_SERVER_ADDRESS) {
- for(iservaddr=0;iservaddr<AFS_MAX_SERVER_ADDRESS;iservaddr++) {
- if (!serv->server[iserv].serverAddress[iservaddr]) {
- serv->server[iserv].serverAddress[iservaddr] =
- fileserver_entry.serverAddress[ientryaddr];
+ for (ientryaddr = 0; ientryaddr < fileserver_entry.count; ientryaddr++) {
+ for (iservaddr = 0; iservaddr < AFS_MAX_SERVER_ADDRESS; iservaddr++) {
+ if (serv->server[iserv].serverAddress[iservaddr] ==
+ fileserver_entry.serverAddress[ientryaddr]) {
break;
}
}
+ if (iservaddr == AFS_MAX_SERVER_ADDRESS) {
+ for (iservaddr = 0; iservaddr < AFS_MAX_SERVER_ADDRESS;
+ iservaddr++) {
+ if (!serv->server[iserv].serverAddress[iservaddr]) {
+ serv->server[iserv].serverAddress[iservaddr] =
+ fileserver_entry.serverAddress[ientryaddr];
+ break;
+ }
+ }
+ }
}
}
- }
- if (tst != ADMITERATORDONE) {
- vos_FileServerGetDone(fileserver_iter, 0);
- goto fail_afsclient_AFSServerGetBegin;
- }
+ if (tst != ADMITERATORDONE) {
+ vos_FileServerGetDone(fileserver_iter, 0);
+ goto fail_afsclient_AFSServerGetBegin;
+ }
- if (!vos_FileServerGetDone(fileserver_iter, &tst)) {
- goto fail_afsclient_AFSServerGetBegin;
- }
+ if (!vos_FileServerGetDone(fileserver_iter, &tst)) {
+ goto fail_afsclient_AFSServerGetBegin;
+ }
- /*
- * Iterate over the list and fill in the hostname of each of the servers
- */
+ /*
+ * Iterate over the list and fill in the hostname of each of the servers
+ */
- LOCK_GLOBAL_MUTEX
- for(iserv=0;iserv<serv->total;iserv++) {
- int addr = htonl(serv->server[iserv].serverAddress[0]);
- host = gethostbyaddr((const char *) &addr, sizeof(int), AF_INET);
- if (host != NULL) {
- strncpy(serv->server[iserv].serverName, host->h_name,
- AFS_MAX_SERVER_NAME_LEN);
+ for (iserv = 0; iserv < serv->total; iserv++) {
+ int addr = htonl(serv->server[iserv].serverAddress[0]);
+ LOCK_GLOBAL_MUTEX;
+ host = gethostbyaddr((const char *)&addr, sizeof(int), AF_INET);
+ if (host != NULL) {
+ strncpy(serv->server[iserv].serverName, host->h_name,
+ AFS_MAX_SERVER_NAME_LEN);
+ serv->server[iserv].serverName[AFS_MAX_SERVER_NAME_LEN - 1] = '\0';
+ }
+ UNLOCK_GLOBAL_MUTEX;
}
- }
- UNLOCK_GLOBAL_MUTEX
-
- if (IteratorInit(iter, (void *) serv, GetServerRPC, GetServerFromCache,
- NULL, NULL, &tst)) {
- *iterationIdP = (void *) iter;
+
+ memcpy(serv_cache, serv, sizeof(server_get_t));
+ } else {
+ int race = 0;
+ LOCK_GLOBAL_MUTEX;
+ if (c_handle->server_list == NULL)
+ race = 1;
+ else
+ memcpy(serv, c_handle->server_list, sizeof(server_get_t));
+ UNLOCK_GLOBAL_MUTEX;
+ if (race)
+ goto restart;
+ }
+
+ if (IteratorInit
+ (iter, (void *)serv, GetServerRPC, GetServerFromCache, NULL, NULL,
+ &tst)) {
+ *iterationIdP = (void *)iter;
rc = 1;
}
-fail_afsclient_AFSServerGetBegin:
+ fail_afsclient_AFSServerGetBegin:
if (rc == 0) {
- if (iter != NULL) {
+ if (iter != NULL)
free(iter);
- }
- if (serv != NULL) {
+ if (serv != NULL)
free(serv);
+ if (serv_cache != NULL)
+ free(serv_cache);
+ } else {
+ if (serv_cache) {
+ LOCK_GLOBAL_MUTEX;
+ /* in case there was a race and we constructed the list twice */
+ if (c_handle->server_list)
+ free(c_handle->server_list);
+
+ c_handle->server_list = serv_cache;
+ c_handle->server_ttl = time(NULL) + SERVER_TTL;
+ UNLOCK_GLOBAL_MUTEX;
}
}
- if (st != NULL) {
- *st = tst;
- }
+ if (st != NULL)
+ *st = tst;
+
return rc;
}
*
* Returns != 0 upon successful completion.
*/
-
-int ADMINAPI afsclient_AFSServerGetNext(
- void *iterationId,
- afs_serverEntry_p serverEntryP,
- afs_status_p st)
+
+int ADMINAPI
+afsclient_AFSServerGetNext(void *iterationId, afs_serverEntry_p serverEntryP,
+ afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
goto fail_afsclient_AFSServerGetNext;
}
- rc = IteratorNext(iter, (void *) serverEntryP, &tst);
+ rc = IteratorNext(iter, (void *)serverEntryP, &tst);
-fail_afsclient_AFSServerGetNext:
+ fail_afsclient_AFSServerGetNext:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
*
* Returns != 0 upon successful completion.
*/
-
-int ADMINAPI afsclient_AFSServerGetDone(
- void *iterationId,
- afs_status_p st)
+
+int ADMINAPI
+afsclient_AFSServerGetDone(void *iterationId, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
-
+
if (iterationId == NULL) {
tst = ADMITERATORNULL;
goto fail_afsclient_AFSServerGetDone;
rc = IteratorDone(iter, &tst);
-fail_afsclient_AFSServerGetDone:
+ fail_afsclient_AFSServerGetDone:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_RPCStatOpen(
- const void *cellHandle,
- const char *serverName,
- afs_stat_source_t type,
- struct rx_connection **rpcStatHandleP,
- afs_status_p st)
+int ADMINAPI
+afsclient_RPCStatOpen(const void *cellHandle, const char *serverName,
+ afs_stat_source_t type,
+ struct rx_connection **rpcStatHandleP, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
goto fail_afsclient_RPCStatOpen;
}
- switch(type) {
+ switch (type) {
- case AFS_BOSSERVER:
+ case AFS_BOSSERVER:
servPort = AFSCONF_NANNYPORT;
break;
- case AFS_FILESERVER:
+ case AFS_FILESERVER:
servPort = AFSCONF_FILEPORT;
break;
- case AFS_KASERVER:
+ case AFS_KASERVER:
servPort = AFSCONF_KAUTHPORT;
break;
- case AFS_PTSERVER:
+ case AFS_PTSERVER:
servPort = AFSCONF_PROTPORT;
break;
- case AFS_VOLSERVER:
+ case AFS_VOLSERVER:
servPort = AFSCONF_VOLUMEPORT;
break;
- case AFS_VLSERVER:
+ case AFS_VLSERVER:
servPort = AFSCONF_VLDBPORT;
break;
- case AFS_CLIENT:
+ case AFS_CLIENT:
servPort = AFSCONF_CALLBACKPORT;
break;
- default:
+ default:
tst = ADMTYPEINVALID;
goto fail_afsclient_RPCStatOpen;
}
sc = c_handle->tokens->afs_sc[c_handle->tokens->sc_index];
}
- *rpcStatHandleP = rx_GetCachedConnection(htonl(servAddr),
- htons(servPort),
- RX_STATS_SERVICE_ID,
- sc,
- c_handle->tokens->sc_index);
+ *rpcStatHandleP =
+ rx_GetCachedConnection(htonl(servAddr), htons(servPort),
+ RX_STATS_SERVICE_ID, sc,
+ c_handle->tokens->sc_index);
if (*rpcStatHandleP == NULL) {
tst = ADMCLIENTRPCSTATNOCONNECTION;
}
rc = 1;
-fail_afsclient_RPCStatOpen:
+ fail_afsclient_RPCStatOpen:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_RPCStatOpenPort(
- const void *cellHandle,
- const char *serverName,
- const int serverPort,
- struct rx_connection **rpcStatHandleP,
- afs_status_p st)
+int ADMINAPI
+afsclient_RPCStatOpenPort(const void *cellHandle, const char *serverName,
+ const int serverPort,
+ struct rx_connection **rpcStatHandleP,
+ afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
sc = c_handle->tokens->afs_sc[c_handle->tokens->sc_index];
}
- *rpcStatHandleP = rx_GetCachedConnection(htonl(servAddr),
- htons(serverPort),
- RX_STATS_SERVICE_ID,
- sc,
- c_handle->tokens->sc_index);
+ *rpcStatHandleP =
+ rx_GetCachedConnection(htonl(servAddr), htons(serverPort),
+ RX_STATS_SERVICE_ID, sc,
+ c_handle->tokens->sc_index);
if (*rpcStatHandleP == NULL) {
tst = ADMCLIENTRPCSTATNOCONNECTION;
}
rc = 1;
-fail_afsclient_RPCStatOpenPort:
+ fail_afsclient_RPCStatOpenPort:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_RPCStatClose(
- struct rx_connection *rpcStatHandle,
- afs_status_p st)
+int ADMINAPI
+afsclient_RPCStatClose(struct rx_connection *rpcStatHandle, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
rx_ReleaseCachedConnection(rpcStatHandle);
rc = 1;
-fail_afsclient_RPCStatClose:
+ fail_afsclient_RPCStatClose:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_CMStatOpen(
- const void *cellHandle,
- const char *serverName,
- struct rx_connection **cmStatHandleP,
- afs_status_p st)
+int ADMINAPI
+afsclient_CMStatOpen(const void *cellHandle, const char *serverName,
+ struct rx_connection **cmStatHandleP, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
sc = c_handle->tokens->afs_sc[c_handle->tokens->sc_index];
- *cmStatHandleP = rx_GetCachedConnection(htonl(servAddr),
- htons(AFSCONF_CALLBACKPORT),
- 1,
- sc,
- c_handle->tokens->sc_index);
+ *cmStatHandleP =
+ rx_GetCachedConnection(htonl(servAddr), htons(AFSCONF_CALLBACKPORT),
+ 1, sc, c_handle->tokens->sc_index);
if (*cmStatHandleP == NULL) {
tst = ADMCLIENTCMSTATNOCONNECTION;
}
rc = 1;
-fail_afsclient_CMStatOpen:
+ fail_afsclient_CMStatOpen:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_CMStatOpenPort(
- const void *cellHandle,
- const char *serverName,
- const int serverPort,
- struct rx_connection **cmStatHandleP,
- afs_status_p st)
+int ADMINAPI
+afsclient_CMStatOpenPort(const void *cellHandle, const char *serverName,
+ const int serverPort,
+ struct rx_connection **cmStatHandleP,
+ afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
sc = c_handle->tokens->afs_sc[c_handle->tokens->sc_index];
- *cmStatHandleP = rx_GetCachedConnection(htonl(servAddr),
- htons(serverPort),
- 1,
- sc,
- c_handle->tokens->sc_index);
+ *cmStatHandleP =
+ rx_GetCachedConnection(htonl(servAddr), htons(serverPort), 1, sc,
+ c_handle->tokens->sc_index);
if (*cmStatHandleP == NULL) {
tst = ADMCLIENTCMSTATNOCONNECTION;
}
rc = 1;
-fail_afsclient_CMStatOpenPort:
+ fail_afsclient_CMStatOpenPort:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_CMStatClose(
- struct rx_connection *cmStatHandle,
- afs_status_p st)
+int ADMINAPI
+afsclient_CMStatClose(struct rx_connection *cmStatHandle, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
rx_ReleaseCachedConnection(cmStatHandle);
rc = 1;
-fail_afsclient_CMStatClose:
+ fail_afsclient_CMStatClose:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_RXDebugOpen(
- const char *serverName,
- afs_stat_source_t type,
- rxdebugHandle_p *rxdebugHandleP,
- afs_status_p st)
+int ADMINAPI
+afsclient_RXDebugOpen(const char *serverName, afs_stat_source_t type,
+ rxdebugHandle_p * rxdebugHandleP, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
goto fail_afsclient_RXDebugOpen;
}
- switch(type) {
+ switch (type) {
- case AFS_BOSSERVER:
+ case AFS_BOSSERVER:
serverPort = AFSCONF_NANNYPORT;
break;
- case AFS_FILESERVER:
+ case AFS_FILESERVER:
serverPort = AFSCONF_FILEPORT;
break;
- case AFS_KASERVER:
+ case AFS_KASERVER:
serverPort = AFSCONF_KAUTHPORT;
break;
- case AFS_PTSERVER:
+ case AFS_PTSERVER:
serverPort = AFSCONF_PROTPORT;
break;
- case AFS_VOLSERVER:
+ case AFS_VOLSERVER:
serverPort = AFSCONF_VOLUMEPORT;
break;
- case AFS_VLSERVER:
+ case AFS_VLSERVER:
serverPort = AFSCONF_VLDBPORT;
break;
- case AFS_CLIENT:
+ case AFS_CLIENT:
serverPort = AFSCONF_CALLBACKPORT;
break;
- default:
+ default:
tst = ADMTYPEINVALID;
goto fail_afsclient_RXDebugOpen;
}
if (!util_AdminServerAddressGetFromName(serverName, &serverAddr, &tst)) {
- goto fail_afsclient_RXDebugOpen;
+ goto fail_afsclient_RXDebugOpen;
}
- sock = (rxdebugSocket_t)socket(AF_INET, SOCK_DGRAM, 0);
+ sock = (rxdebugSocket_t) socket(AF_INET, SOCK_DGRAM, 0);
if (sock == INVALID_RXDEBUG_SOCKET) {
tst = ADMSOCKFAIL;
goto fail_afsclient_RXDebugOpen;
goto fail_afsclient_RXDebugOpen;
}
- handle = (rxdebugHandle_p)malloc(sizeof(rxdebugHandle_t));
+ handle = (rxdebugHandle_p) malloc(sizeof(rxdebugHandle_t));
if (!handle) {
close(sock);
tst = ADMNOMEM;
*rxdebugHandleP = handle;
rc = 1;
-fail_afsclient_RXDebugOpen:
+ fail_afsclient_RXDebugOpen:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_RXDebugOpenPort(
- const char *serverName,
- int serverPort,
- rxdebugHandle_p *rxdebugHandleP,
- afs_status_p st)
+int ADMINAPI
+afsclient_RXDebugOpenPort(const char *serverName, int serverPort,
+ rxdebugHandle_p * rxdebugHandleP, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
}
if (!util_AdminServerAddressGetFromName(serverName, &serverAddr, &tst)) {
- goto fail_afsclient_RXDebugOpenPort;
+ goto fail_afsclient_RXDebugOpenPort;
}
- sock = (rxdebugSocket_t)socket(AF_INET, SOCK_DGRAM, 0);
+ sock = (rxdebugSocket_t) socket(AF_INET, SOCK_DGRAM, 0);
if (sock == INVALID_RXDEBUG_SOCKET) {
tst = ADMSOCKFAIL;
goto fail_afsclient_RXDebugOpenPort;
goto fail_afsclient_RXDebugOpenPort;
}
- handle = (rxdebugHandle_p)malloc(sizeof(rxdebugHandle_t));
+ handle = (rxdebugHandle_p) malloc(sizeof(rxdebugHandle_t));
if (!handle) {
close(sock);
tst = ADMNOMEM;
*rxdebugHandleP = handle;
rc = 1;
-fail_afsclient_RXDebugOpenPort:
+ fail_afsclient_RXDebugOpenPort:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}
* Returns != 0 upon successful completion.
*/
-int ADMINAPI afsclient_RXDebugClose(
- rxdebugHandle_p rxdebugHandle,
- afs_status_p st)
+int ADMINAPI
+afsclient_RXDebugClose(rxdebugHandle_p rxdebugHandle, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
close(rxdebugHandle->sock);
free(rxdebugHandle);
rc = 1;
-fail_afsclient_RXDebugClose:
+ fail_afsclient_RXDebugClose:
if (st != NULL) {
- *st = tst;
+ *st = tst;
}
return rc;
}