Deleted Added
sdiff udiff text old ( 76751 ) new ( 81965 )
full compact
1/* $FreeBSD: head/contrib/telnet/libtelnet/sra.c 81965 2001-08-20 12:28:40Z markm $ */
2
3#ifdef SRA
4#include <sys/types.h>
5#include <arpa/telnet.h>
6#include <stdio.h>
7#ifdef __STDC__
8#include <stdlib.h>
9#endif
10#ifdef NO_STRING_H
11#include <strings.h>
12#else
13#include <string.h>
14#endif
15
16#if !defined(NOPAM)
17#include <security/pam_appl.h>
18#else
19#include <unistd.h>
20#endif
21
22#include <pwd.h>
23#include <syslog.h>
24#include <ttyent.h>
25
26#include "auth.h"
27#include "misc.h"
28#include "encrypt.h"
29#include "pk.h"
30
31char pka[HEXKEYBYTES+1], ska[HEXKEYBYTES+1], pkb[HEXKEYBYTES+1];
32char *user,*pass,*xuser,*xpass;
33DesData ck;
34IdeaData ik;
35
36extern int auth_debug_mode;
37extern char *line;
38
39static int sra_valid = 0;
40static int passwd_sent = 0;
41
42static unsigned char str_data[1024] = { IAC, SB, TELOPT_AUTHENTICATION, 0,
43 AUTHTYPE_SRA, };
44
45#define SRA_KEY 0
46#define SRA_USER 1
47#define SRA_CONTINUE 2
48#define SRA_PASS 3
49#define SRA_ACCEPT 4
50#define SRA_REJECT 5
51
52static int check_user(const char *, const char *);
53
54/* support routine to send out authentication message */
55static int
56Data(Authenticator *ap, int type, void *d, int c)
57{
58 unsigned char *p = str_data + 4;
59 unsigned char *cd = (unsigned char *)d;
60
61 if (c == -1)
62 c = strlen((char *)cd);
63
64 if (auth_debug_mode) {

--- 13 unchanged lines hidden (view full) ---

78 }
79 *p++ = IAC;
80 *p++ = SE;
81 if (str_data[3] == TELQUAL_IS)
82 printsub('>', &str_data[2], p - (&str_data[2]));
83 return(net_write(str_data, p - str_data));
84}
85
86int
87sra_init(Authenticator *ap, int server)
88{
89 if (server)
90 str_data[3] = TELQUAL_REPLY;
91 else
92 str_data[3] = TELQUAL_IS;
93
94 user = (char *)malloc(256);
95 xuser = (char *)malloc(513);

--- 6 unchanged lines hidden (view full) ---

102
103 passwd_sent = 0;
104
105 genkeys(pka,ska);
106 return(1);
107}
108
109/* client received a go-ahead for sra */
110int
111sra_send(Authenticator *ap)
112{
113 /* send PKA */
114
115 if (auth_debug_mode)
116 printf("Sent PKA to server.\r\n" );
117 printf("Trying SRA secure login:\r\n");
118 if (!Data(ap, SRA_KEY, (void *)pka, HEXKEYBYTES)) {
119 if (auth_debug_mode)
120 printf("Not enough room for authentication data\r\n");
121 return(0);
122 }
123
124 return(1);
125}
126
127/* server received an IS -- could be SRA KEY, USER, or PASS */
128void
129sra_is(Authenticator *ap, unsigned char *data, int cnt)
130{
131 int valid;
132 Session_Key skey;
133
134 if (cnt-- < 1)
135 goto bad;
136 switch (*data++) {
137

--- 74 unchanged lines hidden (view full) ---

212 printf("Unknown SRA option %d\r\n", data[-1]);
213 }
214bad:
215 Data(ap, SRA_REJECT, 0, 0);
216 sra_valid = 0;
217 auth_finished(ap, AUTH_REJECT);
218}
219
220/* client received REPLY -- could be SRA KEY, CONTINUE, ACCEPT, or REJECT */
221void
222sra_reply(Authenticator *ap, unsigned char *data, int cnt)
223{
224 extern char *telnet_gets();
225 char uprompt[256],tuser[256];
226 Session_Key skey;
227 int i;
228
229 if (cnt-- < 1)
230 return;

--- 82 unchanged lines hidden (view full) ---

313 return;
314 default:
315 if (auth_debug_mode)
316 printf("Unknown SRA option %d\r\n", data[-1]);
317 return;
318 }
319}
320
321int
322sra_status(Authenticator *ap, char *name, int level)
323{
324 if (level < AUTH_USER)
325 return(level);
326 if (UserNameRequested && sra_valid) {
327 strcpy(name, UserNameRequested);
328 return(AUTH_VALID);
329 } else
330 return(AUTH_USER);
331}
332
333#define BUMP(buf, len) while (*(buf)) {++(buf), --(len);}
334#define ADDC(buf, len, c) if ((len) > 0) {*(buf)++ = (c); --(len);}
335
336void
337sra_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
338{
339 char lbuf[32];
340 register int i;
341
342 buf[buflen-1] = '\0'; /* make sure its NULL terminated */
343 buflen -= 1;
344
345 switch(data[3]) {

--- 47 unchanged lines hidden (view full) ---

393}
394
395struct passwd *pw;
396
397/*
398 * Helper function for sgetpwnam().
399 */
400char *
401sgetsave(char *s)
402{
403 char *new = malloc((unsigned) strlen(s) + 1);
404
405 if (new == NULL) {
406 return(NULL);
407 }
408 (void) strcpy(new, s);
409 return (new);
410}
411
412struct passwd *
413sgetpwnam(char *name)
414{
415 static struct passwd save;
416 register struct passwd *p;
417 char *sgetsave();
418
419 if ((p = getpwnam(name)) == NULL)
420 return (p);
421 if (save.pw_name) {

--- 22 unchanged lines hidden (view full) ---

444 free(save.pw_passwd);
445 save.pw_passwd = sgetsave(sp->sp_pwdp);
446 }
447#endif
448 return (&save);
449}
450
451static int
452isroot(const char *user)
453{
454 struct passwd *pw;
455
456 if ((pw=getpwnam(user))==NULL)
457 return 0;
458 return (!pw->pw_uid);
459}
460
461static int
462rootterm(char *ttyn)
463{
464 struct ttyent *t;
465
466 return ((t = getttynam(ttyn)) && t->ty_status & TTY_SECURE);
467}
468
469#ifdef NOPAM
470static int
471check_user(const char *name, const char *pass)
472{
473 register char *cp;
474 char *xpasswd, *salt;
475
476 if (isroot(name) && !rootterm(line))
477 {
478 crypt("AA","*"); /* Waste some time to simulate success */
479 return(0);

--- 29 unchanged lines hidden (view full) ---

509#define COPY_STRING(s) (s ? strdup(s):NULL)
510
511struct cred_t {
512 const char *uname;
513 const char *pass;
514};
515typedef struct cred_t cred_t;
516
517int
518auth_conv(int num_msg, const struct pam_message **msg,
519 struct pam_response **resp, void *appdata)
520{
521 int i;
522 cred_t *cred = (cred_t *) appdata;
523 struct pam_response *reply =
524 malloc(sizeof(struct pam_response) * num_msg);
525

--- 25 unchanged lines hidden (view full) ---

551
552 *resp = reply;
553 return PAM_SUCCESS;
554}
555
556/*
557 * The PAM version as a side effect may put a new username in *name.
558 */
559static int
560check_user(const char *name, const char *pass)
561{
562 pam_handle_t *pamh = NULL;
563 const void *item;
564 int rval;
565 int e;
566 cred_t auth_cred = { name, pass };
567 struct pam_conv conv = { &auth_conv, &auth_cred };
568
569 e = pam_start("telnetd", name, &conv, &pamh);
570 if (e != PAM_SUCCESS) {

--- 27 unchanged lines hidden (view full) ---

598 *
599 * This is supported by two various mechanisms in the
600 * individual modules. However, from the application's
601 * point of view, the template user is always passed
602 * back as a changed value of the PAM_USER item.
603 */
604 if ((e = pam_get_item(pamh, PAM_USER, &item)) ==
605 PAM_SUCCESS) {
606 strcpy((char *) name, (const char *) item);
607 } else
608 syslog(LOG_ERR, "Couldn't get PAM_USER: %s",
609 pam_strerror(pamh, e));
610 if (isroot(name) && !rootterm(line))
611 rval = 0;
612 else
613 rval = 1;
614 break;

--- 24 unchanged lines hidden ---