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:
@@ -5,7 +5,7 @@ AUTOMAKE_OPTIONS = no-dependencies foreign
|
|||||||
INCLUDES = -I$(top_builddir)/include $(INCLUDE_krb4)
|
INCLUDES = -I$(top_builddir)/include $(INCLUDE_krb4)
|
||||||
|
|
||||||
bin_PROGRAMS = login
|
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 \
|
LDADD = $(top_builddir)/lib/krb5/libkrb5.a \
|
||||||
$(top_builddir)/lib/des/libdes.a \
|
$(top_builddir)/lib/des/libdes.a \
|
||||||
|
@@ -71,6 +71,14 @@ add_env(const char *var, const char *value)
|
|||||||
extend_env(str);
|
extend_env(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
copy_env(void)
|
||||||
|
{
|
||||||
|
char **p;
|
||||||
|
for(p = environ; *p; p++)
|
||||||
|
extend_env(*p);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
exec_shell(const char *shell, int fallback)
|
exec_shell(const char *shell, int fallback)
|
||||||
{
|
{
|
||||||
@@ -93,11 +101,61 @@ exec_shell(const char *shell, int fallback)
|
|||||||
err(1, "%s", shell);
|
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
|
void
|
||||||
do_login(struct passwd *pwd)
|
do_login(struct passwd *pwd)
|
||||||
{
|
{
|
||||||
int rootlogin = (pwd->pw_uid == 0);
|
int rootlogin = (pwd->pw_uid == 0);
|
||||||
update_utmp();
|
|
||||||
|
update_utmp(pwd->pw_name, remote_host ? remote_host : "");
|
||||||
#ifdef HAVE_SETLOGIN
|
#ifdef HAVE_SETLOGIN
|
||||||
if(setlogin(pwd->pw_name)){
|
if(setlogin(pwd->pw_name)){
|
||||||
warn("setlogin(%s)", pwd->pw_name);
|
warn("setlogin(%s)", pwd->pw_name);
|
||||||
@@ -135,6 +193,7 @@ do_login(struct passwd *pwd)
|
|||||||
exec_shell(pwd->pw_shell, rootlogin);
|
exec_shell(pwd->pw_shell, rootlogin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef KRB5
|
||||||
int
|
int
|
||||||
krb5_verify(struct passwd *pwd, const char *password)
|
krb5_verify(struct passwd *pwd, const char *password)
|
||||||
{
|
{
|
||||||
@@ -185,6 +244,7 @@ krb5_verify(struct passwd *pwd, const char *password)
|
|||||||
krb5_free_context(context);
|
krb5_free_context(context);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
check_password(struct passwd *pwd, const char *password)
|
check_password(struct passwd *pwd, const char *password)
|
||||||
@@ -209,33 +269,10 @@ check_password(struct passwd *pwd, const char *password)
|
|||||||
return 1;
|
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
|
void
|
||||||
usage(int status)
|
usage(int status)
|
||||||
{
|
{
|
||||||
arg_printusage(args, nargs, "");
|
arg_printusage(args, nargs, "[username]");
|
||||||
exit(status);
|
exit(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,9 +291,6 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
openlog("login", LOG_ODELAY, LOG_AUTH);
|
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,
|
if (getarg (args, sizeof(args) / sizeof(args[0]), argc, argv,
|
||||||
&optind))
|
&optind))
|
||||||
usage (1);
|
usage (1);
|
||||||
@@ -266,7 +300,16 @@ main(int argc, char **argv)
|
|||||||
if(help_flag)
|
if(help_flag)
|
||||||
usage(0);
|
usage(0);
|
||||||
if (version_flag)
|
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(*argv){
|
||||||
if(strchr(*argv, '=') == NULL && strcmp(*argv, "-") != 0){
|
if(strchr(*argv, '=') == NULL && strcmp(*argv, "-") != 0){
|
||||||
@@ -278,12 +321,20 @@ main(int argc, char **argv)
|
|||||||
for(try = 0; try < max_tries; try++){
|
for(try = 0; try < max_tries; try++){
|
||||||
struct passwd *pwd;
|
struct passwd *pwd;
|
||||||
char password[128];
|
char password[128];
|
||||||
|
int ret;
|
||||||
if(ask){
|
if(ask){
|
||||||
read_string("login: ", username, sizeof(username), 1);
|
|
||||||
f_flag = r_flag = 0;
|
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);
|
pwd = getpwnam(username);
|
||||||
if(pwd == NULL){
|
if(pwd == NULL){
|
||||||
fprintf(stderr, "Login incorrect.\n");
|
fprintf(stderr, "Login incorrect.\n");
|
||||||
|
@@ -55,10 +55,31 @@
|
|||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <roken.h>
|
#include <roken.h>
|
||||||
#include <getarg.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
|
#ifdef KRB5
|
||||||
#include <krb5.h>
|
#include <krb5.h>
|
||||||
#endif
|
#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);
|
int read_string(const char*, char*, size_t, int);
|
||||||
|
|
||||||
|
char *clean_ttyname (char*);
|
||||||
|
char *make_id (char*);
|
||||||
|
|
||||||
|
|
||||||
#endif /* __LOGIN_LOCL_H__ */
|
#endif /* __LOGIN_LOCL_H__ */
|
||||||
|
@@ -86,7 +86,8 @@ read_string(const char *prompt, char *buf, size_t len, int echo)
|
|||||||
while(intr_flag == 0){
|
while(intr_flag == 0){
|
||||||
c = getc(tty);
|
c = getc(tty);
|
||||||
if(c == EOF){
|
if(c == EOF){
|
||||||
ret = 1;
|
if(!ferror(tty))
|
||||||
|
ret = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(c == '\n')
|
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++)
|
for(i = 0; i < sizeof(sigs) / sizeof(sigs[0]); i++)
|
||||||
sigaction(i, &sigs[i], NULL);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -36,7 +36,7 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "bsd_locl.h"
|
#include "login_locl.h"
|
||||||
|
|
||||||
RCSID("$Id$");
|
RCSID("$Id$");
|
||||||
|
|
||||||
|
@@ -36,7 +36,7 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "bsd_locl.h"
|
#include "login_locl.h"
|
||||||
|
|
||||||
RCSID("$Id$");
|
RCSID("$Id$");
|
||||||
|
|
||||||
|
@@ -36,7 +36,7 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "bsd_locl.h"
|
#include "login_locl.h"
|
||||||
|
|
||||||
RCSID("$Id$");
|
RCSID("$Id$");
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
/* Author: Wietse Venema <wietse@wzv.win.tue.nl> */
|
/* Author: Wietse Venema <wietse@wzv.win.tue.nl> */
|
||||||
|
|
||||||
#include "bsd_locl.h"
|
#include "login_locl.h"
|
||||||
|
|
||||||
RCSID("$Id$");
|
RCSID("$Id$");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user