2 * $Id: radlogin.c,v 1.1 2002/01/22 16:03:04 dfs Exp $
4 * Copyright (C) 1995,1996 Lars Fenneberg
6 * See the file COPYRIGHT for the respective terms and conditions.
7 * If the file is missing contact me at lf@elemental.net
8 * and I'll send you a copy.
13 "$Id: radlogin.c,v 1.1 2002/01/22 16:03:04 dfs Exp $";
17 #include <radiusclient.h>
19 #include <pathnames.h>
23 static char *pname = NULL;
28 fprintf(stderr, SC_TIMEOUT, rc_conf_int("login_timeout"));
34 login_allowed(char *tty)
40 strcpy(fname, rc_conf_str("nologin"));
41 if (access(fname, F_OK) < 0) {
43 sprintf(fname, "%s.%s", rc_conf_str("nologin"), tty);
44 if (access(fname, F_OK) < 0)
51 if ((fp = fopen(fname, "r")) != NULL)
53 while ((c = fgetc(fp)) != EOF)
68 subst_placeholders(char *str, char *tty)
71 static char buf[4096];
72 #if defined(HAVE_UNAME)
75 #if !defined(HAVE_STRUCT_UTSNAME_DOMAINNAME) && defined(HAVE_GETDOMAINNAME)
79 #if defined(HAVE_UNAME)
102 #if defined(HAVE_UNAME)
104 strcpy(q, uts.sysname);
105 q += strlen(uts.sysname);
108 strcpy(q, uts.nodename);
109 q += strlen(uts.nodename);
112 strcpy(q, uts.release);
113 q += strlen(uts.release);
116 strcpy(q, uts.version);
117 q += strlen(uts.version);
120 strcpy(q, uts.machine);
121 q += strlen(uts.machine);
125 #if defined(HAVE_STRUCT_UTSNAME_DOMAINNAME)
126 strcpy(q, uts.domainname);
127 q += strlen(uts.domainname);
128 #elif defined(HAVE_GETDOMAINNAME)
129 getdomainname(domainname, sizeof(domainname));
130 strcpy(q, domainname);
131 q += strlen(domainname);
140 #if defined(HAVE_UNAME)
142 strcpy(q, uts.nodename);
143 q += strlen(uts.nodename);
166 fprintf(stderr,"Usage: %s [-Vhnd] [-f <config_file>] [-i <client_port>] [-m <login_tries>]\n\n", pname);
167 fprintf(stderr," -V output version information\n");
168 fprintf(stderr," -h output this text\n");
169 fprintf(stderr," -n don't display issue file\n");
170 fprintf(stderr," -f filename of alternate config file\n");
171 fprintf(stderr," -i ttyname to send to the server\n");
172 fprintf(stderr," -m maximum login tries (overrides value in config file)\n");
179 fprintf(stderr,"%s: %s\n", pname ,rcsid);
184 main (int argc, char **argv)
187 char passwd[AUTH_PASS_LEN + 1];
188 int tries, remaining, c;
190 void (*login_func)(char *);
197 char *path_radiusclient_conf = RC_CONFIG_FILE;
202 pname = (pname = strrchr(argv[0],'/'))?pname+1:argv[0];
206 while ((c = getopt(argc,argv,"f:m:i:nhV")) > 0)
210 path_radiusclient_conf = optarg;
219 maxtries = atoi(optarg);
233 if (rc_read_config(path_radiusclient_conf) != 0)
236 if (rc_read_dictionary(rc_conf_str("dictionary")) != 0)
239 if (rc_read_mapfile(rc_conf_str("mapfile")) != 0)
244 client_port = rc_map2id(ttyn);
246 if ((p = strrchr(ttyn, '/')) == NULL)
247 strncpy(tty, ttyn, sizeof(tty));
249 strncpy(tty, p+1, sizeof(tty));
256 if ((p = strrchr(ttyn, '/')) == NULL)
257 strncpy(tty, ttyn, sizeof(tty));
259 strncpy(tty, p+1, sizeof(tty));
261 client_port = rc_map2id(ttyn);
270 #ifdef SETVBUF_REVERSED
271 setvbuf(stdout, _IONBF, NULL, 0);
273 setvbuf(stdout, NULL, _IONBF, 0);
276 if ((argc - optind) == 1)
278 strncpy(username,argv[optind], sizeof(username));
285 if (rc_conf_str("issue") && ((fp = fopen(rc_conf_str("issue"), "r")) != NULL))
287 while (fgets(buf, sizeof(buf), fp) != NULL)
288 fputs(subst_placeholders(buf, tty), stdout);
293 fputs(subst_placeholders(SC_DEFAULT_ISSUE, tty), stdout);
299 if ((env = rc_new_env(ENV_SIZE)) == NULL)
301 rc_log(LOG_CRIT, "rc_new_env: FATAL: out of memory");
305 #ifdef SECURITY_DISABLED
306 if (rc_import_env(env,environ) < 0)
308 rc_log(LOG_CRIT, "rc_import_env: FATAL: not enough space for environment (increase ENV_SIZE)");
312 rc_add_env(env, "IFS", " ");
313 rc_add_env(env, "PATH", RC_SECURE_PATH);
316 signal(SIGALRM, alarm_handler);
318 remaining = rc_conf_int("login_timeout");
321 maxtries = rc_conf_int("login_tries");
324 while (tries <= maxtries)
329 p = rc_getstr (SC_LOGIN, 1);
331 strncpy(username, p, sizeof(username));
335 p = rc_getstr(SC_PASSWORD,0);
337 strncpy (passwd, p, sizeof (passwd));
341 remaining = alarm(0);
345 if (rc_conf_int("auth_order") & AUTH_LOCAL_FST)
347 login_func = auth_local(username, passwd);
350 if (rc_conf_int("auth_order") & AUTH_RADIUS_SND)
351 login_func = auth_radius(client_port, username, passwd);
355 login_func = auth_radius(client_port, username, passwd);
357 if (rc_conf_int("auth_order") & AUTH_LOCAL_SND)
358 login_func = auth_local(username, passwd);
361 memset(passwd, '\0', sizeof(passwd));
363 if (login_func != NULL)
364 if (login_allowed(tty)) {
365 (*login_func)(username);
373 if ((++tries) <= maxtries) {
376 remaining = alarm(0);
381 fprintf(stderr, SC_EXCEEDED);