}
#endif /* windows */
-int
-afsconf_GetCellInfo(struct afsconf_dir *adir, char *acellName, char *aservice,
- struct afsconf_cell *acellInfo)
+/* flags for _GetCellInfo */
+#define AFSCONF_GETCELL_EMPTYOK (0x1) /** it's okay to return 'empty' cells
+ * (that is, cells without any
+ * dbservers) */
+
+static int
+_GetCellInfo(struct afsconf_dir *adir, char *acellName, char *aservice,
+ struct afsconf_cell *acellInfo, afs_uint32 flags)
{
struct afsconf_entry *tce;
struct afsconf_aliasentry *tcae;
int cnLen;
int ambig;
char tbuffer[64];
+ int emptyok = 0;
+
+ if ((flags & AFSCONF_GETCELL_EMPTYOK)) {
+ emptyok = 1;
+ }
LOCK_GLOBAL_MUTEX;
if (adir)
bestce = tce;
}
}
- if (!ambig && bestce && bestce->cellInfo.numServers) {
+ if (!ambig && bestce && (bestce->cellInfo.numServers || emptyok)) {
*acellInfo = bestce->cellInfo; /* structure assignment */
if (aservice) {
tservice = afsconf_FindService(aservice);
acellInfo->clone[i] = clone[i];
}
acellInfo->numServers = numServers;
- acellInfo->flags |= AFSCONF_CELL_FLAG_DNS_QUERIED;
+ if (numServers) {
+ acellInfo->flags |= AFSCONF_CELL_FLAG_DNS_QUERIED;
+ }
}
UNLOCK_GLOBAL_MUTEX;
return 0;
}
/**
+ * Get info about a cell.
+ *
+ * @param[in] adir afsconf object.
+ * @param[in] acellName name of the cell to get. a cell name abbreviation can
+ * be given if it's unambiguous (e.g. "cell" can be given
+ * for "cell.example.com" if no other cells begin with
+ * "cell").
+ * @param[in] aservice name of the service in the cell, as accepted by
+ * afsconf_FindService. if NULL is given: for local
+ * lookups, no port information will be returned; for DNS
+ * lookups, we'll default to "afs3-vlserver".
+ * @param[out] acellInfo info for the requested cell and service
+ *
+ * @return afsconf error codes
+ */
+int
+afsconf_GetCellInfo(struct afsconf_dir *adir, char *acellName, char *aservice,
+ struct afsconf_cell *acellInfo)
+{
+ return _GetCellInfo(adir, acellName, aservice, acellInfo, 0);
+}
+
+/**
+ * Get a cell's name.
+ *
+ * This is similar to afsconf_GetCellInfo, but doesn't actually retrieve the
+ * info of the specified cell (beyond it's name). This can be useful to verify
+ * that a cell name is valid, or to canonicalize a possibly-abbreviated cell
+ * name. Unlike afsconf_GetCellInfo, this call can avoid DNS lookups if the
+ * cell name is specified in the local config, but the cell's servers are not.
+ *
+ * @param[in] adir afsconf object.
+ * @param[in] acellName name of the cell to get. a cell name abbreviation can
+ * be given if it's unambiguous (see afsconf_GetCellInfo).
+ * @param[out] buf on success, the cell's name is written to this buffer.
+ * @param[in] buf_size size of 'buf'.
+ *
+ * @return afsconf error codes
+ * @retval AFSCONF_FAILURE buf_size is too small to fit the cell's name.
+ */
+int
+afsconf_GetCellName(struct afsconf_dir *adir, char *acellName, char *buf,
+ size_t buf_size)
+{
+ int code;
+ struct afsconf_cell info;
+ code = _GetCellInfo(adir, acellName, NULL, &info, AFSCONF_GETCELL_EMPTYOK);
+ if (code) {
+ return code;
+ }
+ if (strlcpy(buf, info.name, buf_size) >= buf_size) {
+ return AFSCONF_FAILURE;
+ }
+ return 0;
+}
+
+/**
* Get the current localcell name.
*
* Internal function to get a pointer to the local cell name.
extern int afsconf_GetCellInfo(struct afsconf_dir *adir, char *acellName,
char *aservice,
struct afsconf_cell *acellInfo);
+extern int afsconf_GetCellName(struct afsconf_dir *adir, char *acellName,
+ char *buf, size_t buf_size);
extern int afsconf_GetLocalCell(struct afsconf_dir *adir,
char *aname, afs_int32 alen);
extern int afsconf_Close(struct afsconf_dir *adir);
afsconf_GetAfsdbInfo
afsconf_GetAllKeys
afsconf_GetCellInfo
+afsconf_GetCellName
afsconf_GetExtendedCellInfo
afsconf_GetKey
afsconf_GetLatestKey
static int PruneList(struct AclEntry **, int);
static int CleanAcl(struct Acl *, char *);
static int SetVolCmd(struct cmd_syndesc *as, void *arock);
-static int GetCellName(char *, struct afsconf_cell *);
+static int GetCellName(char *, char *, size_t);
static void Die(int, char *);
/*
afs_int32 j;
afs_int32 temp;
char *tp;
- struct afsconf_cell info;
struct chservinfo checkserv;
memset(&checkserv, 0, sizeof(struct chservinfo));
/* now copy in optional cell name, if specified */
if (as->parms[0].items) {
- code = GetCellName(as->parms[0].items->data, &info);
+ code = GetCellName(as->parms[0].items->data, &checkserv.tbuffer[0],
+ sizeof(checkserv.tbuffer));
if (code) {
return 1;
}
- strcpy(checkserv.tbuffer, info.name);
- checkserv.tsize = strlen(info.name) + 1;
+ checkserv.tsize = strlen(checkserv.tbuffer) + 1;
} else {
strcpy(checkserv.tbuffer, "\0");
checkserv.tsize = 0;
{
afs_int32 code;
struct ViceIoctl blob;
- struct afsconf_cell info;
+ char cellName[MAXCELLCHARS];
struct cmd_item *ti;
struct a {
afs_int32 stat;
/* once per cell */
blob.out_size = sizeof(args);
blob.out = (caddr_t) & args;
- code = GetCellName(ti->data, &info);
+ code = GetCellName(ti->data, &cellName[0], sizeof(cellName));
if (code) {
error = 1;
continue;
}
- blob.in_size = 1 + strlen(info.name);
- blob.in = info.name;
+ blob.in_size = 1 + strlen(cellName);
+ blob.in = cellName;
code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
if (code) {
if (errno == ENOENT)
fprintf(stderr, "%s: the cell named '%s' does not exist\n",
- pn, info.name);
+ pn, cellName);
else
- Die(errno, info.name);
+ Die(errno, cellName);
error = 1;
continue;
}
- printf("Cell %s status: ", info.name);
+ printf("Cell %s status: ", cellName);
if (args.stat & 2)
printf("no setuid allowed");
else
{
afs_int32 code;
struct ViceIoctl blob;
- struct afsconf_cell info;
struct cmd_item *ti;
struct a {
afs_int32 stat;
/* set stat for all listed cells */
for (ti = as->parms[0].items; ti; ti = ti->next) {
/* once per cell */
- code = GetCellName(ti->data, &info);
+ code = GetCellName(ti->data, &args.cname[0], sizeof(args.cname));
if (code) {
error = 1;
continue;
}
- strcpy(args.cname, info.name);
blob.in_size = sizeof(args);
blob.in = (caddr_t) & args;
blob.out_size = 0;
blob.out = (caddr_t) 0;
code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
if (code) {
- Die(errno, info.name); /* XXX added cell name to Die() call */
+ Die(errno, args.cname); /* XXX added cell name to Die() call */
error = 1;
}
}
}
static int
-GetCellName(char *cellName, struct afsconf_cell *info)
+GetCellName(char *cellName, char *buf, size_t buf_size)
{
struct afsconf_dir *tdir;
int code;
return -1;
}
- code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
+ code = afsconf_GetCellName(tdir, cellName, buf, buf_size);
if (code) {
fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
AFSDIR_CLIENT_CELLSERVDB_FILEPATH);