From 1a3646958920059c37745c1e4b6f70cd58a0549a Mon Sep 17 00:00:00 2001 From: Joshua Kwan Date: Sat, 12 Jun 2004 00:11:18 +0000 Subject: [PATCH] add USER-authentication support git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@291 db0b04b0-f4d1-0310-9a6d-de3e77497b0e --- Changelog | 4 +++- dgamelaunch.c | 36 +++++++++++++++++++++++++++++++++++- dgamelaunch.h | 1 + 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Changelog b/Changelog index ada11de..6713a16 100644 --- a/Changelog +++ b/Changelog @@ -1,4 +1,4 @@ -1.4.5 (????/??/??) +1.4.5 (2004/06/11) * Reset offset if necessary to show at least one game to avoid things like "(15-14 of 14)". * Provide several examples for dgl-create-chroot.conf. @@ -8,6 +8,8 @@ * Added ^W for delete word in mygetnstr(). * Begun generalization of code so that someone can get it to work with stuff like Slash'EM etc. easier. + * Allow automatic authorization using the USER environment variable + that one can auto-set in .telnetrc. 1.4.4 (2004/03/07) * Show total number of games in progress below the list, useful if diff --git a/dgamelaunch.c b/dgamelaunch.c index 379048b..f99337c 100644 --- a/dgamelaunch.c +++ b/dgamelaunch.c @@ -785,6 +785,21 @@ initcurses () /* ************************************************************* */ +void +autologin (char* user, char *pass) +{ + int me_index = -1; + if ((me_index = userexist(user)) != -1) + { + me = users[me_index]; + if (passwordgood(pass)) + { + loggedin = 1; + snprintf (rcfilename, 80, "%srcfiles/%s.nethackrc", myconfig->dglroot, me->username); + } + } +} + void loginprompt (int from_ttyplay) { @@ -1652,7 +1667,7 @@ int main (int argc, char** argv) { /* for chroot and program execution */ - char atrcfilename[81], *spool; + char atrcfilename[81], *spool, *auth = getenv("USER"); unsigned int len; int c; int nhext = 0, nhauth = 0; @@ -1760,6 +1775,25 @@ main (int argc, char** argv) if (nhauth) graceful_exit (authenticate ()); + if (auth) + { + char *user, *pass, *p; + + p = strchr(auth, ':'); + + if (p) + { + pass = p + 1; + + if (pass != '\0') + { + *p = '\0'; + user = auth; + autologin(user, pass); + } + } + } + initcurses (); menuloop(); diff --git a/dgamelaunch.h b/dgamelaunch.h index a5e5c32..17e5378 100644 --- a/dgamelaunch.h +++ b/dgamelaunch.h @@ -87,6 +87,7 @@ extern void freefile(void); extern void initcurses(void); extern void loginprompt(int from_ttyplay); extern void newuser(void); +extern void autologin(char *user, char *pass); extern int passwordgood(char *cpw); extern int readfile(int nolock); extern int userexist(char *cname);