/*
* 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/stds.h>
+#include <roken.h>
+
#ifdef IGNORE_SOME_GCC_WARNINGS
# pragma GCC diagnostic warning "-Wstrict-prototypes"
#endif
-#include <sys/types.h>
-#include <fcntl.h>
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#elif defined(AFS_SUN5_ENV)
-#include <netdb.h>
-#else
-#include <sys/param.h> /* for hostnames etc */
-#endif
+#include <afs/cmd.h>
#include <afs/auth.h>
#include <afs/cellconfig.h>
#include <ubik.h>
+#include <afs/afsint.h>
#include <afs/volser.h>
#include <afs/volser_prototypes.h>
#include <afs/afsutil.h>
#include <afs/budb_client.h>
#include <afs/budb.h>
#include <afs/com_err.h>
-#include <errno.h>
#include "bc.h"
#include "error_macros.h"
extern char *whoami;
/* -------------------------------------
- * Globals
+ * Globals
* -------------------------------------
*/
* -------------------------------------
*/
-afs_int32 bcdb_AddVolume(register struct budb_volumeEntry *veptr)
+afs_int32 bcdb_AddVolume(struct budb_volumeEntry *veptr)
{
afs_int32 code;
return (code);
}
-afs_int32 bcdb_AddVolumes(register struct budb_volumeEntry *veptr, afs_int32 count)
+afs_int32 bcdb_AddVolumes(struct budb_volumeEntry *veptr, afs_int32 count)
{
struct budb_volumeList volumeList;
afs_int32 code;
}
-afs_int32 bcdb_CreateDump(register struct budb_dumpEntry *deptr)
+afs_int32 bcdb_CreateDump(struct budb_dumpEntry *deptr)
{
afs_int32 code;
return (code);
}
-afs_int32 bcdb_deleteDump(afs_int32 dumpID, afs_int32 fromTime, afs_int32 toTime,
+afs_int32 bcdb_deleteDump(afs_int32 dumpID, afs_int32 fromTime, afs_int32 toTime,
budb_dumpsList *dumps)
{
afs_int32 code;
*/
int
-bcdb_FindDump(char *volumeName, afs_int32 beforeDate,
+bcdb_FindDump(char *volumeName, afs_int32 beforeDate,
struct budb_dumpEntry *deptr)
{
afs_int32 code;
int
bcdb_FindDumpByID(afs_int32 dumpID, struct budb_dumpEntry *deptr)
{
- register afs_int32 code;
+ afs_int32 code;
afs_int32 nextindex;
afs_int32 dbTime;
budb_dumpList dl;
*/
afs_int32
-bcdb_FindLastVolClone(char *volSetName, char *dumpName, char *volName,
+bcdb_FindLastVolClone(char *volSetName, char *dumpName, char *volName,
afs_int32 *clonetime)
{
/* server notes
*/
int
-bcdb_FindLatestDump(char *volSetName, char *dumpPath,
+bcdb_FindLatestDump(char *volSetName, char *dumpPath,
struct budb_dumpEntry *deptr)
{
afs_int32 code;
*/
int
-bcdb_FindTape(afs_int32 dumpid, char *tapeName,
+bcdb_FindTape(afs_int32 dumpid, char *tapeName,
struct budb_tapeEntry *teptr)
{
budb_tapeList tl;
}
int
-bcdb_FindTapeSeq(afs_int32 dumpid, afs_int32 tapeSeq,
+bcdb_FindTapeSeq(afs_int32 dumpid, afs_int32 tapeSeq,
struct budb_tapeEntry *teptr)
{
budb_tapeList tl;
}
/* bcdb_FindVolumes
- * notes:
+ * notes:
* - this is part of dblookup. The existing semantics will not work since
* they do lookups based on dump id.
* - in the restore code, it uses this to extract information about
*/
afs_int32
-bcdb_FindVolumes(afs_int32 dumpID, char *volumeName,
- struct budb_volumeEntry *returnArray,
- afs_int32 last, afs_int32 *next, afs_int32 maxa,
+bcdb_FindVolumes(afs_int32 dumpID, char *volumeName,
+ struct budb_volumeEntry *returnArray,
+ afs_int32 last, afs_int32 *next, afs_int32 maxa,
afs_int32 *nEntries)
{
budb_volumeList vl;
}
int
-bcdb_FinishDump(register struct budb_dumpEntry *deptr)
+bcdb_FinishDump(struct budb_dumpEntry *deptr)
{
afs_int32 code;
code = ubik_BUDB_FinishDump(udbHandle.uh_client, 0, deptr);
}
int
-bcdb_FinishTape(register struct budb_tapeEntry *teptr)
+bcdb_FinishTape(struct budb_tapeEntry *teptr)
{
afs_int32 code;
code = ubik_BUDB_FinishTape(udbHandle.uh_client, 0, teptr);
*/
afs_int32
-bcdb_LookupVolume(char *volumeName, struct budb_volumeEntry *returnArray,
- afs_int32 last, afs_int32 *next, afs_int32 maxa,
+bcdb_LookupVolume(char *volumeName, struct budb_volumeEntry *returnArray,
+ afs_int32 last, afs_int32 *next, afs_int32 maxa,
afs_int32 *nEntries)
{
budb_volumeList vl;
/* ---- text configuration handling routines ----
- *
- * notes:
+ *
+ * notes:
* The caller should pass in/out a fid for an unlinked, open file to prevent
- * tampering with the files contents;
+ * tampering with the files contents;
*/
/* bcdb_GetTextFile
*/
int
-bcdb_GetTextFile(register udbClientTextP ctPtr)
+bcdb_GetTextFile(udbClientTextP ctPtr)
{
afs_int32 bufferSize;
afs_int32 offset, nextOffset;
/* allocate a buffer */
bufferSize = 1024;
- charList.charListT_val = (char *)malloc(bufferSize);
+ charList.charListT_val = malloc(bufferSize);
if (charList.charListT_val == 0)
ERROR(BUDB_INTERNALERROR);
charList.charListT_len = bufferSize;
- offset = 0;
nextOffset = 0;
ctPtr->textSize = 0;
while (nextOffset != -1) {
/* allocate a buffer */
bufferSize = 1024;
- charList.charListT_val = (char *)malloc(bufferSize);
+ charList.charListT_val = malloc(bufferSize);
if (charList.charListT_val == 0)
ERROR(BUDB_INTERNALERROR);
charList.charListT_len = bufferSize;
offset = 0;
while (fileSize != 0) {
- chunkSize = MIN(fileSize, bufferSize);
+ chunkSize = min(fileSize, bufferSize);
code =
fread(charList.charListT_val, sizeof(char), chunkSize,
ctPtr->textStream);
* -------------------------------------
*/
-/* vldbClientInit
+static afsconf_secflags
+parseSecFlags(int noAuthFlag, int localauth, const char **confdir) {
+ afsconf_secflags secFlags;
+
+ secFlags = 0;
+ if (noAuthFlag)
+ secFlags |= AFSCONF_SECOPTS_NOAUTH;
+
+ if (localauth) {
+ secFlags |= AFSCONF_SECOPTS_LOCALAUTH;
+ *confdir = AFSDIR_SERVER_ETC_DIRPATH;
+ } else {
+ *confdir = AFSDIR_CLIENT_ETC_DIRPATH;
+ }
+ return secFlags;
+}
+
+/* vldbClientInit
* Initialize a client for the vl ubik database.
*/
int
-vldbClientInit(int noAuthFlag, int localauth, char *cellName,
- struct ubik_client **cstruct,
+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 = 0; /* Index of Rx security object - noauth */
+ afs_int32 i, scIndex = RX_SECIDX_NULL;
struct afsconf_cell info;
- struct ktc_principal sname;
- struct ktc_token *ttoken = NULL;
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((localauth ? AFSDIR_SERVER_ETC_DIRPATH :
- AFSDIR_CLIENT_ETC_DIRPATH));
+ acdir = afsconf_Open(confdir);
if (!acdir) {
- afs_com_err(whoami, 0, "Can't open configuration directory '%s'",
- (localauth ? AFSDIR_SERVER_ETC_DIRPATH :
- AFSDIR_CLIENT_ETC_DIRPATH));
+ afs_com_err(whoami, 0, "Can't open configuration directory '%s'", confdir);
ERROR(BC_NOCELLCONFIG);
}
- if (!cellName[0]) {
- char cname[64];
-
- code = afsconf_GetLocalCell(acdir, cname, sizeof(cname));
- if (code) {
- afs_com_err(whoami, code,
- "; Can't get the local cell name - check %s/%s",
- (localauth ? AFSDIR_SERVER_ETC_DIRPATH :
- AFSDIR_CLIENT_ETC_DIRPATH), AFSDIR_THISCELL_FILE);
- ERROR(code);
- }
- strcpy(cellName, cname);
- }
-
code = afsconf_GetCellInfo(acdir, cellName, AFSCONF_VLDBSERVICE, &info);
if (code) {
afs_com_err(whoami, code, "; Can't find cell %s's hosts in %s/%s",
- cellName,
- (localauth ? AFSDIR_SERVER_ETC_DIRPATH :
- AFSDIR_CLIENT_ETC_DIRPATH), AFSDIR_CELLSERVDB_FILE);
+ cellName, confdir, AFSDIR_CELLSERVDB_FILE);
ERROR(BC_NOCELLCONFIG);
}
- /*
- * Grab tickets if we care about authentication.
- */
- *expires = 0;
- if (localauth) {
- code = afsconf_GetLatestKey(acdir, 0, 0);
- if (code) {
- afs_com_err(whoami, code, "; Can't get key from local key file");
- ERROR(code);
- } else {
- code = afsconf_ClientAuth(acdir, &sc, &scIndex);
- if (code) {
- afs_com_err(whoami, code, "; Calling ClientAuth");
- ERROR(code);
- }
-
- *expires = NEVERDATE;
- }
- } else {
- if (!noAuthFlag) {
- strcpy(sname.cell, info.name);
- sname.instance[0] = 0;
- strcpy(sname.name, "afs");
-
- code =
- ktc_GetToken(&sname, ttoken, sizeof(struct ktc_token), NULL);
- if (code) {
- afs_com_err(whoami, code,
- "; Can't get AFS tokens - running unauthenticated");
- } else {
- if ((ttoken->kvno < 0) || (ttoken->kvno > 256))
- afs_com_err(whoami, 0,
- "Funny kvno (%d) in ticket, proceeding",
- ttoken->kvno);
- *expires = ttoken->endTime;
- scIndex = 2;
- }
- }
-
- switch (scIndex) {
- case 0:
- sc = rxnull_NewClientSecurityObject();
- break;
- case 2:
- sc = (struct rx_securityClass *)
- rxkad_NewClientSecurityObject(rxkad_clear,
- &ttoken->sessionKey,
- ttoken->kvno, ttoken->ticketLen,
- ttoken->ticket);
- break;
- default:
- afs_com_err(whoami, 0, "Unsupported authentication type %d", scIndex);
- ERROR(-1);
- break;
- }
- }
-
- if (!sc) {
- afs_com_err(whoami, 0,
- "Can't create a security object with security index %d",
- scIndex);
- ERROR(-1);
+ 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);
afs_int32
udbClientInit(int noAuthFlag, int localauth, char *cellName)
{
- struct ktc_principal principal;
- struct ktc_token token;
struct afsconf_cell info;
struct afsconf_dir *acdir;
+ const char *confdir;
int i;
+ afs_int32 secFlags;
afs_int32 code = 0;
- acdir =
- afsconf_Open((localauth ? AFSDIR_SERVER_ETC_DIRPATH :
- AFSDIR_CLIENT_ETC_DIRPATH));
+ 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'",
- (localauth ? AFSDIR_SERVER_ETC_DIRPATH :
- AFSDIR_CLIENT_ETC_DIRPATH));
+ confdir);
ERROR(BC_NOCELLCONFIG);
}
- if (!cellName[0]) {
- char cname[64];
-
- code = afsconf_GetLocalCell(acdir, cname, sizeof(cname));
- if (code) {
- afs_com_err(whoami, code,
- "; Can't get the local cell name - check %s/%s",
- (localauth ? AFSDIR_SERVER_ETC_DIRPATH :
- AFSDIR_CLIENT_ETC_DIRPATH), AFSDIR_THISCELL_FILE);
- ERROR(code);
- }
- strcpy(cellName, cname);
- }
-
code = afsconf_GetCellInfo(acdir, cellName, 0, &info);
if (code) {
afs_com_err(whoami, code, "; Can't find cell %s's hosts in %s/%s",
- cellName,
- (localauth ? AFSDIR_SERVER_ETC_DIRPATH :
- AFSDIR_CLIENT_ETC_DIRPATH), AFSDIR_CELLSERVDB_FILE);
+ cellName, confdir, AFSDIR_CELLSERVDB_FILE);
ERROR(BC_NOCELLCONFIG);
}
- udbHandle.uh_scIndex = RX_SCINDEX_NULL;
-
- if (localauth) {
- code = afsconf_GetLatestKey(acdir, 0, 0);
- if (code) {
- afs_com_err(whoami, code, "; Can't get key from local key file");
- ERROR(-1);
- } else {
- code =
- afsconf_ClientAuth(acdir, &udbHandle.uh_secobj,
- &udbHandle.uh_scIndex);
- if (code) {
- afs_com_err(whoami, code, "; Calling ClientAuth");
- ERROR(-1);
- }
- }
- } else {
- if (!noAuthFlag) {
- /* setup principal */
- strcpy(principal.cell, info.name);
- principal.instance[0] = 0;
- strcpy(principal.name, "afs");
-
- /* get token */
- code = ktc_GetToken(&principal, &token, sizeof(token), NULL);
- if (code) {
- afs_com_err(whoami, code,
- "; Can't get tokens - running unauthenticated");
- } else {
- if ((token.kvno < 0) || (token.kvno > 256))
- afs_com_err(whoami, 0,
- "Unexpected kvno (%d) in ticket - proceeding",
- token.kvno);
- udbHandle.uh_scIndex = RX_SCINDEX_KAD; /* Kerberos */
- }
- }
-
- switch (udbHandle.uh_scIndex) {
- case 0:
- udbHandle.uh_secobj = rxnull_NewClientSecurityObject();
- break;
-
- case 2:
- udbHandle.uh_secobj = (struct rx_securityClass *)
- rxkad_NewClientSecurityObject(rxkad_clear, &token.sessionKey,
- token.kvno, token.ticketLen,
- token.ticket);
- break;
-
- default:
- afs_com_err(whoami, 0, "Unsupported authentication type %d",
- udbHandle.uh_scIndex);
- ERROR(-1);
- break;
- }
- }
-
- if (!udbHandle.uh_secobj) {
- afs_com_err(whoami, 0,
- "Can't create a security object with security index %d",
- udbHandle.uh_scIndex);
- ERROR(-1);
+ 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");
- if (info.numServers > MAXSERVERS) {
+ /* 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);
- info.numServers = MAXSERVERS;
+ info.numServers, cellName, MAXSERVERS-1);
+ info.numServers = MAXSERVERS - 1;
}
/* establish connections to the servers. Check for failed connections? */
*/
afs_int32
-ubik_Call_SingleServer(int (*aproc) (), struct ubik_client *aclient,
- afs_int32 aflags, char *p1, char *p2, char *p3,
+ubik_Call_SingleServer(int (*aproc) (), struct ubik_client *aclient,
+ afs_int32 aflags, char *p1, char *p2, char *p3,
char *p4, char *p5, char *p6, char *p7, char *p8,
- char *p9, char *p10, char *p11, char *p12, char *p13,
+ char *p9, char *p10, char *p11, char *p12, char *p13,
char *p14, char *p15, char *p16)
{
- register afs_int32 code;
+ afs_int32 code;
afs_int32 someCode, newHost, thisHost;
- register afs_int32 i;
- register afs_int32 count;
+ afs_int32 i;
+ afs_int32 count;
int chaseCount;
int pass;
struct rx_connection *tc;
/* -------------------------------------
- * debug and test routines
+ * debug and test routines
* -------------------------------------
*/
int
udbLocalInit(void)
{
- afs_int32 serverList[MAXSERVERS];
+ afs_uint32 serverList[MAXSERVERS];
char hostname[256];
char *args[3];
int i;
return (-1);
}
- udbHandle.uh_scIndex = RX_SCINDEX_NULL;
+ udbHandle.uh_scIndex = RX_SECIDX_NULL;
udbHandle.uh_secobj = (struct rx_securityClass *)
rxnull_NewClientSecurityObject();
* the udbClientTextP.textStream member.
* Output: The temp file name is returned in tmpFileName. This should be used
* to delete the file when done with it.
- * Return Values:
+ * Return Values:
* !0: error code
* 0: Success.
*/
bc_openTextFile(udbClientTextP ctPtr, char *tmpFileName)
{
int code = 0;
+ int fd;
- if (ctPtr->textStream != NULL)
+ if (ctPtr->textStream != NULL) {
fclose(ctPtr->textStream);
+ ctPtr->textStream = NULL;
+ }
sprintf(tmpFileName, "%s/bu_XXXXXX", gettmpdir());
-#ifdef AFS_LINUX20_ENV
- mkstemp(tmpFileName);
-#else
- mktemp(tmpFileName);
-#endif
- ctPtr->textStream = fopen(tmpFileName, "w+");
+ fd = mkstemp(tmpFileName);
+ if (fd == -1)
+ ERROR(BUDB_INTERNALERROR);
+ ctPtr->textStream = fdopen(fd, "w+");
if (ctPtr->textStream == NULL)
ERROR(BUDB_INTERNALERROR);
/* bc_closeTextFile: This function closes any actual temp files associated with
- * a udbClientText structure.
+ * a udbClientText structure.
* Input: ctPtr->textStream - stream to close
* tmpFileName - temp file name to delete
- * RetVal:
+ * RetVal:
* 0 - Success
* !0 - error code
*/