Beispiel #1
0
static void HandleRPCFailure(long cid, long rcode, long op)
{

    ConnVector[cid].Status = BROKEN;

    if (rcode == RPC2_CONNBUSY)
	{
	connbusies++;
	return;
	}

    if (op == 7 && rcode == RPC2_NAKED)
	{
	lostunbinds++;
	assert(RPC2_Unbind(ConnVector[cid].ConnHandle) == RPC2_SUCCESS);
        FLUSH();
	return;
	}

    printf ("\n%s: call %ld on %#x to %s for %s failed (%s) at %s", MYNAME,
	op, ConnVector[cid].ConnHandle,
	ConnVector[cid].RemoteHost.Value.Name,
	ConnVector[cid].NameBuf, RPC2_ErrorMsg(rcode), TimeNow());
    DumpAndQuit(op);
}
Beispiel #2
0
int main(int argc, char *argv[])
{
    RPC2_Handle cid;
    long subsys = 1001;
    long rc;
    char *host;
    short port;

    if (argc == 1)
        goto badargs;

    if (strcmp(argv[1], "-p") == 0) {
        if (argc < 4)
            goto badargs;

        host = argv[3];
        port = atoi(argv[2]);
    } else {
        struct servent *s = coda_getservbyname("codasrv", "udp");
        host              = argv[1];
        port              = ntohs(s->s_port);
        subsys            = 1001; /* SUBSYS_SRV */
    }

    Initialize();

    rc = Bind(host, port, subsys, &cid);

    RPC2_Unbind(cid);

    if (rc != RPC2_SUCCESS) {
        printf("RPC2 connection to %s:%d failed with %s.\n", host, port,
               RPC2_ErrorMsg(rc));
        exit(EXIT_FAILURE);
    }

    printf("RPC2 connection to %s:%d successful.\n", host, port);
    exit(EXIT_SUCCESS);

badargs:
    printf("Usage %s [-p port] hostname\n", argv[0]);
    exit(EXIT_FAILURE);
}
Beispiel #3
0
int main(int argc, char **argv)
{
    register int i;
    char   *current;
    char   *next;
    char   *uid;
    char   *pw;
    int    rc;
    int    fd;
    struct stat    buff;
    char   *auid = 0;
    char   *apw = 0;
    char   *filenm = 0;
    char   *area = 0;
    RPC2_EncryptionKey	key;
    
 /* parse arguments    */
    for (i = 1; i < argc; i++) {
	if (argv[i][0] == '-') {
	    if (strcmp(argv[i], "-f") == 0) {
		filenm = argv[++i];
		continue;
	    }
	    break;
	}
	if (auid == 0) {
	    auid = argv[i];
	    continue;
	}
	if (apw == 0) {
	    apw = argv[i];
	    continue;
	}
	break;
    }

    if (!auid || !apw || !filenm) {
	printf("usage: newuser -f filename authuserid authpasswd\n");
	fflush(stdout);
	exit(-1);
    }
 /* Bind to auth server using auid and apw */

    U_InitRPC();
    memset(key, 0, sizeof(RPC2_EncryptionKey));
    strncpy(key, apw, sizeof(RPC2_EncryptionKey));
    rc = U_BindToServer(1, auid, key, &AuthID);
    if(rc != AUTH_SUCCESS) {
	printf("Bind to Auth Server failed %s\n",U_Error(rc));
	fflush(stdout);
	exit(-2);
    }

 /* open input file and read it into area malloc */
    if(stat(filenm, &buff)) {
	printf("Could not stat %s because %d\n",filenm, errno);
	fflush(stdout);
	exit(-3);
    }
    area = (char *)malloc(buff.st_size+1);
    fd = open(filenm, O_RDONLY, 0);
    if(fd <= 0) {
	printf("Could not open %s because %d\n",filenm, errno);
	fflush(stdout);
	exit(-4);
    }
    rc = read(fd, area, buff.st_size);
    if(rc != buff.st_size) {
	printf("Could nor read %s got %d bytes instead of %d, error = %d\n",
		filenm, rc, buff.st_size, errno);
	fflush(stdout);
	exit(-5);
    }
    close(fd);
    *(area+buff.st_size+1) = '\0';

 /* parse data in area and pass it to AddNewUser. The first field in each line is the
    uid, the second field in each line is the password. Fields are blank separated */

    for(current = area; current < area+buff.st_size; current = next) {
	next = NextRecord(current);	/* next line */
	uid = current;				/* use first field  */
	pw = NextField(uid);			/* use second field */
	MakeString(uid);			/* make uid a string */
	MakeString(pw);			/* make pw a string */
	AddNewUser(uid, pw);
    }

 /* clean up and Unbind the connection */
    if(area) free(area);
    RPC2_Unbind(AuthID);
    return(0);
}
Beispiel #4
0
static void ClientBody(void *arg)
{
    RPC2_Handle thisconn;
    RPC2_Integer thisopcode;
    RPC2_PacketBuffer *request, *reply;
    long retcode, rpctime = 0;
    struct timeval t1, t2;
    char myprivatefile[256];
    char myhashmark;
    RPC2_BindParms bp;
    SE_Descriptor sed;


#define MakeTimedCall(whichse)\
	if (VerboseFlag) gettimeofday(&t1, 0);\
	retcode = RPC2_MakeRPC(ConnVector[thisconn].ConnHandle, request, whichse, &reply, NULL, 0);\
	if (VerboseFlag) gettimeofday(&t2, 0);\
	if (VerboseFlag) rpctime = ((t2.tv_sec - t1.tv_sec)*1000) + ((t2.tv_usec - t1.tv_usec)/1000);


    memset(&sed, 0, sizeof(SE_Descriptor));
    sed.Tag = SMARTFTP;

    strcpy(myprivatefile, MakeName(LWP_Name()));
    myhashmark = NextHashMark++;

    LWP_DispatchProcess();	/* initial courtesy to parent */
    
    RPC2_AllocBuffer(1000, &request);
    reply = NULL;


    ClientsReady++;
    LWP_WaitProcess((char *)&ClientsReady);	/* wait for main() to tap me on shoulder */

    while(1)
	{
	if (reply) RPC2_FreeBuffer(&reply);

	RanDelay(MaxThinkTime);
	SelectParms(&thisconn, &thisopcode);
	ConnVector[thisconn].Status = BUSY;
	request->Header.Opcode = thisopcode;
	
	if (VerboseFlag)
	    fprintf(stderr, "Making request %d to %s for %s\n",
		    thisopcode,
		    ConnVector[thisconn].RemoteHost.Value.Name,
		    ConnVector[thisconn].NameBuf);

	switch(thisopcode)
	    {
	    case 1: /* return Unix epoch time */
		{
		request->Header.BodyLength = 0;
		MakeTimedCall(NULL);
		if (retcode == RPC2_SUCCESS)
		    {
		    if (VerboseFlag)
			fprintf(stderr, "Time on %s is %s (%ld msecs)\n",
				ConnVector[thisconn].RemoteHost.Value.Name,
				reply->Body, rpctime);
		    break;
		    }
		else HandleRPCFailure(thisconn, retcode, ntohl(request->Header.Opcode));
		}

	    case 2: /* square the input integer */
	    {
		uint32_t *op = (uint32_t *)request->Body;
		uint32_t x = (uint32_t)random() % 100;

		op[0] = htonl(x);
		request->Header.BodyLength = sizeof(uint32_t);

		MakeTimedCall(NULL);
		if (retcode == RPC2_SUCCESS)
		    {
		    if (VerboseFlag) {
			uint32_t *ip = (uint32_t *)reply->Body;
			fprintf(stderr, " %s says square of %u is %u (%ld msecs)\n",
				ConnVector[thisconn].RemoteHost.Value.Name, x,
				ntohl(ip[0]), rpctime);
		    }
		    break;
		    }
		else HandleRPCFailure(thisconn, retcode, ntohl(request->Header.Opcode));
		break;
	    }

	    case 3: /* cube the input integer */
	    {
		uint32_t *op = (uint32_t *)request->Body;
		uint32_t x = (uint32_t)random() % 100;

		op[0] = htonl(x);
		request->Header.BodyLength = sizeof(uint32_t);

		MakeTimedCall(NULL);
		if (retcode == RPC2_SUCCESS)
		    {
		    if (VerboseFlag) {
			uint32_t *ip = (uint32_t *)reply->Body;
			fprintf(stderr, "%s says cube of %d is %u (%ld msecs)\n",
				ConnVector[thisconn].RemoteHost.Value.Name, x,
				ntohl(ip[0]), rpctime);
		    }
		    break;
		    }
		else HandleRPCFailure(thisconn, retcode, ntohl(request->Header.Opcode));
		break;
	    }

	    case 4: /* Return your machine name */
		{
		request->Header.BodyLength = 0;
		MakeTimedCall(NULL);
		if (retcode == RPC2_SUCCESS)
		    {
		    if (VerboseFlag)
			fprintf(stderr, "%s says its name is \"%s\" (%ld msecs)\n",
				ConnVector[thisconn].RemoteHost.Value.Name,
				reply->Body, rpctime);
		    break;
		    }
		else HandleRPCFailure(thisconn, retcode, ntohl(request->Header.Opcode));
		break;
		}

	    case 5: /* Fetch a random file */
		{
		if (AvoidBulk)
		     {
		     ConnVector[thisconn].Status = SFREE;
		     continue;
		     }
		request->Header.BodyLength = 0;
		sed.Value.SmartFTPD.TransmissionDirection = SERVERTOCLIENT;
		sed.Value.SmartFTPD.FileInfo.ByName.ProtectionBits = 0644;
		sed.Value.SmartFTPD.SeekOffset = 0;
		sed.Value.SmartFTPD.Tag = FILEBYNAME;
		strcpy(sed.Value.SmartFTPD.FileInfo.ByName.LocalFileName, myprivatefile);
		if (VerboseFlag)
		    sed.Value.SmartFTPD.hashmark = myhashmark;
		else sed.Value.SmartFTPD.hashmark = 0;
		MakeTimedCall(&sed);
		if (retcode != RPC2_SUCCESS)
		    {
		    HandleRPCFailure(thisconn, retcode, ntohl(request->Header.Opcode));
		    break;		    
		    }
		else
		    if (VerboseFlag)
			fprintf(stderr, "%ld bytes transferred\n",
				sed.Value.SmartFTPD.BytesTransferred);

		break;
		}

	    case 6: /* Store a random file */
	    {
		uint32_t randval;
		if (AvoidBulk)
		     {
		     ConnVector[thisconn].Status = SFREE;
		     continue;
		     }
		request->Header.BodyLength = 0;
		sed.Value.SmartFTPD.TransmissionDirection = CLIENTTOSERVER;
		sed.Value.SmartFTPD.SeekOffset = 0;
		sed.Value.SmartFTPD.Tag = FILEBYNAME;
		randval = (uint32_t)random();
		strcpy(sed.Value.SmartFTPD.FileInfo.ByName.LocalFileName,
		       SysFiles[randval % SysFileCount]);
		if (VerboseFlag)
		    sed.Value.SmartFTPD.hashmark = myhashmark;
		else sed.Value.SmartFTPD.hashmark = 0;
		MakeTimedCall(&sed);
		if (retcode !=  RPC2_SUCCESS)
		{
		    HandleRPCFailure(thisconn, retcode, ntohl(request->Header.Opcode));
		    break;
		}
		else
		    if (VerboseFlag)
			fprintf(stderr, "%ld bytes transferred\n",
				sed.Value.SmartFTPD.BytesTransferred);
		break;
	    }

	    case 7:   /* Unbind */
		{
		request->Header.BodyLength = 0;
		MakeTimedCall(NULL);
		if (retcode == RPC2_SUCCESS)
		    {
		    if (VerboseFlag)
			fprintf(stderr, "Unbound connection to %s for %s after %ld calls\n",
				ConnVector[thisconn].RemoteHost.Value.Name,
				ConnVector[thisconn].Identity.SeqBody,
				ConnVector[thisconn].CallsMade);
		    assert(RPC2_Unbind(ConnVector[thisconn].ConnHandle) == RPC2_SUCCESS);
		    }
		else
		    {HandleRPCFailure(thisconn, retcode, ntohl(request->Header.Opcode));}
		ConnVector[thisconn].Status = UNBOUND;
		break;
		}


	    case 8:	/* Rebind */
		{
		bp.SecurityLevel = ConnVector[thisconn].SecurityLevel;
		bp.EncryptionType = RPC2_XOR;
		bp.SideEffectType = SMARTFTP;
		bp.ClientIdent = &ConnVector[thisconn].Identity;
		bp.SharedSecret = &ConnVector[thisconn].Password;
		retcode = RPC2_NewBinding(&ConnVector[thisconn].RemoteHost,
					  &PortId, &SubsysId, &bp,
					  &ConnVector[thisconn].ConnHandle);
		if (retcode < RPC2_ELIMIT)
		    {
		    HandleRPCFailure(thisconn, retcode, ntohl(request->Header.Opcode));
		    }
		else
		    {
		    if (VerboseFlag)
			fprintf(stderr, "Rebound connection to %s for %s\n",
				ConnVector[thisconn].RemoteHost.Value.Name,
				ConnVector[thisconn].Identity.SeqBody);
		    }
		break;
		}



	    case 999: /* Quit */
		{
		}

	    default: /* unknown opcode */
		printf("Arrrgggghhh .... bogus opcode\n"); abort();
		break;
	    }
	
	if (ConnVector[thisconn].Status == BUSY) ConnVector[thisconn].Status = SFREE;
	if (retcode == RPC2_CONNBUSY) continue; /* you didn't really do it */

	/* Indicate progress  */
	ConnVector[thisconn].CallsMade++;
	if(ConnVector[thisconn].CallsMade % Announce == 1)
	    {
	    struct CVEntry *ce = &ConnVector[thisconn];
	    printf("\n%ld successful calls to %s for %s at %s", ce->CallsMade,
		ce->RemoteHost.Value.Name, ce->NameBuf, TimeNow());
	    PrintStats();
	    }
	else
	    {
	    int xx;
	    xx = (1.0*Announce)/100.0 + 0.5; /* ceiling */
	    if (xx == 0 || ConnVector[thisconn].CallsMade % xx == 1)
		printf("%c", myhashmark);
	    }
	
	}

}
Beispiel #5
0
static void WorkerBody(void *arg)
{
    long i, rc;
    RPC2_RequestFilter reqfilter;
    RPC2_PacketBuffer *InBuff, *OutBuff;
    RPC2_Handle workercid;
    char myprivatefile[256];
    char myhashmark;
    SE_Descriptor sed;


    memset(&sed, 0, sizeof(SE_Descriptor));
    sed.Tag = SMARTFTP;

    strcpy(myprivatefile, MakeName(LWP_Name()));
    myhashmark = NextHashMark++;

    LWP_DispatchProcess();	/* initial courtesy to parent */

    reqfilter.FromWhom = ONESUBSYS;
    reqfilter.ConnOrSubsys.SubsysId = SUBSYS_SRV;
    assert(reqfilter.ConnOrSubsys.SubsysId != -1);
    reqfilter.OldOrNew = OLD;

    RPC2_AllocBuffer(1000, &OutBuff);
    InBuff = NULL;

    while (1)
	{
	RanDelay(MaxComputeTime);

	if (InBuff != NULL) RPC2_FreeBuffer(&InBuff);
	i = RPC2_GetRequest(&reqfilter, &workercid, &InBuff, NULL, NULL, 0, NULL);
	if (i != RPC2_SUCCESS)
	    {
	    printf("\n%s: GetRequest failed (%s) at %s", MYNAME, RPC2_ErrorMsg(i), TimeNow());
	    DumpAndQuit(0);
	    }
	
	switch(InBuff->Header.Opcode)
	    {
	    case 1: /* return Unix epoch time */
		{
		strcpy((char *)OutBuff->Body, TimeNow());
		OutBuff->Header.ReturnCode = RPC2_SUCCESS;
		OutBuff->Header.BodyLength = sizeof(struct RPC2_PacketHeader) + strlen((char *)OutBuff->Body) + 1;
		break;
		}
		
	    case 2: /* square the input integer */
		{
		uint32_t *ip = (uint32_t *)InBuff->Body;
		uint32_t *op = (uint32_t *)OutBuff->Body;
		uint32_t x = ntohl(*ip);

		*op = htonl(x * x);
		OutBuff->Header.ReturnCode = RPC2_SUCCESS;
		OutBuff->Header.BodyLength = sizeof(RPC2_Integer);
		break;
		}
	    
	    case 3: /* cube the input integer */
		{
		uint32_t *ip = (uint32_t *)InBuff->Body;
		uint32_t *op = (uint32_t *)OutBuff->Body;
		uint32_t x = ntohl(*ip);

		*op = htonl(x*x*x);
		OutBuff->Header.ReturnCode = RPC2_SUCCESS;
		OutBuff->Header.BodyLength = sizeof(RPC2_Integer);
		break;
		}

	    case 4: /* Return your machine name */
		{
		gethostname((char *)OutBuff->Body, 100);
		OutBuff->Header.ReturnCode = RPC2_SUCCESS;
		OutBuff->Header.BodyLength = strlen((char *)OutBuff->Body) + 1;
		break;
		}

	    case 5: /* Fetch a random file */
	    {
		uint32_t randval;
		if (VerboseFlag) sed.Value.SmartFTPD.hashmark = myhashmark;
		else sed.Value.SmartFTPD.hashmark = 0;
		randval = (uint32_t)random();
		strcpy(sed.Value.SmartFTPD.FileInfo.ByName.LocalFileName,
		       SysFiles[randval % SysFileCount]);
		sed.Value.SmartFTPD.TransmissionDirection = SERVERTOCLIENT;
		sed.Value.SmartFTPD.SeekOffset = 0;
		sed.Value.SmartFTPD.Tag = FILEBYNAME;

		if ((rc = RPC2_InitSideEffect(workercid, &sed)) != RPC2_SUCCESS)
		    {
		    BulkErr(workercid, &sed, rc, InBuff->Header.Opcode);
		    assert(RPC2_Unbind(workercid) == RPC2_SUCCESS);
		    continue;
		    }
		if ((rc = RPC2_CheckSideEffect(workercid, &sed, SE_AWAITLOCALSTATUS)) != RPC2_SUCCESS)
			{
			BulkErr(workercid, &sed, rc, InBuff->Header.Opcode);
			assert(RPC2_Unbind(workercid) == RPC2_SUCCESS);
			continue;
			}
		else
		    if (VerboseFlag)
			fprintf(stderr, "%ld bytes transferred\n",
				sed.Value.SmartFTPD.BytesTransferred);
		OutBuff->Header.ReturnCode = (long)sed.LocalStatus;
		OutBuff->Header.BodyLength = 0;
		break;
	    }

	    case 6: /* Store a random file */
		{
		if (VerboseFlag) sed.Value.SmartFTPD.hashmark = myhashmark;
		else sed.Value.SmartFTPD.hashmark = 0;
		strcpy(sed.Value.SmartFTPD.FileInfo.ByName.LocalFileName, myprivatefile);
		sed.Value.SmartFTPD.FileInfo.ByName.ProtectionBits = 0644;
		sed.Value.SmartFTPD.TransmissionDirection = CLIENTTOSERVER;
		sed.Value.SmartFTPD.SeekOffset = 0;
		sed.Value.SmartFTPD.Tag = FILEBYNAME;
		
		if ((rc = RPC2_InitSideEffect(workercid, &sed)) != RPC2_SUCCESS)
			{
			BulkErr(workercid, &sed, rc, InBuff->Header.Opcode);
			}
		if ((rc = RPC2_CheckSideEffect(workercid, &sed, SE_AWAITLOCALSTATUS)) != RPC2_SUCCESS)
			{
			BulkErr(workercid, &sed, rc, InBuff->Header.Opcode);
			}
		else
		    if (VerboseFlag)
			fprintf(stderr, "%ld bytes transferred\n",
				sed.Value.SmartFTPD.BytesTransferred);
		OutBuff->Header.ReturnCode = (long)sed.LocalStatus;
		OutBuff->Header.BodyLength = 0;
		break;
		}

	    case 7:	/* Unbind */
		{
		OutBuff->Header.ReturnCode = RPC2_SUCCESS;
		OutBuff->Header.BodyLength = 0;
		break;
		}

	    case 999: /* Quit */
		{
		OutBuff->Header.ReturnCode = RPC2_SUCCESS;
		OutBuff->Header.BodyLength = 0;
		break;
		}

	    default: /* unknown opcode */
		OutBuff->Header.ReturnCode = RPC2_FAIL;
		OutBuff->Header.BodyLength = 1 + strlen("Get your act together");
		strcpy((char *)OutBuff->Body, "Get your act together");
	    break;
	    }


	i = RPC2_SendResponse(workercid, OutBuff);
	if (i != RPC2_SUCCESS) 
	    {
	    printf ("\n%s: response for opcode %d on connection %#x  failed (%s) at %s", 
		MYNAME,	InBuff->Header.Opcode, workercid,
		RPC2_ErrorMsg(i), TimeNow());
	    DumpAndQuit(InBuff->Header.Opcode);
	    }
	if (InBuff->Header.Opcode == 7)
	    assert(RPC2_Unbind(workercid) == RPC2_SUCCESS);
	}
}
Beispiel #6
0
/* Talks to an authentication server and obtains tokens on behalf of user uName.
   Gets back the viceId and clear and secretTokens for this user    */
int U_Authenticate(struct RPC2_addrinfo *srvs, const int AuthenticationType,
		   const char *uName, const int uNamelen,
		   OUT ClearToken *cToken, 
		   OUT EncryptedSecretToken sToken, 
		   const int verbose, const int interactive)
{
	RPC2_Handle	RPCid;
	int		rc = 0;
	int             bound = 0;
	char            passwd[128];
	int		secretlen;

	memset(passwd, 0, sizeof(passwd));

	switch(AuthenticationType) {
	case AUTH_METHOD_CODAUSERNAME:
		if (!interactive) {
			fgets(passwd, sizeof(passwd), stdin);
			rc = strlen(passwd);
			if ( passwd[rc-1] == '\n' )
				passwd[rc-1] = 0;
		} else {
			strncpy (passwd, getpass ("Password: "******"Cannot initialize KRB5\n");
			exit(1);
		}
		/* actual secret recovery is done in U_BindToServer */
		break;
#endif
	default:
		fprintf(stderr, "Unsupported authentication type\n");
		exit(1);
	}
			
	if (rc)
		return rc;

	secretlen = strlen(passwd);
	rc = U_BindToServer(srvs, AuthenticationType, uName, uNamelen,
			    passwd, secretlen, &RPCid, interactive);
	if(rc == 0) {
		bound = 1;
		rc = AuthGetTokens(RPCid, sToken, cToken);
		if ( rc >= 0 ) 
			/* return irrelevant */
			AuthQuit(RPCid);
	}

        if (bound)
		RPC2_Unbind(RPCid);

	return(rc);
}