/*! * \brief Get the appropriate type of ubik client structure out from the system. */ afs_int32 ugen_ClientInit(int noAuthFlag, const char *confDir, char *cellName, afs_int32 sauth, struct ubik_client **uclientp, int (*secproc) (struct rx_securityClass *, afs_int32), char *funcName, afs_int32 gen_rxkad_level, afs_int32 maxservers, char *serviceid, afs_int32 deadtime, afs_uint32 server, afs_uint32 port, afs_int32 usrvid) { afs_int32 code, secFlags, i; afs_int32 scIndex; struct afsconf_cell info; struct afsconf_dir *tdir; struct rx_securityClass *sc; /* This must change if VLDB_MAXSERVERS becomes larger than MAXSERVERS */ static struct rx_connection *serverconns[MAXSERVERS]; code = rx_Init(0); if (code) { fprintf(stderr, "%s: could not initialize rx.\n", funcName); return code; } rx_SetRxDeadTime(deadtime); secFlags = AFSCONF_SECOPTS_FALLBACK_NULL; if (sauth) { secFlags |= AFSCONF_SECOPTS_LOCALAUTH; confDir = AFSDIR_SERVER_ETC_DIRPATH; } else { if (confDir == NULL) confDir = AFSDIR_CLIENT_ETC_DIRPATH; } if (noAuthFlag) { secFlags |= AFSCONF_SECOPTS_NOAUTH; } tdir = afsconf_Open(confDir); if (!tdir) { fprintf(stderr, "%s: Could not process files in configuration directory (%s).\n", funcName, confDir); return -1; } if (sauth) cellName = tdir->cellName; code = afsconf_GetCellInfo(tdir, cellName, serviceid, &info); if (code) { afsconf_Close(tdir); fprintf(stderr, "%s: can't find cell %s's hosts in %s/%s\n", funcName, cellName, confDir, AFSDIR_CELLSERVDB_FILE); return -1; } code = afsconf_PickClientSecObj(tdir, secFlags, &info, cellName, &sc, &scIndex, NULL); if (code) { fprintf(stderr, "%s: can't create client security object", funcName); return -1; } if (scIndex == RX_SECIDX_NULL && !noAuthFlag) { fprintf(stderr, "%s: Could not get afs tokens, running unauthenticated.\n", funcName); } afsconf_Close(tdir); if (secproc) /* tell UV module about default authentication */ (*secproc) (sc, scIndex); if (server) { serverconns[0] = rx_NewConnection(server, port, usrvid, sc, scIndex); } else { if (info.numServers > maxservers) { fprintf(stderr, "%s: info.numServers=%d (> maxservers=%d)\n", funcName, info.numServers, maxservers); return -1; } for (i = 0; i < info.numServers; i++) { if (!info.hostAddr[i].sin_port && port) info.hostAddr[i].sin_port = port; serverconns[i] = rx_NewConnection(info.hostAddr[i].sin_addr.s_addr, info.hostAddr[i].sin_port, usrvid, sc, scIndex); } } /* Are we just setting up connections, or is this really ubik stuff? */ if (uclientp) { *uclientp = 0; code = ubik_ClientInit(serverconns, uclientp); if (code) { fprintf(stderr, "%s: ubik client init failed.\n", funcName); return code; } } return 0; }
static afs_int32 InitThisModule(int a_noAuthFlag, char *a_confDir, char *a_cellName) { /*InitThisModule */ #ifdef USS_VOL_DB static char rn[] = "uss_vol:InitThisModule"; #endif afs_int32 code; /*Return code */ struct afsconf_dir *tdir; /*Ptr to conf dir info */ struct afsconf_cell info; /*Info about chosen cell */ afs_int32 scIndex; /*Chosen security index */ afs_int32 secFlags; struct rx_securityClass *sc; /*Generated security object */ afs_int32 i; /*Loop index */ /* * Only once, guys, will 'ya? */ if (initDone) { #ifdef USS_VOL_DB printf("[%s] Called multiple times!\n", rn); #endif /* USS_VOL_DB */ return (0); } /* * Set up our Rx environment. */ #ifdef USS_VOL_DB printf("[%s] Initializing Rx environment\n", rn); #endif /* USS_VOL_DB */ code = rx_Init(0); if (code) { fprintf(stderr, "%s: Couldn't initialize Rx.\n", uss_whoami); return (code); } rx_SetRxDeadTime(50); /* * Find out all about our configuration. */ #ifdef USS_VOL_DB printf("[%s] Handling configuration info\n", rn); #endif /* USS_VOL_DB */ tdir = afsconf_Open(a_confDir); if (!tdir) { fprintf(stderr, "%s: Couldn't open configuration directory (%s).\n", uss_whoami, a_confDir); return (-1); } code = afsconf_GetCellInfo(tdir, a_cellName, AFSCONF_VLDBSERVICE, &info); if (code) { printf("%s: Can't find VLDB server(s) for cell %s\n", uss_whoami, a_cellName); exit(1); } #ifdef USS_VOL_DB printf("[%s] Getting tickets if needed\n", rn); #endif /* USS_VOL_DB */ secFlags = AFSCONF_SECOPTS_FALLBACK_NULL; if (a_noAuthFlag) secFlags |= AFSCONF_SECOPTS_NOAUTH; code = afsconf_PickClientSecObj(tdir, secFlags, &info, a_cellName, &sc, &scIndex, NULL); if (code) { printf("%s: Can't create client security object\n", uss_whoami); exit(1); } if (scIndex == RX_SECIDX_NULL && !a_noAuthFlag) { fprintf(stderr, "%s: Couldn't get AFS tokens, running unauthenticated.\n", uss_whoami); } /* * Tell UV module about default authentication. */ #ifdef USS_VOL_DB printf("[%s] Setting UV security: obj 0x%x, index %d\n", rn, sc, scIndex); #endif /* USS_VOL_DB */ UV_SetSecurity(sc, scIndex); if (info.numServers > VLDB_MAXSERVERS) { fprintf(stderr, "%s: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n", uss_whoami, info.numServers, VLDB_MAXSERVERS); exit(1); } /* * Connect to each VLDB server for the chosen cell. */ for (i = 0; i < info.numServers; i++) { #ifdef USS_VOL_DB printf ("[%s] Connecting to VLDB server 0x%x, port %d, service id %d\n", rn, info.hostAddr[i].sin_addr.s_addr, info.hostAddr[i].sin_port, USER_SERVICE_ID); #endif /* USS_VOL_DB */ serverconns[i] = rx_NewConnection(info.hostAddr[i].sin_addr.s_addr, info.hostAddr[i].sin_port, USER_SERVICE_ID, sc, scIndex); } /* * Set up to execute Ubik transactions on the VLDB. */ #ifdef USS_VOL_DB printf("[%s] Initializing Ubik interface\n", rn); #endif /* USS_VOL_DB */ code = ubik_ClientInit(serverconns, &uconn_vldbP); if (code) { fprintf(stderr, "%s: Ubik client init failed.\n", uss_whoami); return (code); } #ifdef USS_VOL_DB printf("[%s] VLDB ubik connection structure at 0x%x\n", rn, uconn_vldbP); #endif /* USS_VOL_DB */ /* * Place the ubik VLDB connection structure in its advertised * location. */ cstruct = uconn_vldbP; /* * Success! */ initDone = 1; return (0); } /*InitThisModule */
/* vldbClientInit * Initialize a client for the vl ubik database. */ int vldbClientInit(int noAuthFlag, int localauth, char *cellName, struct ubik_client **cstruct, time_t *expires) { afs_int32 code = 0; struct afsconf_dir *acdir; struct rx_securityClass *sc; afs_int32 i, scIndex = RX_SECIDX_NULL; struct afsconf_cell info; struct rx_connection *serverconns[VLDB_MAXSERVERS]; afsconf_secflags secFlags; const char *confdir; secFlags = parseSecFlags(noAuthFlag, localauth, &confdir); secFlags |= AFSCONF_SECOPTS_FALLBACK_NULL; /* This just preserves old behaviour of using the default cell when * passed an empty string */ if (cellName && cellName[0] == '\0') cellName = NULL; /* Find out about the given cell */ acdir = afsconf_Open(confdir); if (!acdir) { afs_com_err(whoami, 0, "Can't open configuration directory '%s'", confdir); ERROR(BC_NOCELLCONFIG); } code = afsconf_GetCellInfo(acdir, cellName, AFSCONF_VLDBSERVICE, &info); if (code) { afs_com_err(whoami, code, "; Can't find cell %s's hosts in %s", cellName, acdir->cellservDB); ERROR(BC_NOCELLCONFIG); } code = afsconf_PickClientSecObj(acdir, secFlags, &info, cellName, &sc, &scIndex, expires); if (code) { afs_com_err(whoami, code, "(configuring connection security)"); ERROR(BC_NOCELLCONFIG); } if (scIndex == RX_SECIDX_NULL && !noAuthFlag) afs_com_err(whoami, 0, "Can't get tokens - running unauthenticated"); /* tell UV module about default authentication */ UV_SetSecurity(sc, scIndex); if (info.numServers > VLDB_MAXSERVERS) { afs_com_err(whoami, 0, "Warning: %d VLDB servers exist for cell '%s', can only remember the first %d", info.numServers, cellName, VLDB_MAXSERVERS); info.numServers = VLDB_MAXSERVERS; } for (i = 0; i < info.numServers; i++) serverconns[i] = rx_NewConnection(info.hostAddr[i].sin_addr.s_addr, info.hostAddr[i].sin_port, USER_SERVICE_ID, sc, scIndex); serverconns[i] = 0; *cstruct = 0; code = ubik_ClientInit(serverconns, cstruct); if (code) { afs_com_err(whoami, code, "; Can't initialize ubik connection to vldb"); ERROR(code); } error_exit: if (acdir) afsconf_Close(acdir); return (code); }
afs_int32 udbClientInit(int noAuthFlag, int localauth, char *cellName) { struct afsconf_cell info; struct afsconf_dir *acdir; const char *confdir; int i; afs_int32 secFlags; afs_int32 code = 0; secFlags = parseSecFlags(noAuthFlag, localauth, &confdir); secFlags |= AFSCONF_SECOPTS_FALLBACK_NULL; if (cellName && cellName[0] == '\0') cellName = NULL; acdir = afsconf_Open(confdir); if (!acdir) { afs_com_err(whoami, 0, "Can't open configuration directory '%s'", confdir); ERROR(BC_NOCELLCONFIG); } code = afsconf_GetCellInfo(acdir, cellName, 0, &info); if (code) { afs_com_err(whoami, code, "; Can't find cell %s's hosts in %s", cellName, acdir->cellservDB); ERROR(BC_NOCELLCONFIG); } code = afsconf_PickClientSecObj(acdir, secFlags, &info, cellName, &udbHandle.uh_secobj, &udbHandle.uh_scIndex, NULL); if (code) { afs_com_err(whoami, code, "(configuring connection security)"); ERROR(BC_NOCELLCONFIG); } if (udbHandle.uh_scIndex == RX_SECIDX_NULL && !noAuthFlag) afs_com_err(whoami, 0, "Can't get tokens - running unauthenticated"); /* We have to have space for the trailing NULL that terminates the server * conneciton array - so we can only store MAXSERVERS-1 real elements in * that array. */ if (info.numServers >= MAXSERVERS) { afs_com_err(whoami, 0, "Warning: %d BDB servers exist for cell '%s', can only remember the first %d", info.numServers, cellName, MAXSERVERS-1); info.numServers = MAXSERVERS - 1; } /* establish connections to the servers. Check for failed connections? */ for (i = 0; i < info.numServers; i++) { udbHandle.uh_serverConn[i] = rx_NewConnection(info.hostAddr[i].sin_addr.s_addr, htons(AFSCONF_BUDBPORT), BUDB_SERVICE, udbHandle.uh_secobj, udbHandle.uh_scIndex); } udbHandle.uh_serverConn[i] = 0; code = ubik_ClientInit(udbHandle.uh_serverConn, &udbHandle.uh_client); if (code) { afs_com_err(whoami, code, "; Can't initialize ubik connection to backup database"); ERROR(code); } /* Try to quickly find a good site by setting deadtime low */ for (i = 0; i < info.numServers; i++) rx_SetConnDeadTime(udbHandle.uh_client->conns[i], 1); code = ubik_BUDB_GetInstanceId(udbHandle.uh_client, 0, &udbHandle.uh_instanceId); /* Reset dead time back up to default */ for (i = 0; i < info.numServers; i++) rx_SetConnDeadTime(udbHandle.uh_client->conns[i], 60); /* If did not find a site on first quick pass, try again */ if (code == -1) code = ubik_BUDB_GetInstanceId(udbHandle.uh_client, 0, &udbHandle.uh_instanceId); if (code) { afs_com_err(whoami, code, "; Can't access backup database"); ERROR(code); } error_exit: if (acdir) afsconf_Close(acdir); return (code); }
static int internal_client_init(struct afsconf_dir *dir, struct afsconf_cell *info, int secFlags, struct ubik_client **uclientp, int (*secproc) (struct rx_securityClass *, afs_int32), int maxservers, const char *serviceid, int deadtime, afs_uint32 server, afs_uint32 port, afs_int32 usrvid) { int code, i; afs_int32 scIndex; struct rx_securityClass *sc; /* This must change if VLDB_MAXSERVERS becomes larger than MAXSERVERS */ static struct rx_connection *serverconns[MAXSERVERS]; const char *progname; progname = getprogname(); if (progname == NULL) progname = "<unknown>"; code = rx_Init(0); if (code) { fprintf(stderr, "%s: could not initialize rx.\n", progname); return code; } rx_SetRxDeadTime(deadtime); code = afsconf_PickClientSecObj(dir, secFlags, info, NULL, &sc, &scIndex, NULL); if (code) { fprintf(stderr, "%s: can't create client security object", progname); return code; } if (scIndex == RX_SECIDX_NULL && !(secFlags & AFSCONF_SECOPTS_NOAUTH)) { fprintf(stderr, "%s: Could not get afs tokens, running unauthenticated.\n", progname); } if (secproc) /* tell UV module about default authentication */ (*secproc) (sc, scIndex); if (server) { serverconns[0] = rx_NewConnection(server, port, usrvid, sc, scIndex); } else { if (info->numServers > maxservers) { fprintf(stderr, "%s: info.numServers=%d (> maxservers=%d)\n", progname, info->numServers, maxservers); return -1; } for (i = 0; i < info->numServers; i++) { if (!info->hostAddr[i].sin_port && port) info->hostAddr[i].sin_port = port; serverconns[i] = rx_NewConnection(info->hostAddr[i].sin_addr.s_addr, info->hostAddr[i].sin_port, usrvid, sc, scIndex); } } /* Are we just setting up connections, or is this really ubik stuff? */ if (uclientp) { *uclientp = 0; code = ubik_ClientInit(serverconns, uclientp); if (code) fprintf(stderr, "%s: ubik client init failed.\n", progname); return code; } return 0; }