#include <afs/afsutil.h>
#include <rx/rx.h>
#include <rx/xdr.h>
+#include <afs/afs_consts.h>
#include <afs/afscbint.h>
#include <afs/vldbint.h>
#include <afs/vlserver.h>
#include <des_prototypes.h>
#include <rx_prototypes.h>
#include "../rxkad/md5.h"
-#define MAXHOSTS 13
#ifdef O_LARGEFILE
#define afs_stat stat64
#define afs_fstat fstat64
struct cellLookup {
struct cellLookup *next;
struct afsconf_cell info;
- struct rx_securityClass *sc[3];
+ struct rx_securityClass *sc;
afs_int32 scIndex;
};
AFS_UNUSED
afs_int32
-HandleLocalAuth(struct rx_securityClass **sc[3], afs_int32 *scIndex)
+HandleLocalAuth(struct rx_securityClass **sc, afs_int32 *scIndex)
{
static struct afsconf_dir *tdir = NULL;
struct ktc_principal sname;
char *cell;
afs_int32 code;
+ *sc = NULL;
+ *scIndex = RX_SECIDX_NULL;
+
tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
if (!tdir) {
fprintf(stderr,"Could not open configuration directory: %s.\n",
AFSDIR_SERVER_ETC_DIRPATH);
return -1;
}
- cell = tdir->cellName;
- strcpy(sname.cell, cell);
- sname.instance[0] = 0;
- strcpy(sname.name, "afs");
- code=afsconf_GetLatestKey(tdir, &kvno, &key);
- if (code) {
- fprintf(stderr,"afsconf_GetLatestKey returned %d\n", code);
- return -1;
- }
- ttoken.kvno = kvno;
- des_init_random_number_generator(ktc_to_cblock(&key));
- code = des_random_key(ktc_to_cblock(&ttoken.sessionKey));
+ code = afsconf_ClientAuth(tdir, sc, &scIndex);
if (code) {
- fprintf(stderr,"des_random_key returned %d\n", code);
+ fprintf(stderr,"afsconf_ClientAuth returned %d\n", code);
return -1;
}
- ttoken.ticketLen = MAXKTCTICKETLEN;
- code = tkt_MakeTicket(ttoken.ticket, &ttoken.ticketLen, &key,
- AUTH_SUPERUSER, "", sname.cell,
- 0, 0xffffffff,
- &ttoken.sessionKey, host,
- sname.name, sname.instance);
- if (code)
- *scIndex = 0;
- else {
- *scIndex = 2;
- *sc[2] = (struct rx_securityClass *)
- rxkad_NewClientSecurityObject(rxkad_clear,
- &ttoken.sessionKey, ttoken.kvno,
- ttoken.ticketLen, ttoken.ticket);
- }
- if (*scIndex == 0)
- *sc[0] = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
return 0;
}
i++;
}
}
- for (; i<MAXHOSTS; i++) *h++ = 0;
+ for (; i<AFS_MAXHOSTS; i++) *h++ = 0;
return 0;
}
* offer it, and the FID.
*/
afs_int32
-get_file_cell(char *fn, char **cellp, afs_int32 hosts[MAXHOSTS], AFSFid *Fid,
+get_file_cell(char *fn, char **cellp, afs_int32 hosts[AFS_MAXHOSTS], AFSFid *Fid,
struct AFSFetchStatus *Status, afs_int32 create)
{
afs_int32 code;
int j;
afs_int32 *Tmpafs_int32;
- memset((char *) Status, 0, sizeof(struct AFSFetchStatus));
+ memset( Status, 0, sizeof(struct AFSFetchStatus));
memset(buf, 0, sizeof(buf));
status.in_size = 0;
status.out_size = sizeof(buf);
afs_com_err(pnp, code, (char *) 0);
} else {
Tmpafs_int32 = (afs_int32 *)buf;
- for (j=0;j<MAXHOSTS;++j) {
+ for (j=0;j<AFS_MAXHOSTS;++j) {
hosts[j] = Tmpafs_int32[j];
if (!Tmpafs_int32[j])
break;
afs_com_err(pnp, code, (char *) 0);
}
} else {
- afs_int32 saveCommand, saveVolume;
-
Tmpafs_int32 = (afs_int32 *)buf;
Fid->Volume = Tmpafs_int32[1];
Fid->Vnode = Tmpafs_int32[2];
Fid->Unique = Tmpafs_int32[3];
- status.in_size = sizeof(struct FsCmdInputs);
- status.out_size = sizeof(struct FsCmdOutputs);
- status.in = (char *) &PioctlInputs;
- status.out = (char *) &PioctlOutputs;
- saveCommand = PioctlInputs.command;
- saveVolume = PioctlInputs.fid.Volume;
- PioctlInputs.command = 0;
- PioctlInputs.fid.Volume = 0;
- if (!pioctl(fn, VIOC_FS_CMD, &status, 0))
- memcpy((char *)Status, &PioctlOutputs.status,
- sizeof(struct AFSFetchStatus));
- PioctlInputs.command = saveCommand;
- PioctlInputs.fid.Volume = saveVolume;
- if (create && (Status->Length || Status->Length_hi)) {
- fprintf(stderr,"AFS file %s not empty, request aborted.\n",
- fn);
- exit(-5);
- }
}
}
return code;
char *fname;
char *cell = 0;
afs_int32 code;
- afs_int32 hosts[MAXHOSTS];
+ afs_int32 hosts[AFS_MAXHOSTS];
AFSFid Fid;
int i, j;
struct rx_connection *RXConn;
return ENOENT;
}
cl = FindCell(cell);
- for (j=0;j<MAXHOSTS;++j) {
+ for (j=0;j<AFS_MAXHOSTS;++j) {
int useHost;
if (first && as->parms[6].items) {
}
first = 0;
RXConn = FindRXConnection(useHost, htons(AFSCONF_FILEPORT), 1,
- cl->sc[cl->scIndex], cl->scIndex);
+ cl->sc, cl->scIndex);
if (!RXConn) {
fprintf(stderr,"rx_NewConnection failed to server 0x%X\n",
useHost);
char *fname = NULL;
char *cell = 0;
afs_int32 code, localcode = 0;
- afs_int32 hosts[MAXHOSTS];
+ afs_int32 hosts[AFS_MAXHOSTS];
afs_uint32 useHost;
AFSFid Fid;
int i;
struct AFSVolSync tsync;
struct AFSFetchStatus OutStatus;
struct AFSStoreStatus InStatus;
+ struct AFSCallBack CallBack;
afs_int64 Pos;
afs_int64 length, Len, synthlength = 0, offset = 0;
u_char vnode = 0;
} else
code = get_file_cell(fname, &cell, hosts, &Fid, &OutStatus, append ? 0 : 1);
if (code) {
- if (code != -5)
- fprintf(stderr,"File or directory not found: %s\n",
+ fprintf(stderr,"File or directory not found: %s\n",
fname);
return code;
}
gettimeofday (&starttime, &Timezone);
useHost = hosts[0];
RXConn = FindRXConnection(useHost, htons(AFSCONF_FILEPORT), 1,
- cl->sc[cl->scIndex], cl->scIndex);
+ cl->sc, cl->scIndex);
if (!RXConn) {
fprintf(stderr,"rx_NewConnection failed to server 0x%X\n",
hosts[0]);
return -1;
}
+ code = AFS_FetchStatus(RXConn, &Fid, &OutStatus, &CallBack, &tsync);
+ if (code) {
+ fprintf(stderr,"RXAFS_FetchStatus failed to server 0x%X for file %s, code was%d\n",
+ useHost, fname, code);
+ return -1;
+ }
+ if (!append && (OutStatus.Length || OutStatus.Length_hi)) {
+ fprintf(stderr,"AFS file %s not empty, request aborted.\n", fname);
+ DestroyConnections();
+ return -5;
+ }
InStatus.Mask = AFS_SETMODE + AFS_FSYNC;
InStatus.UnixModeBits = 0644;
if (append) {
if (code = VLDBInit(1, &p->info))
fprintf(stderr,"VLDBInit failed for cell %s\n", p->info.name);
#endif
- strcpy((char *)&sname.cell, (char *)&p->info.name);
- sname.instance[0] = 0;
- strcpy(sname.name, "afs");
- code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), NULL);
- if (code)
- p->scIndex = 0;
- else {
- if ((ttoken.kvno >= 0) && (ttoken.kvno <= 255))
- /* this is a kerberos ticket, set scIndex accordingly */
- p->scIndex = 2;
- else {
- fprintf(stderr,"funny kvno (%d) in ticket, proceeding\n",
- ttoken.kvno);
- p->scIndex = 2;
- }
- p->sc[2] = (struct rx_securityClass *)
- rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey,
- ttoken.kvno, ttoken.ticketLen,
- ttoken.ticket);
- }
- if (p->scIndex == 0)
- p->sc[0] = (struct rx_securityClass *)
- rxnull_NewClientSecurityObject();
+ code = afsconf_ClientAuthToken(&p->info, 0, &p->sc, &p->scIndex);
+ if (code) {
+ p->scIndex = RX_SECIDX_NULL;
+ p->sc = rxnull_NewClientSecurityObject();
+ }
}
if (p)