|
|
1.1 root 1: #ifndef lint
2: static char *rcsid = "$Header: xnscreds.c,v 1.2 87/07/28 08:41:13 ed Exp $";
3: #endif lint
4:
5: /*
6: * Copyright (c) 1986, 1987 Xerox Corporation.
7: */
8:
9: /*
10: * $Log: xnscreds.c,v $
11: * Revision 1.2 87/07/28 08:41:13 ed
12: * fprintf to stderr not stdin (how did it work?).
13: *
14: * Revision 1.1 87/03/17 16:28:14 ed
15: * Initial revision
16: *
17: *
18: */
19:
20: #include <stdio.h>
21: #include <xnscourier/Authentication2.h>
22:
23: int authenticate= 0;
24: int verbose= 0;
25:
26: main(argc, argv)
27: int argc;
28: char *argv[];
29: {
30: char name[128];
31: char *pwd, *cp;
32: char *getXNSpass(), *getenv(), *index();
33: Cardinal passwd, buffer;
34: int csh, i;
35: FILE *tty, *fopen();
36: Authentication2_Credentials credentials;
37: Authentication2_Verifier verifier;
38: Authentication2_ThreePartName defaultobjname, username;
39: Authentication2_ThreePartName CH_StringToName();
40:
41: static char *options= "av";
42: static char *usage= "Usage: %s [-a] [-v]\n";
43:
44: extern int optind;
45: extern char *optarg;
46: int opt;
47:
48: if ( !isatty(fileno(stdin)) ) {
49: fprintf(stderr, "\nMust be run from terminal\n");
50: exit(1);
51: }
52:
53: if ( argc > 3 ) {
54: fprintf(stderr, usage, argv[0]);
55: exit(1);
56: }
57:
58: while ( (opt= getopt(argc, argv, options)) != EOF ) {
59: switch (opt) {
60: case 'a' :
61: authenticate++;
62: break;
63: case 'v' :
64: verbose++;
65: break;
66:
67: default :
68: fprintf(stderr, "Invalid command option -%c\n", opt);
69: exit(1);
70: }
71: }
72:
73: if ( (tty= fopen("/dev/tty", "r+")) == NULL ) {
74: tty= stdin;
75: } else {
76: setbuf(tty, (char *)NULL);
77: }
78: fprintf(stderr, "Enter XNS name: ");
79: fgets(name, sizeof(name), tty);
80: if ( (cp= index(name, '\n')) )
81: *cp= '\0';
82:
83: pwd= getXNSpass("Enter XNS password: ");
84: fclose(tty);
85:
86: CH_NameDefault(&defaultobjname);
87: username= CH_StringToName(name, &defaultobjname);
88: MakeSimpleCredsAndVerifier(&username, pwd, &credentials, &verifier, 0);
89:
90: if ( authenticate ) {
91: if ( verbose ) {
92: fprintf(stderr, "Validating XNS credentials\n");
93: }
94:
95: if ( !Auth_CredCheck(credentials, verifier) ) {
96: fprintf(stderr, "Invalid XNS credentials\n");
97: exit(1);
98: }
99: }
100:
101: passwd= verifier.sequence[0];
102:
103: csh= 0;
104:
105: if ( (cp= getenv("SHELL")) && (i= strlen(cp)) >= 3 ) {
106: csh= (strcmp(&cp[i-3], "csh") ? 0 : 1);
107: }
108:
109: if ( !csh )
110: fprintf(stdout, "export XNSNAME XNSPASSWD\n");
111: else
112: fprintf(stdout, "set noglob;\n");
113:
114: if ( csh ) {
115: fprintf(stdout, "setenv XNSNAME %s ;\n", name);
116: fprintf(stdout, "setenv XNSPASSWD %d ;\n", passwd);
117: fprintf(stdout, "unset noglob;\n");
118: } else {
119: fprintf(stdout, "XNSNAME=%s ;\n", name);
120: fprintf(stdout, "XNSPASSWD=%d ;\n", passwd);
121: }
122:
123: }
124:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.