summaryrefslogtreecommitdiffstats
path: root/lib/librpc/secure_rpc/demo/rme.c
blob: 773eafaf57930a59faafb22423f5ab9dc6c9ea15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = 	"@(#)rme.c	2.3 88/09/09 4.0 RPCSRC";
#endif
/*
 * rme.c: secure identity verifier and reporter: client side
 */
#include <rpc/rpc.h>
#include <stdio.h>
#include "whoami.h"

/*
 * Before running this program, the user must have a key in the publickey
 * database, and must have logged in with a password (or used keylogin).
 * The user's machine and the server's machine must both be running keyserv.
 */

main(argc, argv)
	int argc;
	char *argv[];
{
	CLIENT *cl;
	char *server;
	remote_identity *remote_me;
	name *servername;
	void *nullp;

	if (argc != 2) {
		fprintf(stderr, "usage: %s host\n", argv[0]);
		exit(1);
	}

	/*
	 * Remember what our command line argument refers to
	 */
	server = argv[1];

	/*
	 * Create client "handle" used for calling WHOAMI on the
	 * server designated on the command line. We tell the rpc package
	 * to use the "udp" protocol when contacting the server.
	 */
	cl = clnt_create(server, WHOAMI, WHOAMI_V1, "udp");
	if (cl == NULL) {
		/*
		 * Couldn't establish connection with server.
		 * Print error message and die.
		 */
		clnt_pcreateerror(server);
		exit(1);
	}
    /*
     * Get network identifier for server machine.
     */
    servername = whoami_whoru_1(nullp, cl);
    if (servername == NULL)
    {
        fprintf(stderr, "Trouble communicating with %s\n",
            clnt_sperror(cl, server));
        exit(1);
    }
    else if (*servername[0] == '\0')
    {
        fprintf(stderr, "Could not determine netname of WHOAMI server.\n");
        exit(1);
    }
    printf("Server's netname is: %s\n", *servername);

    /*
     * A wide window and no synchronization is used.  Client and server
     * clock must be with five minutes of each other.
     */
    if ((cl->cl_auth = authdes_create(*servername, 300, NULL, NULL)) == NULL)
    {
        fprintf(stderr, "Could not establish DES credentials of netname %s\n",
            servername);
        exit(1);
    }

    /*
     *  Find out who I am, in the server's point of view.
     */
    remote_me = whoami_iask_1(nullp, cl);
    if (remote_me == NULL)
    {
        fprintf(stderr, "Trouble getting my identity from %s\n",
            clnt_sperror(cl, server));
        exit(1);
    }
    /*
     * Print out my identity.
     */
    printf("My remote user name: %s\n", remote_me->remote_username);
    printf("My remote real name: %s\n", remote_me->remote_realname);

    exit(0);
}
OpenPOWER on IntegriCloud