login.c (33332) | login.c (35557) |
---|---|
1/*- 2 * Copyright (c) 1980, 1987, 1988, 1991, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)login.c 8.4 (Berkeley) 4/2/94"; 43#endif 44static const char rcsid[] = | 1/*- 2 * Copyright (c) 1980, 1987, 1988, 1991, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)login.c 8.4 (Berkeley) 4/2/94"; 43#endif 44static const char rcsid[] = |
45 "$Id: login.c,v 1.31 1998/02/05 18:37:02 guido Exp $"; | 45 "$Id: login.c,v 1.32 1998/02/13 21:02:53 ache Exp $"; |
46#endif /* not lint */ 47 48/* 49 * login [ name ] 50 * login -h hostname (for telnetd, etc.) 51 * login -f name (for pre-authenticated login: datakit, xterm, etc.) 52 */ 53 --- 98 unchanged lines hidden (view full) --- 152 struct group *gr; 153 struct stat st; 154 struct timeval tp; 155 struct utmp utmp; 156 int rootok, retries, backoff; 157 int ask, ch, cnt, fflag, hflag, pflag, quietlog, rootlogin, rval; 158 int changepass; 159 time_t warntime; | 46#endif /* not lint */ 47 48/* 49 * login [ name ] 50 * login -h hostname (for telnetd, etc.) 51 * login -f name (for pre-authenticated login: datakit, xterm, etc.) 52 */ 53 --- 98 unchanged lines hidden (view full) --- 152 struct group *gr; 153 struct stat st; 154 struct timeval tp; 155 struct utmp utmp; 156 int rootok, retries, backoff; 157 int ask, ch, cnt, fflag, hflag, pflag, quietlog, rootlogin, rval; 158 int changepass; 159 time_t warntime; |
160 uid_t uid; | 160 uid_t uid, eiud; |
161 char *domain, *p, *ep, *salt, *ttyn; 162 char tbuf[MAXPATHLEN + 2], tname[sizeof(_PATH_TTY) + 10]; 163 char localhost[MAXHOSTNAMELEN]; 164 char *shell = NULL; 165#ifdef LOGIN_CAP 166 login_cap_t *lc = NULL; 167#ifdef LOGIN_CAP_AUTH 168 char *style, *authtype; --- 25 unchanged lines hidden (view full) --- 194 term = NULL; 195 if (gethostname(localhost, sizeof(localhost)) < 0) 196 syslog(LOG_ERR, "couldn't get local hostname: %m"); 197 else 198 domain = strchr(localhost, '.'); 199 200 fflag = hflag = pflag = 0; 201 uid = getuid(); | 161 char *domain, *p, *ep, *salt, *ttyn; 162 char tbuf[MAXPATHLEN + 2], tname[sizeof(_PATH_TTY) + 10]; 163 char localhost[MAXHOSTNAMELEN]; 164 char *shell = NULL; 165#ifdef LOGIN_CAP 166 login_cap_t *lc = NULL; 167#ifdef LOGIN_CAP_AUTH 168 char *style, *authtype; --- 25 unchanged lines hidden (view full) --- 194 term = NULL; 195 if (gethostname(localhost, sizeof(localhost)) < 0) 196 syslog(LOG_ERR, "couldn't get local hostname: %m"); 197 else 198 domain = strchr(localhost, '.'); 199 200 fflag = hflag = pflag = 0; 201 uid = getuid(); |
202 euid = geteuid(); |
|
202 while ((ch = getopt(argc, argv, "fh:p")) != -1) 203 switch (ch) { 204 case 'f': 205 fflag = 1; 206 break; 207 case 'h': 208 if (uid) 209 errx(1, "-h option: %s", strerror(EPERM)); --- 121 unchanged lines hidden (view full) --- 331 salt = "xx"; 332 333#ifdef LOGIN_CAP 334 /* 335 * Establish the class now, before we might goto 336 * within the next block. pwd can be NULL since it 337 * falls back to the "default" class if it is. 338 */ | 203 while ((ch = getopt(argc, argv, "fh:p")) != -1) 204 switch (ch) { 205 case 'f': 206 fflag = 1; 207 break; 208 case 'h': 209 if (uid) 210 errx(1, "-h option: %s", strerror(EPERM)); --- 121 unchanged lines hidden (view full) --- 332 salt = "xx"; 333 334#ifdef LOGIN_CAP 335 /* 336 * Establish the class now, before we might goto 337 * within the next block. pwd can be NULL since it 338 * falls back to the "default" class if it is. 339 */ |
340 if (pwd != NULL) 341 (void)seteuid(rootlogin ? 0 : pwd->pw_uid); |
|
339 lc = login_getpwclass(pwd); | 342 lc = login_getpwclass(pwd); |
343 seteuid(euid); |
|
340#endif /* LOGIN_CAP */ 341 342 /* 343 * if we have a valid account name, and it doesn't have a 344 * password, or the -f option was specified and the caller 345 * is root or the caller isn't changing their uid, don't 346 * authenticate. 347 */ --- 188 unchanged lines hidden (view full) --- 536 checknologin(); 537#endif 538 539#ifdef LOGIN_CAP 540 quietlog = login_getcapbool(lc, "hushlogin", 0); 541#else 542 quietlog = 0; 543#endif | 344#endif /* LOGIN_CAP */ 345 346 /* 347 * if we have a valid account name, and it doesn't have a 348 * password, or the -f option was specified and the caller 349 * is root or the caller isn't changing their uid, don't 350 * authenticate. 351 */ --- 188 unchanged lines hidden (view full) --- 540 checknologin(); 541#endif 542 543#ifdef LOGIN_CAP 544 quietlog = login_getcapbool(lc, "hushlogin", 0); 545#else 546 quietlog = 0; 547#endif |
548 (void)seteuid(rootlogin ? 0 : pwd->pw_uid); |
|
544 if (!*pwd->pw_dir || chdir(pwd->pw_dir) < 0) { 545#ifdef LOGIN_CAP 546 if (login_getcapbool(lc, "requirehome", 0)) 547 refused("Home directory not available", "HOMEDIR", 1); 548#endif 549 if (chdir("/") < 0) 550 refused("Cannot find root directory", "ROOTDIR", 1); 551 pwd->pw_dir = "/"; 552 if (!quietlog || *pwd->pw_dir) 553 printf("No home directory.\nLogging in with home = \"/\".\n"); 554 } | 549 if (!*pwd->pw_dir || chdir(pwd->pw_dir) < 0) { 550#ifdef LOGIN_CAP 551 if (login_getcapbool(lc, "requirehome", 0)) 552 refused("Home directory not available", "HOMEDIR", 1); 553#endif 554 if (chdir("/") < 0) 555 refused("Cannot find root directory", "ROOTDIR", 1); 556 pwd->pw_dir = "/"; 557 if (!quietlog || *pwd->pw_dir) 558 printf("No home directory.\nLogging in with home = \"/\".\n"); 559 } |
560 (void)seteuid(euid); |
|
555 if (!quietlog) 556 quietlog = access(_PATH_HUSHLOGIN, F_OK) == 0; 557 558 if (pwd->pw_change || pwd->pw_expire) 559 (void)gettimeofday(&tp, (struct timezone *)NULL); 560 561#define DEFAULT_WARN (2L * 7L * 86400L) /* Two weeks */ 562 --- 452 unchanged lines hidden --- | 561 if (!quietlog) 562 quietlog = access(_PATH_HUSHLOGIN, F_OK) == 0; 563 564 if (pwd->pw_change || pwd->pw_expire) 565 (void)gettimeofday(&tp, (struct timezone *)NULL); 566 567#define DEFAULT_WARN (2L * 7L * 86400L) /* Two weeks */ 568 --- 452 unchanged lines hidden --- |