From c8d50207118e4bcd6325186fb584fcf265ff9b0d Mon Sep 17 00:00:00 2001 From: Joshua Kwan Date: Tue, 30 Dec 2003 23:33:58 +0000 Subject: [PATCH] Honor case in login name. Also fix ttyrec path, probably lost in strcpy->snprintf transition. git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@7 db0b04b0-f4d1-0310-9a6d-de3e77497b0e --- dgamelaunch.c | 26 +++++++++++++++++++++++--- ttyrec.c | 5 +++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/dgamelaunch.c b/dgamelaunch.c index 4594f11..e22fd1f 100644 --- a/dgamelaunch.c +++ b/dgamelaunch.c @@ -537,9 +537,10 @@ freefile () free (users[i]); } - free(users); + if (users) + free(users); + users = NULL; - me = NULL; f_num = 0; } @@ -558,6 +559,20 @@ initncurses () /* ************************************************************* */ +struct dg_user * +deep_copy (struct dg_user * src) +{ + struct dg_user *dest = malloc(sizeof (struct dg_user)); + + dest->username = strdup(src->username); + dest->email = strdup(src->email); + dest->env = strdup(src->env); + dest->password = strdup(src->password); + dest->flags = src->flags; + + return dest; +} + void login () { @@ -593,7 +608,7 @@ login () if ((me_index = userexist (user_buf)) != -1) { - me = users[me_index]; + me = deep_copy(users[me_index]); error = 0; } } @@ -657,6 +672,8 @@ newuser () getnstr (buf, 20); if (userexist (buf) == -1) error = 0; + else + error = 1; for (i = 0; i < strlen (buf); i++) { @@ -1090,6 +1107,9 @@ main (void) /* NOW we can safely kill this */ freefile (); + + if (me) + free(me); exit (1); return 1; diff --git a/ttyrec.c b/ttyrec.c index dc73030..8aaafa3 100644 --- a/ttyrec.c +++ b/ttyrec.c @@ -104,12 +104,13 @@ ttyrec_main (char *username) void finish (); char dirname[100]; - snprintf (dirname, 100, "/%s%s%s", LOC_TTYRECDIR, username, - ttyrec_filename); + snprintf (dirname, 100, "%s%s", LOC_TTYRECDIR, username); if (access(dirname, F_OK) != 0) mkdir (dirname, 0755); + snprintf (dirname, 100, "%s%s/%s", LOC_TTYRECDIR, username, ttyrec_filename); + if ((fscript = fopen (dirname, "w")) == NULL) { perror (dirname);