Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/libbb/login.c


Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/libbb/login.c

    r1765 r2725  
    77 * Optimize and correcting OCRNL by Vladimir Oleynik <dzo@simtreas.ru>
    88 *
    9  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     9 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    1010 */
    1111
    12 #include <sys/param.h>  /* MAXHOSTNAMELEN */
     12#include "libbb.h"
     13/* After libbb.h, since it needs sys/types.h on some systems */
    1314#include <sys/utsname.h>
    14 #include "libbb.h"
    1515
    1616#define LOGIN " login: "
     
    1919static const char fmtstr_t[] ALIGN1 = "%H:%M:%S";
    2020
    21 void print_login_issue(const char *issue_file, const char *tty)
     21void FAST_FUNC print_login_issue(const char *issue_file, const char *tty)
    2222{
    23     FILE *fd;
     23    FILE *fp;
    2424    int c;
    2525    char buf[256+1];
     
    3131    uname(&uts);
    3232
    33     puts("\r"); /* start a new line */
     33    puts("\r");  /* start a new line */
    3434
    35     fd = fopen(issue_file, "r");
    36     if (!fd)
     35    fp = fopen_for_read(issue_file);
     36    if (!fp)
    3737        return;
    38     while ((c = fgetc(fd)) != EOF) {
     38    while ((c = fgetc(fp)) != EOF) {
    3939        outbuf = buf;
    4040        buf[0] = c;
     
    4545        }
    4646        if (c == '\\' || c == '%') {
    47             c = fgetc(fd);
     47            c = fgetc(fp);
    4848            switch (c) {
    4949            case 's':
     
    5151                break;
    5252            case 'n':
     53            case 'h':
    5354                outbuf = uts.nodename;
    5455                break;
     
    6263                outbuf = uts.machine;
    6364                break;
     65/* The field domainname of struct utsname is Linux specific. */
     66#if defined(__linux__)
    6467            case 'D':
    6568            case 'o':
    66                 c = getdomainname(buf, sizeof(buf) - 1);
    67                 buf[c >= 0 ? c : 0] = '\0';
     69                outbuf = uts.domainname;
    6870                break;
     71#endif
    6972            case 'd':
    7073                strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));
     
    7275            case 't':
    7376                strftime(buf, sizeof(buf), fmtstr_t, localtime(&t));
    74                 break;
    75             case 'h':
    76                 gethostname(buf, sizeof(buf) - 1);
    77                 buf[sizeof(buf) - 1] = '\0';
    7877                break;
    7978            case 'l':
     
    8685        fputs(outbuf, stdout);
    8786    }
    88     fclose(fd);
    89     fflush(stdout);
     87    fclose(fp);
     88    fflush_all();
    9089}
    9190
    92 void print_login_prompt(void)
     91void FAST_FUNC print_login_prompt(void)
    9392{
    94     char buf[MAXHOSTNAMELEN+1];
     93    char *hostname = safe_gethostname();
    9594
    96     if (gethostname(buf, MAXHOSTNAMELEN) == 0)
    97         fputs(buf, stdout);
     95    fputs(hostname, stdout);
     96    fputs(LOGIN, stdout);
     97    fflush_all();
     98    free(hostname);
     99}
    98100
    99     fputs(LOGIN, stdout);
    100     fflush(stdout);
     101/* Clear dangerous stuff, set PATH */
     102static const char forbid[] ALIGN1 =
     103    "ENV" "\0"
     104    "BASH_ENV" "\0"
     105    "HOME" "\0"
     106    "IFS" "\0"
     107    "SHELL" "\0"
     108    "LD_LIBRARY_PATH" "\0"
     109    "LD_PRELOAD" "\0"
     110    "LD_TRACE_LOADED_OBJECTS" "\0"
     111    "LD_BIND_NOW" "\0"
     112    "LD_AOUT_LIBRARY_PATH" "\0"
     113    "LD_AOUT_PRELOAD" "\0"
     114    "LD_NOWARN" "\0"
     115    "LD_KEEPDIR" "\0";
     116
     117int FAST_FUNC sanitize_env_if_suid(void)
     118{
     119    const char *p;
     120
     121    if (getuid() == geteuid())
     122        return 0;
     123
     124    p = forbid;
     125    do {
     126        unsetenv(p);
     127        p += strlen(p) + 1;
     128    } while (*p);
     129    putenv((char*)bb_PATH_root_path);
     130
     131    return 1; /* we indeed were run by different user! */
    101132}
Note: See TracChangeset for help on using the changeset viewer.