utmp and some environment stuff

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@4062 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1997-11-29 00:52:11 +00:00
parent 87167acf87
commit aac2ad0deb
8 changed files with 118 additions and 39 deletions

View File

@@ -5,7 +5,7 @@ AUTOMAKE_OPTIONS = no-dependencies foreign
INCLUDES = -I$(top_builddir)/include $(INCLUDE_krb4)
bin_PROGRAMS = login
login_SOURCES = login.c read_string.c
login_SOURCES = login.c read_string.c utmp_login.c utmpx_login.c tty.c stty_default.c
LDADD = $(top_builddir)/lib/krb5/libkrb5.a \
$(top_builddir)/lib/des/libdes.a \

View File

@@ -71,6 +71,14 @@ add_env(const char *var, const char *value)
extend_env(str);
}
void
copy_env(void)
{
char **p;
for(p = environ; *p; p++)
extend_env(*p);
}
void
exec_shell(const char *shell, int fallback)
{
@@ -93,11 +101,61 @@ exec_shell(const char *shell, int fallback)
err(1, "%s", shell);
}
int f_flag;
int p_flag;
int r_flag;
int version_flag;
int help_flag;
char *remote_host;
struct getargs args[] = {
#if 0
{ NULL, 'a' },
{ NULL, 'd' },
#endif
{ NULL, 'f', arg_flag, &f_flag, "pre-authenticated" },
{ NULL, 'h', arg_string, &remote_host, "remote host", "hostname" },
{ NULL, 'p', arg_flag, &p_flag, "don't purge environment" },
#if 0
{ NULL, 'r', arg_flag, &r_flag, "rlogin protocol" },
#endif
{ "version", 0, arg_flag, &version_flag },
{ "help", 'h', arg_flag,&help_flag, }
};
int nargs = sizeof(args) / sizeof(args[0]);
void
update_utmp(const char *username, const char *hostname)
{
char *tty, *ttyn, ttname[32];
ttyn = ttyname(STDIN_FILENO);
if(ttyn == NULL){
snprintf(ttname, sizeof(ttname), "%s??", _PATH_TTY);
ttyn = ttname;
}
if((tty = strrchr(ttyn, '/')))
tty++;
else
tty = ttyn;
/*
* Update the utmp files, both BSD and SYSV style.
*/
if (utmpx_login(tty, username, hostname) != 0 && !f_flag) {
printf("No utmpx entry. You must exec \"login\" from the "
"lowest level shell.\n");
exit(1);
}
utmp_login(ttyn, username, hostname);
}
void
do_login(struct passwd *pwd)
{
int rootlogin = (pwd->pw_uid == 0);
update_utmp();
update_utmp(pwd->pw_name, remote_host ? remote_host : "");
#ifdef HAVE_SETLOGIN
if(setlogin(pwd->pw_name)){
warn("setlogin(%s)", pwd->pw_name);
@@ -135,6 +193,7 @@ do_login(struct passwd *pwd)
exec_shell(pwd->pw_shell, rootlogin);
}
#ifdef KRB5
int
krb5_verify(struct passwd *pwd, const char *password)
{
@@ -185,6 +244,7 @@ krb5_verify(struct passwd *pwd, const char *password)
krb5_free_context(context);
return ret;
}
#endif
int
check_password(struct passwd *pwd, const char *password)
@@ -209,33 +269,10 @@ check_password(struct passwd *pwd, const char *password)
return 1;
}
int f_flag;
int p_flag;
int r_flag;
int version_flag;
int help_flag;
char *remote_host;
struct getargs args[] = {
#if 0
{ NULL, 'a' },
{ NULL, 'd' },
#endif
{ "authenticated", 'f', arg_flag, &f_flag, "don't authenticate" },
{ "host", 'h', arg_string, &remote_host, "remote host", "hostname" },
{ "preserve-environment", 'p', arg_flag, &p_flag,
"don't purge environment" },
{ NULL, 'r', arg_flag, &r_flag, "foo" },
{ "version", 0, arg_flag, &version_flag, "print version" },
{ "help", 0, arg_flag, &help_flag, NULL }
};
int nargs = sizeof(args) / sizeof(args[0]);
void
usage(int status)
{
arg_printusage(args, nargs, "");
arg_printusage(args, nargs, "[username]");
exit(status);
}
@@ -254,9 +291,6 @@ main(int argc, char **argv)
openlog("login", LOG_ODELAY, LOG_AUTH);
if (geteuid() != 0)
err(1, "only root may use login, use su");
if (getarg (args, sizeof(args) / sizeof(args[0]), argc, argv,
&optind))
usage (1);
@@ -266,8 +300,17 @@ main(int argc, char **argv)
if(help_flag)
usage(0);
if (version_flag)
errx(0, "(%s-%s)", PACKAGE, VERSION);
errx(0, "%s version %s", PACKAGE, VERSION);
if (geteuid() != 0)
err(1, "only root may use login, use su");
/* Default tty settings. */
stty_default();
if(p_flag)
copy_env();
if(*argv){
if(strchr(*argv, '=') == NULL && strcmp(*argv, "-") != 0){
strncpy(username, *argv, sizeof(username));
@@ -278,12 +321,20 @@ main(int argc, char **argv)
for(try = 0; try < max_tries; try++){
struct passwd *pwd;
char password[128];
int ret;
if(ask){
read_string("login: ", username, sizeof(username), 1);
f_flag = r_flag = 0;
ret = read_string("login: ", username, sizeof(username), 1);
if(ret == -3)
exit(0);
if(ret == -2)
continue;
}
if(f_flag == 0){
ret = read_string("Password: ", password, sizeof(password), 0);
if(ret == -3 || ret == -2)
continue;
}
if(f_flag == 0)
read_string("Password: ", password, sizeof(password), 0);
pwd = getpwnam(username);
if(pwd == NULL){
fprintf(stderr, "Login incorrect.\n");

View File

@@ -55,10 +55,31 @@
#include <pwd.h>
#include <roken.h>
#include <getarg.h>
#ifdef HAVE_PATHS_H
#include <paths.h>
#endif
#ifdef HAVE_UTMP_H
#include <utmp.h>
#endif
#ifdef HAVE_UTMPX_H
#include <utmpx.h>
#endif
#ifdef KRB5
#include <krb5.h>
#endif
#ifndef _PATH_WTMP
#ifdef WTMP_FILE
#define _PATH_WTMP WTMP_FILE
#else
#define _PATH_WTMP "/var/adm/wtmp"
#endif
#endif
int read_string(const char*, char*, size_t, int);
char *clean_ttyname (char*);
char *make_id (char*);
#endif /* __LOGIN_LOCL_H__ */

View File

@@ -86,7 +86,8 @@ read_string(const char *prompt, char *buf, size_t len, int echo)
while(intr_flag == 0){
c = getc(tty);
if(c == EOF){
ret = 1;
if(!ferror(tty))
ret = 1;
break;
}
if(c == '\n')
@@ -110,7 +111,13 @@ read_string(const char *prompt, char *buf, size_t len, int echo)
for(i = 0; i < sizeof(sigs) / sizeof(sigs[0]); i++)
sigaction(i, &sigs[i], NULL);
return of || intr_flag || ret;
if(ret)
return -3;
if(intr_flag)
return -2;
if(of)
return -1;
return 0;
}

View File

@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*/
#include "bsd_locl.h"
#include "login_locl.h"
RCSID("$Id$");

View File

@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*/
#include "bsd_locl.h"
#include "login_locl.h"
RCSID("$Id$");

View File

@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*/
#include "bsd_locl.h"
#include "login_locl.h"
RCSID("$Id$");

View File

@@ -1,6 +1,6 @@
/* Author: Wietse Venema <wietse@wzv.win.tue.nl> */
#include "bsd_locl.h"
#include "login_locl.h"
RCSID("$Id$");