summaryrefslogtreecommitdiff
path: root/loginrec.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2000-06-27 09:40:06 +1000
committerDamien Miller <djm@mindrot.org>2000-06-27 09:40:06 +1000
commitf8af08d7cb8e4fc0c998291a76ca1f4057972565 (patch)
tree1e1641107557a1e60d960620ff2e602e34998cf8 /loginrec.c
parent0800647391ac42dea364e409100e8961686fae34 (diff)
- (djm) Fixes to login code - not setting li->uid, cleanups
Diffstat (limited to 'loginrec.c')
-rw-r--r--loginrec.c54
1 files changed, 26 insertions, 28 deletions
diff --git a/loginrec.c b/loginrec.c
index 00dcc3280..e4cb2a64e 100644
--- a/loginrec.c
+++ b/loginrec.c
@@ -170,7 +170,7 @@
170#include "xmalloc.h" 170#include "xmalloc.h"
171#include "loginrec.h" 171#include "loginrec.h"
172 172
173RCSID("$Id: loginrec.c,v 1.9 2000/06/20 03:49:11 djm Exp $"); 173RCSID("$Id: loginrec.c,v 1.10 2000/06/26 23:40:06 djm Exp $");
174 174
175/** 175/**
176 ** prototypes for helper functions in this file 176 ** prototypes for helper functions in this file
@@ -198,16 +198,9 @@ int lastlog_get_entry(struct logininfo *li);
198int wtmp_get_entry(struct logininfo *li); 198int wtmp_get_entry(struct logininfo *li);
199int wtmpx_get_entry(struct logininfo *li); 199int wtmpx_get_entry(struct logininfo *li);
200 200
201
202#ifdef MIN
203# undef MIN
204# define MIN(a,b) ( (a)<(b) ? (a) : (b) )
205#endif
206
207/* pick the shortest string */ 201/* pick the shortest string */
208#define MIN_SIZEOF(s1,s2) ( sizeof(s1) < sizeof(s2) ? sizeof(s1) : sizeof(s2) ) 202#define MIN_SIZEOF(s1,s2) ( sizeof(s1) < sizeof(s2) ? sizeof(s1) : sizeof(s2) )
209 203
210
211/** 204/**
212 ** platform-independent login functions 205 ** platform-independent login functions
213 **/ 206 **/
@@ -303,7 +296,7 @@ login_get_lastlog(struct logininfo *li, const int uid)
303 pw = getpwuid(uid); 296 pw = getpwuid(uid);
304 /* No MIN_SIZEOF here - we absolutely *must not* truncate the 297 /* No MIN_SIZEOF here - we absolutely *must not* truncate the
305 * username */ 298 * username */
306 strlcpy(li->username, pw->pw_name, li->username); 299 strlcpy(li->username, pw->pw_name, sizeof(li->username));
307#endif 300#endif
308 if (getlast_entry(li)) 301 if (getlast_entry(li))
309 return li; 302 return li;
@@ -353,18 +346,27 @@ int
353login_init_entry(struct logininfo *li, int pid, const char *username, 346login_init_entry(struct logininfo *li, int pid, const char *username,
354 const char *hostname, const char *line) 347 const char *hostname, const char *line)
355{ 348{
349 struct passwd *pw;
350
356 /* zero the structure */ 351 /* zero the structure */
357 memset(li, 0, sizeof(struct logininfo)); 352 memset(li, 0, sizeof(struct logininfo));
358 353
359 li->pid = pid; 354 li->pid = pid;
355
360 /* set the line information */ 356 /* set the line information */
361 if (line) 357 if (line)
362 line_fullname(li->line, line, sizeof(li->line)); 358 line_fullname(li->line, line, sizeof(li->line));
363 359
364 if (username) 360 if (username) {
365 strlcpy(li->username, username, sizeof(li->username)); 361 strlcpy(li->username, username, sizeof(li->username));
362 pw = getpwnam(li->username);
363 if (pw == NULL)
364 fatal("login_init_entry: Cannot find user \"%s\"", li->username);
365 li->uid = pw->pw_uid;
366 }
366 if (hostname) 367 if (hostname)
367 strlcpy(li->hostname, hostname, sizeof(li->hostname)); 368 strlcpy(li->hostname, hostname, sizeof(li->hostname));
369
368 return 1; 370 return 1;
369} 371}
370 372
@@ -377,16 +379,12 @@ login_init_entry(struct logininfo *li, int pid, const char *username,
377void 379void
378login_set_current_time(struct logininfo *li) 380login_set_current_time(struct logininfo *li)
379{ 381{
380#ifdef HAVE_SYS_TIME_H
381 struct timeval tv; 382 struct timeval tv;
382 383
383 gettimeofday(&tv, NULL); 384 gettimeofday(&tv, NULL);
384 li->tv_sec = tv.tv_sec ; li->tv_usec = tv.tv_usec; 385
385#else 386 li->tv_sec = tv.tv_sec;
386 time_t tm = time(0); 387 li->tv_usec = tv.tv_usec;
387
388 li->tv_sec = tm; li->tv_usec = 0;
389#endif
390} 388}
391 389
392 390
@@ -1394,17 +1392,17 @@ lastlog_openseek(struct logininfo *li, int *fd, int filemode)
1394 1392
1395 type = lastlog_filetype(LASTLOG_FILE); 1393 type = lastlog_filetype(LASTLOG_FILE);
1396 switch (type) { 1394 switch (type) {
1397 case LL_FILE: 1395 case LL_FILE:
1398 strlcpy(lastlog_file, LASTLOG_FILE, sizeof(lastlog_file)); 1396 strlcpy(lastlog_file, LASTLOG_FILE, sizeof(lastlog_file));
1399 break; 1397 break;
1400 case LL_DIR: 1398 case LL_DIR:
1401 snprintf(lastlog_file, sizeof(lastlog_file), "%s/%s", 1399 snprintf(lastlog_file, sizeof(lastlog_file), "%s/%s",
1402 LASTLOG_FILE, li->username); 1400 LASTLOG_FILE, li->username);
1403 break; 1401 break;
1404 default: 1402 default:
1405 log("lastlog_openseek: %.100s is not a file or directory!", 1403 log("lastlog_openseek: %.100s is not a file or directory!",
1406 LASTLOG_FILE); 1404 LASTLOG_FILE);
1407 return 0; 1405 return 0;
1408 } /* switch */ 1406 } /* switch */
1409 1407
1410 *fd = open(lastlog_file, filemode); 1408 *fd = open(lastlog_file, filemode);