#include <afsconfig.h>
#include <afs/param.h>
+#include <afs/stds.h>
+#include <roken.h>
+#include <afs/opr.h>
-#include <afs/stds.h>
#include <ctype.h>
-#include <stdio.h>
+
#include <lock.h>
#include <afs/afsutil.h>
#include <ubik.h>
#include <rx/rx.h>
#include <rx/rxkad.h>
#include <afs/auth.h>
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#else
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#endif
-#include <string.h>
+#include <afs/cellconfig.h>
+
#include "ptserver.h"
#include "pterror.h"
#include "ptprototypes.h"
#include "afs/audit.h"
-#ifdef AFS_ATHENA_STDENV
-#include <krb.h>
-#endif
-
extern int restricted;
extern struct ubik_dbase *dbase;
extern int pr_noAuth;
-extern char *pr_realmName;
extern int prp_group_default;
extern int prp_user_default;
+extern struct afsconf_dir *prdir;
static afs_int32 iNewEntry(struct rx_call *call, char aname[], afs_int32 aid,
afs_int32 oid, afs_int32 *cid);
return code;
}
+static int
+WritePreamble(struct ubik_trans **tt)
+{
+ int code;
+
+ code = Initdb();
+ if (code)
+ return code;
+
+ code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, tt);
+ if (code)
+ return code;
+
+ code = ubik_SetLock(*tt, 1, 1, LOCKWRITE);
+ if (code)
+ goto out;
+
+ code = read_DbHeader(*tt);
+
+out:
+ if (code)
+ ubik_AbortTrans(*tt);
+
+ return code;
+}
+
+static int
+ReadPreamble(struct ubik_trans **tt)
+{
+ int code;
+
+ code = Initdb();
+ if (code)
+ return code;
+
+ code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, tt);
+ if (code)
+ return code;
+
+ code = ubik_SetLock(*tt, 1, 1, LOCKREAD);
+ if (code)
+ goto out;
+
+ code = read_DbHeader(*tt);
+
+out:
+ if (code)
+ ubik_AbortTrans(*tt);
+
+ return code;
+}
+
afs_int32
SPR_INewEntry(struct rx_call *call, char aname[], afs_int32 aid, afs_int32 oid)
{
int admin;
stolower(aname);
- code = Initdb();
- if (code != PRSUCCESS)
- return code;
- code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
+
+ code = WritePreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
int admin;
char cname[PR_MAXNAMELEN];
stolower(aname);
- code = Initdb();
- if (code)
- return code;
- code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
+
+ code = WritePreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
/* this is for cross-cell self registration. It is not added in the
* SPR_INewEntry because we want self-registration to only do
struct ubik_trans *tt;
afs_int32 temp;
- code = Initdb();
- if (code != PRSUCCESS)
- return code;
- code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
+ code = ReadPreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKREAD);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
afs_int32 code;
struct ubik_trans *tt;
- code = Initdb();
- if (code != PRSUCCESS)
- return code;
- code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
+ code = ReadPreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKREAD);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
struct prentry tentry;
struct prentry uentry;
- code = Initdb();
- if (code != PRSUCCESS)
- return code;
if (gid == ANYUSERID || gid == AUTHUSERID)
return PRPERM;
if (aid == ANONYMOUSID)
return PRPERM;
- code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
+
+ code = WritePreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
if (size < 0)
return PRTOOMANY;
- aid->idlist_val = (afs_int32 *) malloc(size * sizeof(afs_int32));
+ aid->idlist_val = malloc(size * sizeof(afs_int32));
if (!aid->idlist_val)
return PRNOMEM;
- code = Initdb();
- if (code != PRSUCCESS)
- return code;
- code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
+ code = ReadPreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKREAD);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
for (i = 0; i < aname->namelist_len; i++) {
char vname[256];
char *nameinst, *cell;
+ afs_int32 islocal = 1;
strncpy(vname, aname->namelist_val[i], sizeof(vname));
vname[sizeof(vname)-1] ='\0';
cell++;
}
- if (cell && afs_is_foreign_ticket_name(nameinst,NULL,cell,pr_realmName))
- code = NameToID(tt, aname->namelist_val[i], &aid->idlist_val[i]);
- else
+ if (cell && *cell) {
+ code = afsconf_IsLocalRealmMatch(prdir, &islocal, nameinst, NULL, cell);
+ ViceLog(0,
+ ("PTS_NameToID: afsconf_IsLocalRealmMatch(); code=%d, nameinst=%s, cell=%s\n",
+ code, nameinst, cell));
+ }
+ if (islocal)
code = NameToID(tt, nameinst, &aid->idlist_val[i]);
+ else
+ code = NameToID(tt, aname->namelist_val[i], &aid->idlist_val[i]);
if (code != PRSUCCESS)
aid->idlist_val[i] = ANONYMOUSID;
return 0;
if (size < 0)
return PRTOOMANY;
- aname->namelist_val = (prname *) malloc(size * PR_MAXNAMELEN);
+ aname->namelist_val = malloc(size * PR_MAXNAMELEN);
aname->namelist_len = 0;
if (aname->namelist_val == 0)
return PRNOMEM;
if (size == 0)
return PRTOOMANY; /* rxgen will probably handle this */
- code = Initdb();
- if (code != PRSUCCESS)
- return code;
- code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
+ code = ReadPreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKREAD);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
for (i = 0; i < aid->idlist_len; i++) {
code = IDToName(tt, aid->idlist_val[i], aname->namelist_val[i]);
afs_int32 loc, nptr;
int count;
- code = Initdb();
- if (code)
- return code;
- if (code != PRSUCCESS)
- return code;
if (aid == SYSADMINID || aid == ANYUSERID || aid == AUTHUSERID
|| aid == ANONYMOUSID)
return PRPERM;
- code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
+
+ code = WritePreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
afs_int32 loc;
int id = 0;
- code = Initdb();
- if (code)
- return code;
- if (code != PRSUCCESS)
- return code;
if (aid) {
id = aid;
if (aid == SYSADMINID || aid == ANYUSERID || aid == AUTHUSERID
|| aid == ANONYMOUSID)
return PRPERM;
}
- code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
+
+ code = WritePreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
struct prentry uentry;
struct prentry gentry;
- code = Initdb();
- if (code != PRSUCCESS)
- return code;
- code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
+ code = WritePreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
*over = 0;
alist->prlist_len = 0;
alist->prlist_val = NULL;
- code = Initdb();
- if (code != PRSUCCESS)
- return code;
- code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
+
+ code = ReadPreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKREAD);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
temp = FindByID(tt, aid);
if (!temp)
afs_int32 cid = ANONYMOUSID;
code = getCPS2(call, aid, ahost, alist, over, &cid);
- osi_auditU(call, PTS_GetCPS2Event, code, AUD_ID, aid, AUD_HOST, ahost,
+ osi_auditU(call, PTS_GetCPS2Event, code, AUD_ID, aid, AUD_HOST, htonl(ahost),
AUD_END);
ViceLog(125, ("PTS_GetCPS2: code %d cid %d aid %d ahost %d\n", code, cid, aid, ahost));
return code;
afs_int32 hostid;
int host_list = 0;
struct in_addr iaddr;
+ char hoststr[16];
*over = 0;
iaddr.s_addr = ntohl(ahost);
alist->prlist_len = 0;
alist->prlist_val = NULL;
- code = Initdb();
- if (code != PRSUCCESS)
- return code;
- code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
+
+ code = ReadPreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKREAD);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
if (aid != PRBADID) {
temp = FindByID(tt, aid);
|| !AccessOK(tt, *cid, &tentry, PRP_MEMBER_MEM, PRP_MEMBER_ANY))
ABORT_WITH(tt, PRPERM);
}
- code = NameToID(tt, inet_ntoa(iaddr), &hostid);
+ code = NameToID(tt, afs_inet_ntoa_r(iaddr.s_addr, hoststr), &hostid);
if (code == PRSUCCESS && hostid != 0) {
temp = FindByID(tt, hostid);
if (temp) {
afs_int32 code;
code = getHostCPS(call, ahost, alist, over);
- osi_auditU(call, PTS_GetHCPSEvent, code, AUD_HOST, ahost, AUD_END);
+ osi_auditU(call, PTS_GetHCPSEvent, code, AUD_HOST, htonl(ahost), AUD_END);
ViceLog(125, ("PTS_GetHostCPS: code %d ahost %d\n", code, ahost));
return code;
}
struct prentry host_tentry;
afs_int32 hostid;
struct in_addr iaddr;
+ char hoststr[16];
*over = 0;
iaddr.s_addr = ntohl(ahost);
alist->prlist_len = 0;
alist->prlist_val = NULL;
- code = Initdb();
- if (code != PRSUCCESS)
- return code;
- code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
+
+ code = ReadPreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKREAD);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
- code = NameToID(tt, inet_ntoa(iaddr), &hostid);
+ code = NameToID(tt, afs_inet_ntoa_r(iaddr.s_addr, hoststr), &hostid);
if (code == PRSUCCESS && hostid != 0) {
temp = FindByID(tt, hostid);
if (temp) {
afs_int32 code;
struct ubik_trans *tt;
- code = Initdb();
- if (code != PRSUCCESS)
- return code;
- code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
+ code = ReadPreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKREAD);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
code = GetMax(tt, uid, gid);
if (code != PRSUCCESS)
afs_int32 code;
struct ubik_trans *tt;
- code = Initdb();
- if (code != PRSUCCESS)
- return code;
- code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
+ code = WritePreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
afs_int32 temp;
struct prentry tentry;
- code = Initdb();
- if (code != PRSUCCESS)
- return code;
- code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
+ code = ReadPreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKREAD);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
bulkentries->prentries_val = 0;
bulkentries->prentries_len = 0;
- code = Initdb();
- if (code != PRSUCCESS)
- return code;
- code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
+ code = ReadPreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKREAD);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
/* Make sure we are an authenticated caller and that we are on the
* SYSADMIN list.
if (bulkentries->prentries_val == 0) {
bulkentries->prentries_len = 0;
- bulkentries->prentries_val =
- (struct prlistentries *)malloc(PR_MAXENTRIES *
- sizeof(struct prentry));
+ bulkentries->prentries_val = malloc(PR_MAXENTRIES *
+ sizeof(struct prentry));
if (!bulkentries->prentries_val) {
return (PRNOMEM);
}
return PRPERM;
stolower(name);
- code = Initdb();
- if (code)
- return code;
if (aid == ANYUSERID || aid == AUTHUSERID || aid == ANONYMOUSID
|| aid == SYSADMINID)
return PRPERM;
- if (code != PRSUCCESS)
- return code;
- code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
+
+ code = WritePreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
if (mask == 0)
return 0; /* no-op */
- code = Initdb();
- if (code)
- return code;
+
if (id == ANYUSERID || id == AUTHUSERID || id == ANONYMOUSID)
return PRPERM;
- if (code != PRSUCCESS)
- return code;
- code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
+
+ code = WritePreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
alist->prlist_len = 0;
alist->prlist_val = NULL;
- code = Initdb();
- if (code != PRSUCCESS)
- return code;
- code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
+ code = ReadPreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKREAD);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
alist->prlist_len = 0;
alist->prlist_val = (afs_int32 *) 0;
- code = Initdb();
- if (code != PRSUCCESS)
- goto done;
- code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
+ code = ReadPreamble(&tt);
if (code)
- goto done;
+ return code;
+
code = ubik_SetLock(tt, 1, 1, LOCKREAD);
if (code)
ABORT_WITH(tt, code);
code = ubik_EndTrans(tt);
- done:
return code;
}
start = *lastP;
*lastP = 0;
- code = Initdb();
- if (code != PRSUCCESS)
- return code;
- code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
+ code = ReadPreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKREAD);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
code = WhoIsThis(call, tt, cid);
if (code)
afs_int32 code;
struct ubik_trans *tt;
- code = Initdb();
- if (code != PRSUCCESS)
- return code;
- code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
+ code = ReadPreamble(&tt);
if (code)
return code;
- code = ubik_SetLock(tt, 1, 1, LOCKREAD);
- if (code)
- ABORT_WITH(tt, code);
- code = read_DbHeader(tt);
- if (code)
- ABORT_WITH(tt, code);
{
afs_int32 uloc = FindByID(tt, uid);
afs_int32 hostid;
int size = 0, i, code;
int added = 0;
+ char hoststr[16];
while ((host = (host & wild))) {
wild = htonl(ntohl(wild) << 8);
iaddr.s_addr = host;
- code = NameToID(tt, inet_ntoa(iaddr), &hostid);
+ code = NameToID(tt, afs_inet_ntoa_r(iaddr.s_addr, hoststr), &hostid);
if (code == PRSUCCESS && hostid != 0) {
temp = FindByID(tt, hostid);
if (temp) {
WhoIsThisWithName(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid,
char *aname)
{
- int foreign = 0;
+ afs_int32 islocal = 1;
/* aid is set to the identity of the caller, if known, else ANONYMOUSID */
/* returns -1 and sets aid to ANONYMOUSID on any failure */
struct rx_connection *tconn;
else if (code == 1) { /* vab class */
goto done; /* no longer supported */
} else if (code == 2) { /* kad class */
- if ((code = rxkad_GetServerInfo(acall->conn, NULL, NULL,
+ if ((code = rxkad_GetServerInfo(rx_ConnectionOf(acall), NULL, NULL,
name, inst, tcell, NULL)))
goto done;
- if (tcell[0])
- foreign = afs_is_foreign_ticket_name(name, inst, tcell,
- pr_realmName);
-
+ if (tcell[0]) {
+ code = afsconf_IsLocalRealmMatch(prdir, &islocal, name, inst, tcell);
+ if (code)
+ goto done;
+ }
strncpy(vname, name, sizeof(vname));
if ((ilen = strlen(inst))) {
if (strlen(vname) + 1 + ilen >= sizeof(vname))
strcat(vname, ".");
strcat(vname, inst);
}
- if (foreign) {
+ if (!islocal) {
if (strlen(vname) + strlen(tcell) + 1 >= sizeof(vname))
goto done;
strcat(vname, "@");