#include <afs/param.h>
#endif
-RCSID
- ("$Header$");
#if defined(UKERNEL)
#include "afs/sysincludes.h"
#include "afs/stds.h"
#include "rx/rx.h"
#include "rx/xdr.h"
-#include "rx/rxkad.h"
#include "afs/auth.h"
#include "afs/cellconfig.h"
#include "afs/afsutil.h"
#include "afs/ptclient.h"
#include "afs/ptuser.h"
#include "afs/pterror.h"
+#include "afs/com_err.h"
#else /* defined(UKERNEL) */
#include <afs/stds.h>
#include <ctype.h>
#include <netinet/in.h>
#endif
#include <stdio.h>
-#ifdef HAVE_STRING_H
#include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
#include <rx/rx.h>
#include <rx/xdr.h>
-#include <rx/rxkad.h>
#include <afs/auth.h>
#include <afs/cellconfig.h>
#include <afs/afsutil.h>
+#include <afs/com_err.h>
#include "ptclient.h"
#include "ptuser.h"
#include "pterror.h"
afs_int32 scIndex;
static struct afsconf_cell info;
afs_int32 i;
+#if !defined(UKERNEL)
char cellstr[64];
+#endif
afs_int32 gottdir = 0;
afs_int32 refresh = 0;
if (!tdir) {
if (confDir && strcmp(confDir, ""))
fprintf(stderr,
- "libprot: Could not open configuration directory: %s.\n",
- confDir);
+ "%s: Could not open configuration directory: %s.\n",
+ whoami, confDir);
else
fprintf(stderr,
- "libprot: No configuration directory specified.\n");
+ "%s: No configuration directory specified.\n",
+ whoami);
return -1;
}
gottdir = 1;
code = afsconf_GetLocalCell(tdir, cellstr, sizeof(cellstr));
if (code) {
- afsconf_Close(tdir);
fprintf(stderr,
"libprot: Could not get local cell. [%d]\n", code);
return code;
code = afsconf_GetCellInfo(tdir, cell, "afsprot", &info);
if (code) {
- afsconf_Close(tdir);
fprintf(stderr, "libprot: Could not locate cell %s in %s/%s\n",
cell, confDir, AFSDIR_CELLSERVDB_FILE);
return code;
* which case we will get one (and re-read the key file).
*/
if (pruclient && (lastLevel == secLevel) && (secLevel != 2)) {
- afsconf_Close(tdir);
return 0;
}
code = rx_Init(0);
if (code) {
- afsconf_Close(tdir);
fprintf(stderr, "libprot: Could not initialize rx.\n");
return code;
}
/* Most callers use secLevel==1, however, the fileserver uses secLevel==2
* to force use of the KeyFile. secLevel == 0 implies -noauth was
* specified. */
- if ((secLevel == 2) && (afsconf_GetLatestKey(tdir, 0, 0) == 0)) {
- /* If secLevel is two assume we're on a file server and use
- * ClientAuthSecure if possible. */
- code = afsconf_ClientAuthSecure(tdir, &sc[2], &scIndex);
- if (code)
- fprintf(stderr,
- "libprot: clientauthsecure returns %d %s"
- " (so trying noauth)\n", code, error_message(code));
- if (code)
- scIndex = 0; /* use noauth */
+ if (secLevel == 2) {
+ code = afsconf_GetLatestKey(tdir, 0, 0);
+ if (code) {
+ afs_com_err(whoami, code,
+ "(getting key from local KeyFile)\n");
+ scIndex = 0; /* use noauth */
+ } else {
+ /* If secLevel is two assume we're on a file server and use
+ * ClientAuthSecure if possible. */
+ code = afsconf_ClientAuthSecure(tdir, &sc[2], &scIndex);
+ if (code) {
+ afs_com_err(whoami, code,
+ "(calling client secure)\n");
+ scIndex = 0; /* use noauth */
+ }
+ }
if (scIndex != 2)
/* if there was a problem, an unauthenticated conn is returned */
sc[scIndex] = sc[2];
sname.instance[0] = 0;
strcpy(sname.name, "afs");
code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), NULL);
- if (code)
+ if (code) {
+ afs_com_err(whoami, code, "(getting token)");
+ if (secLevel > 1)
+ return code;
scIndex = 0;
- else {
+ } else {
if (ttoken.kvno >= 0 && ttoken.kvno <= 256)
/* this is a kerberos ticket, set scIndex accordingly */
scIndex = 2;
else {
fprintf(stderr,
- "libprot: funny kvno (%d) in ticket, proceeding\n",
- ttoken.kvno);
+ "%s: funny kvno (%d) in ticket, proceeding\n",
+ whoami, ttoken.kvno);
scIndex = 2;
}
sc[2] =
- rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey,
+ rxkad_NewClientSecurityObject((secLevel > 1) ? rxkad_crypt :
+ rxkad_clear, &ttoken.sessionKey,
ttoken.kvno, ttoken.ticketLen,
ttoken.ticket);
}
}
- afsconf_Close(tdir);
- tdir = NULL;
if (scIndex == 1)
return PRBADARG;
if ((scIndex == 0) && (sc[0] == 0))
sc[0] = rxnull_NewClientSecurityObject();
if ((scIndex == 0) && (secLevel != 0))
- com_err(whoami, code,
- "Could not get afs tokens, running unauthenticated.");
+ fprintf(stderr,
+ "%s: Could not get afs tokens, running unauthenticated\n",
+ whoami);
memset(serverconns, 0, sizeof(serverconns)); /* terminate list!!! */
for (i = 0; i < info.numServers; i++)
code = ubik_ClientInit(serverconns, &pruclient);
if (code) {
- com_err(whoami, code, "ubik client init failed.");
+ afs_com_err(whoami, code, "ubik client init failed.");
return code;
}
lastLevel = scIndex;
}
int
-pr_End()
+pr_End(void)
{
int code = 0;
idlist lids;
lnames.namelist_len = 2;
- lnames.namelist_val = (prname *) malloc(2 * PR_MAXNAMELEN);
+ lnames.namelist_val = (prname *) xdr_alloc(2 * PR_MAXNAMELEN);
strncpy(lnames.namelist_val[0], user, PR_MAXNAMELEN);
strncpy(lnames.namelist_val[1], group, PR_MAXNAMELEN);
lids.idlist_val = 0;
lids.idlist_val[1]);
done:
if (lnames.namelist_val)
- free(lnames.namelist_val);
+ xdr_free(lnames.namelist_val, 2 * PR_MAXNAMELEN);
if (lids.idlist_val)
- free(lids.idlist_val);
+ xdr_free(lids.idlist_val, lids.idlist_len * sizeof(lids.idlist_val[0]));
return code;
}
idlist lids;
lnames.namelist_len = 2;
- lnames.namelist_val = (prname *) malloc(2 * PR_MAXNAMELEN);
+ lnames.namelist_val = (prname *) xdr_alloc(2 * PR_MAXNAMELEN);
strncpy(lnames.namelist_val[0], user, PR_MAXNAMELEN);
strncpy(lnames.namelist_val[1], group, PR_MAXNAMELEN);
lids.idlist_val = 0;
lids.idlist_val[1]);
done:
if (lnames.namelist_val)
- free(lnames.namelist_val);
+ xdr_free(lnames.namelist_val, 2 * PR_MAXNAMELEN);
if (lids.idlist_val)
- free(lids.idlist_val);
+ xdr_free(lids.idlist_val, lids.idlist_len * sizeof(lids.idlist_val[0]));
return code;
}
lids.idlist_len = 0;
lids.idlist_val = 0;
lnames.namelist_len = 1;
- lnames.namelist_val = (prname *) malloc(PR_MAXNAMELEN);
+ lnames.namelist_val = (prname *) xdr_alloc(PR_MAXNAMELEN);
stolower(name);
strncpy(lnames.namelist_val[0], name, PR_MAXNAMELEN);
code = ubik_PR_NameToID(pruclient, 0, &lnames, &lids);
if (lids.idlist_val) {
*id = *lids.idlist_val;
- free(lids.idlist_val);
+ xdr_free(lids.idlist_val, lids.idlist_len * sizeof(lids.idlist_val[0]));
}
if (lnames.namelist_val)
- free(lnames.namelist_val);
+ xdr_free(lnames.namelist_val, PR_MAXNAMELEN);
return code;
}
register afs_int32 code;
lids.idlist_len = 1;
- lids.idlist_val = (afs_int32 *) malloc(sizeof(afs_int32));
+ lids.idlist_val = (afs_int32 *) xdr_alloc(sizeof(afs_int32));
*lids.idlist_val = id;
lnames.namelist_len = 0;
lnames.namelist_val = 0;
code = ubik_PR_IDToName(pruclient, 0, &lids, &lnames);
if (lnames.namelist_val) {
strncpy(name, lnames.namelist_val[0], PR_MAXNAMELEN);
- free(lnames.namelist_val);
+ xdr_free(lnames.namelist_val, PR_MAXNAMELEN);
}
if (lids.idlist_val)
- free(lids.idlist_val);
+ xdr_free(lids.idlist_val, lids.idlist_len * sizeof(lids.idlist_val[0]));
return code;
}
if (code)
return code;
if (alist.prlist_val)
- free(alist.prlist_val);
+ xdr_free(alist.prlist_val, alist.prlist_len * sizeof(alist.prlist_val[0]));
return PRSUCCESS;
}
if (code)
return code;
if (alist.prlist_val)
- free(alist.prlist_val);
+ xdr_free(alist.prlist_val, alist.prlist_len * sizeof(alist.prlist_val[0]));
return PRSUCCESS;
}
if (*id == ANONYMOUSID)
return PRNOENT;
code = ubik_PR_ListEntry(pruclient, 0, *id, &aentry);
- //code = ubik_PR_ListEntry(pruclient, 0, *id, &aentry);
if (code)
return code;
/* this should be done in one RPC, but I'm lazy. */
if (oid == ANONYMOUSID)
return PRNOENT;
}
- code = ubik_PR_ChangeEntry(pruclient, 0, id, newname, oid, newid);
+ if (newid)
+ code = ubik_PR_ChangeEntry(pruclient, 0, id, newname, oid, *newid);
+ else
+ code = ubik_PR_ChangeEntry(pruclient, 0, id, newname, oid, 0);
return code;
}
stolower(uname);
stolower(gname);
lnames.namelist_len = 2;
- lnames.namelist_val = (prname *) malloc(2 * PR_MAXNAMELEN);
+ lnames.namelist_val = (prname *) xdr_alloc(2 * PR_MAXNAMELEN);
strncpy(lnames.namelist_val[0], uname, PR_MAXNAMELEN);
strncpy(lnames.namelist_val[1], gname, PR_MAXNAMELEN);
lids.idlist_val = 0;
code = pr_NameToId(&lnames, &lids);
if (code) {
if (lnames.namelist_val)
- free(lnames.namelist_val);
+ xdr_free(lnames.namelist_val, 2 * PR_MAXNAMELEN);
if (lids.idlist_val)
- free(lids.idlist_val);
+ xdr_free(lids.idlist_val, lids.idlist_len * sizeof(lids.idlist_val[0]));
return code;
}
code =
ubik_PR_IsAMemberOf(pruclient, 0, lids.idlist_val[0],
lids.idlist_val[1], flag);
if (lnames.namelist_val)
- free(lnames.namelist_val);
+ xdr_free(lnames.namelist_val, 2 * PR_MAXNAMELEN);
if (lids.idlist_val)
- free(lids.idlist_val);
+ xdr_free(lids.idlist_val, lids.idlist_len * sizeof(lids.idlist_val[0]));
return code;
}