File: local.c

package info (click to toggle)
radiusclient 0.3.2-11.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,036 kB
  • ctags: 468
  • sloc: sh: 4,806; ansic: 3,645; perl: 258; makefile: 130
file content (88 lines) | stat: -rw-r--r-- 2,241 bytes parent folder | download | duplicates (6)
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
/*
 * $Id: local.c,v 1.2 1997/12/25 23:28:54 lf Exp $
 *
 * Copyright (C) 1996 Lars Fenneberg
 *
 * See the file COPYRIGHT for the respective terms and conditions. 
 * If the file is missing contact me at lf@elemental.net 
 * and I'll send you a copy.
 *
 */

#include <config.h>
#include <includes.h>
#include <radiusclient.h>
#include <messages.h>
#include <radlogin.h>

#ifdef HAVE_SHADOW_PASSWORDS
#include <shadow.h>
#endif /* HAVE_SHADOW_PASSWORDS */

extern ENV *env;

LFUNC auth_local(char *username, char *passwd)
{
	struct passwd	*pw;
	char		*xpasswd;
#ifdef HAVE_SHADOW_PASSWORDS
	struct spwd	*spw;
#endif

	if ((pw = getpwnam(username)) == NULL) {
		endpwent();
		rc_log(LOG_NOTICE, "authentication FAILED, type local, username %s", username);
		printf(SC_LOCAL_FAILED);
		return NULL;
	}
	endpwent();
	
#ifdef HAVE_SHADOW_PASSWORDS
        if((spw = getspnam(pw->pw_name)) == NULL) {
			endspent();
			rc_log(LOG_NOTICE, "authentication FAILED, type local, username %s", username);
			printf(SC_LOCAL_FAILED);
			return NULL;
        }
        else 
        { 
        	pw->pw_passwd = spw->sp_pwdp; 
        }
        endspent();
#endif /* HAVE_SHADOW_PASSWORDS */

	xpasswd = crypt(passwd, pw->pw_passwd);
	
	if (*pw->pw_passwd == '\0' || strcmp(xpasswd, pw->pw_passwd)) {
		rc_log(LOG_NOTICE, "authentication FAILED, type local, username %s", username);
		printf(SC_LOCAL_FAILED);
		return NULL;		
	}

	rc_log(LOG_NOTICE, "authentication OK, type local, username %s", username);
	printf(SC_LOCAL_OK);
	
	return local_login;
}

void
local_login(char *username)
{
	char *login_local = rc_conf_str("login_local");

	/* login should spot this... but who knows what old /bin/logins
	 * may be still around
	 */
	if (*username == '-') {
		rc_log(LOG_WARNING, "username can't start with a dash");
		exit(ERROR_RC);
	}
	/* the new shadow login seems to require either a -r or a -h
	 * flag for -f to work (so source code, lmain.c) so we supply
	 * it here. shouldn't hurt on other systems,	-lf, 03/13/96
	 */
	execle(login_local, login_local, "-h", "localhost", "-f", username, NULL, env->env);
	rc_log(LOG_ERR, "couldn't execute %s: %s", login_local, strerror(errno));
	sleep(1);	/* give the user time to read */
	exit(ERROR_RC);
}