diff options
author | jakub <jakub> | 2000-08-07 11:45:49 +0000 |
---|---|---|
committer | jakub <jakub> | 2000-08-07 11:45:49 +0000 |
commit | 440c7c040b3fb919efda03185097606d1ad080be (patch) | |
tree | 77f5eedbb0e11a295edb17de6e43d895ad07cc68 | |
parent | 2e8cc2f6429b22f3d6eb0beb871aa5aa29bf8900 (diff) | |
download | anaconda-440c7c040b3fb919efda03185097606d1ad080be.tar.gz anaconda-440c7c040b3fb919efda03185097606d1ad080be.tar.xz anaconda-440c7c040b3fb919efda03185097606d1ad080be.zip |
The IMHO safe part of the stripping down changes.
Saves more than 200KB of the /sbin/loader's unused crap.
-rw-r--r-- | loader/Makefile | 2 | ||||
-rw-r--r-- | loader/dl-stub.c | 7 | ||||
-rw-r--r-- | loader/fnmatch-stub.c | 27 | ||||
-rw-r--r-- | loader/ftp.c | 11 | ||||
-rw-r--r-- | loader/printf-stub.c | 627 | ||||
-rw-r--r-- | loader/pwd-stub.c | 33 |
6 files changed, 701 insertions, 6 deletions
diff --git a/loader/Makefile b/loader/Makefile index bcb195fbd..f17e72479 100644 --- a/loader/Makefile +++ b/loader/Makefile @@ -8,7 +8,7 @@ ARCH := $(patsubst i%86,i386,$(shell uname -m)) ARCH := $(patsubst sparc%,sparc,$(ARCH)) OBJS = log.o windows.o modules.o devices.o cdrom.o urls.o kickstart.o lang.o \ - misc.o ftp.o + misc.o ftp.o fnmatch-stub.o printf-stub.o pwd-stub.o dl-stub.o LOADEROBJS = loader.o loader-pcmcia.o popen.o SOURCES = $(subst .o,.c,$(OBJS)) loader.c BINS = init diff --git a/loader/dl-stub.c b/loader/dl-stub.c new file mode 100644 index 000000000..79a27a382 --- /dev/null +++ b/loader/dl-stub.c @@ -0,0 +1,7 @@ +void _dl_mcount_wrapper (void *selfpc) +{ +} + +void _dl_mcount_wrapper_check (void *selfpc) +{ +} diff --git a/loader/fnmatch-stub.c b/loader/fnmatch-stub.c new file mode 100644 index 000000000..88de2221d --- /dev/null +++ b/loader/fnmatch-stub.c @@ -0,0 +1,27 @@ +#include <stdio.h> +#include <string.h> +#include <fnmatch.h> + +/* A very simplified fnmatch which just supports one + * in the string and no [, ? or { */ +int fnmatch(const char *pattern, const char *string, int flags) +{ + const char *p, *q, *r; + + if (flags == (FNM_PATHNAME | FNM_PERIOD) + && strpbrk (pattern, "[?{") == NULL + && (p = strchr (pattern, '*')) != NULL + && strchr (p + 1, '*') == NULL) + { + if (strncmp (string, pattern, p - pattern)) + return FNM_NOMATCH; + q = strstr (string + (p - pattern), p + 1); + r = strchr (string + (p - pattern), '/'); + if (q == NULL || strlen (q) != strlen (p + 1) + || (r != NULL && r < q)) + return FNM_NOMATCH; + return 0; + } + fprintf (stderr, "fnmatch stub does not support '%s' patterns\n", pattern); + exit (1); +} diff --git a/loader/ftp.c b/loader/ftp.c index 2c53631f3..c76916143 100644 --- a/loader/ftp.c +++ b/loader/ftp.c @@ -228,13 +228,14 @@ int ftpOpen(char * host, char * name, char * password, char * proxy, name = "anonymous"; if (!password) { + password = "root@"; if (getuid()) { pw = getpwuid(getuid()); - password = alloca(strlen(pw->pw_name) + 2); - strcpy(password, pw->pw_name); - strcat(password, "@"); - } else { - password = "root@"; + if (pw) { + password = alloca(strlen(pw->pw_name) + 2); + strcpy(password, pw->pw_name); + strcat(password, "@"); + } } } diff --git a/loader/printf-stub.c b/loader/printf-stub.c new file mode 100644 index 000000000..3c261ac43 --- /dev/null +++ b/loader/printf-stub.c @@ -0,0 +1,627 @@ +/* + * linux/lib/vsprintf.c + * + * Copyright (C) 1991, 1992 Linus Torvalds + * Copyright (C) 2000 Jakub Jelinek <jakub@redhat.com> + */ + +/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ +/* + * Wirzenius wrote this portably, Torvalds fucked it up :-) + */ + +#include <stdarg.h> +#include <stdio.h> +#include <string.h> +#include <ctype.h> + +#define ASM_GLOBAL_DIRECTIVE .globl +#define __SYMBOL_PREFIX + +/* Define ALIAS as a strong alias for ORIGINAL. */ +#define strong_alias(original, alias) \ + asm (__string_1 (ASM_GLOBAL_DIRECTIVE) " " __SYMBOL_PREFIX #alias "\n" \ + ".set " __SYMBOL_PREFIX #alias "," __SYMBOL_PREFIX #original); + +/* Helper macros used above. */ +#define __string_1(x) __string_0(x) +#define __string_0(x) #x + +#define do_div(n,base) ({ \ + int __res; \ + __res = ((unsigned long long) n) % (unsigned) base; \ + n = ((unsigned long long) n) / (unsigned) base; \ + __res; }) + +static int skip_atoi(const char **s) +{ + int i=0; + + while (isdigit(**s)) + i = i*10 + *((*s)++) - '0'; + return i; +} + +#define ZEROPAD 1 /* pad with zero */ +#define SIGN 2 /* unsigned/signed long */ +#define PLUS 4 /* show plus */ +#define SPACE 8 /* space if plus */ +#define LEFT 16 /* left justified */ +#define SPECIAL 32 /* 0x */ +#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */ + +static char * number(char * str, long long num, int base, int size, int precision, int type) +{ + char c,sign,tmp[66]; + const char *digits="0123456789abcdefghijklmnopqrstuvwxyz"; + int i; + + if (type & LARGE) + digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + if ((type & LEFT) || precision >= 0) + type &= ~ZEROPAD; + if (base < 2 || base > 36) + return 0; + c = (type & ZEROPAD) ? '0' : ' '; + sign = 0; + if (type & SIGN) { + if (num < 0) { + sign = '-'; + num = -num; + size--; + } else if (type & PLUS) { + sign = '+'; + size--; + } else if (type & SPACE) { + sign = ' '; + size--; + } + } + if (type & SPECIAL) { + if (base == 16) + size -= 2; + else if (base == 8) + size--; + } + i = 0; + if (num == 0) + tmp[i++]='0'; + else while (num != 0) + tmp[i++] = digits[do_div(num,base)]; + if (i > precision) + precision = i; + size -= precision; + if (!(type&(ZEROPAD+LEFT))) + while(size-->0) + *str++ = ' '; + if (sign) + *str++ = sign; + if (type & SPECIAL) { + if (base==8) + *str++ = '0'; + else if (base==16) { + *str++ = '0'; + *str++ = digits[33]; + } + } + if (!(type & LEFT)) + while (size-- > 0) + *str++ = c; + while (i < precision--) + *str++ = '0'; + while (i-- > 0) + *str++ = tmp[i]; + while (size-- > 0) + *str++ = ' '; + return str; +} + +static char bigbuf[1024], *buf = NULL, *str, *lim; + +static void check(int width) +{ + if (str + width + 16 < lim) + return; + if (width < 512) width = 512; + if (buf == bigbuf) { + buf = (char *)malloc(1024 + width); + memcpy (buf, bigbuf, str - bigbuf); + str = buf + (str - bigbuf); + lim = buf + 1024 + width; + } else { + int w = lim - buf + width; + buf = (char *)realloc (buf, w); + lim = buf + w; + } +} + +static void xprintf(const char *fmt, va_list args) +{ + int len; + unsigned long long num; + int i, base; + const char *s; + + int flags; /* flags to number() */ + + int field_width; /* width of output field */ + int precision; /* min. # of digits for integers; max + number of chars for from string */ + int qualifier; /* 'h', 'l', or 'L' for integer fields */ + /* 'z' support added 23/7/1999 S.H. */ + /* 'z' changed to 'Z' --davidm 1/25/99 */ + + for (str=buf ; *fmt ; ++fmt) { + if (*fmt != '%') { + check (1); + *str++ = *fmt; + continue; + } + + /* process flags */ + flags = 0; + repeat: + ++fmt; /* this also skips first '%' */ + switch (*fmt) { + case '-': flags |= LEFT; goto repeat; + case '+': flags |= PLUS; goto repeat; + case ' ': flags |= SPACE; goto repeat; + case '#': flags |= SPECIAL; goto repeat; + case '0': flags |= ZEROPAD; goto repeat; + } + + /* get field width */ + field_width = -1; + if (isdigit(*fmt)) + field_width = skip_atoi(&fmt); + else if (*fmt == '*') { + ++fmt; + /* it's the next argument */ + field_width = va_arg(args, int); + if (field_width < 0) { + field_width = -field_width; + flags |= LEFT; + } + } + + /* get the precision */ + precision = -1; + if (*fmt == '.') { + ++fmt; + if (isdigit(*fmt)) + precision = skip_atoi(&fmt); + else if (*fmt == '*') { + ++fmt; + /* it's the next argument */ + precision = va_arg(args, int); + } + if (precision < 0) + precision = 0; + } + + /* get the conversion qualifier */ + qualifier = -1; + if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || *fmt =='Z') { + qualifier = *fmt; + ++fmt; + if (qualifier == 'l' && *fmt == 'l') { + qualifier = 'L'; + ++fmt; + } + } + + /* default base */ + base = 10; + + switch (*fmt) { + case 'c': + check(field_width + 2); + if (!(flags & LEFT)) { + while (--field_width > 0) + *str++ = ' '; + } + *str++ = (unsigned char) va_arg(args, int); + while (--field_width > 0) + *str++ = ' '; + continue; + + case 's': + s = va_arg(args, char *); + if (!s) + s = "(null)"; +got_string: + len = strnlen(s, precision); + + check(field_width > len ? field_width : len); + if (!(flags & LEFT)) + while (len < field_width--) + *str++ = ' '; + for (i = 0; i < len; ++i) + *str++ = *s++; + while (len < field_width--) + *str++ = ' '; + continue; + + case 'p': + { + unsigned long ptr; + ptr = (unsigned long) va_arg(args, void *); + if (!ptr) { + if (precision >= 0 && precision < 5) + precision = 5; + s = "(nil)"; + goto got_string; + } + if (field_width == -1) { + field_width = 2*sizeof(void *)+2; + flags |= ZEROPAD; + } + check(field_width + 32 + precision); + str = number(str, ptr, 16, + field_width, precision, flags | SPECIAL); + } + continue; + + case 'n': + if (qualifier == 'l') { + long * ip = va_arg(args, long *); + *ip = (str - buf); + } else if (qualifier == 'Z') { + size_t * ip = va_arg(args, size_t *); + *ip = (str - buf); + } else { + int * ip = va_arg(args, int *); + *ip = (str - buf); + } + continue; + + case '%': + check(1); + *str++ = '%'; + continue; + + /* integer number formats - set up the flags and "break" */ + case 'o': + base = 8; + break; + + case 'X': + flags |= LARGE; + case 'x': + base = 16; + break; + + case 'd': + case 'i': + flags |= SIGN; + case 'u': + break; + + case 'e': + case 'E': + case 'f': + case 'g': + case 'G': + fputs("Floating point output not supported by xprintf\n", stderr); + exit(1); + + default: + check(2); + *str++ = '%'; + if (*fmt) + *str++ = *fmt; + else + --fmt; + continue; + } + if (qualifier == 'L') + num = va_arg(args, long long); + else if (qualifier == 'l') { + num = va_arg(args, unsigned long); + if (flags & SIGN) + num = (signed long) num; + } else if (qualifier == 'Z') { + num = va_arg(args, size_t); + } else if (qualifier == 'h') { + num = (unsigned short) va_arg(args, int); + if (flags & SIGN) + num = (signed short) num; + } else { + num = va_arg(args, unsigned int); + if (flags & SIGN) + num = (signed int) num; + } + check (field_width + 32 + precision); + str = number(str, num, base, field_width, precision, flags); + } + *str++ = '\0'; +} + +int vsnprintf(char * b, size_t n, const char *fmt, va_list args) +{ + buf = bigbuf; + lim = buf + 1024; + xprintf(fmt, args); + if (str - buf > n) { + memcpy(b, buf, n - 1); + b[n - 1] = '\0'; + } else + strcpy(b, buf); + if (buf != bigbuf) + free (buf); + return str - buf - 1; +} + +int snprintf(char * buf, size_t n, const char *fmt, ...) +{ + va_list args; + int i; + + va_start(args, fmt); + i=vsnprintf(buf,n,fmt,args); + va_end(args); + return i; +} + +int vsprintf(char * b, const char *fmt, va_list args) +{ + buf = b; + lim = (char *)~0UL; + xprintf(fmt, args); + return str - buf - 1; +} + +int sprintf(char * buf, const char *fmt, ...) +{ + va_list args; + int i; + + va_start(args, fmt); + i=vsprintf(buf,fmt,args); + va_end(args); + return i; +} + +int _IO_vfprintf(FILE *f, const char *fmt, va_list args) +{ + buf = bigbuf; + lim = buf + 1024; + xprintf(fmt, args); + fputs(buf, f); + if (buf != bigbuf) + free(buf); + return str - buf - 1; +} + +int fprintf(FILE *f, const char *fmt, ...) +{ + va_list args; + int i; + + va_start(args, fmt); + i=vfprintf(f,fmt,args); + va_end(args); + return i; +} + +int printf(const char *fmt, ...) +{ + va_list args; + int i; + + va_start(args, fmt); + i=vfprintf(stderr,fmt,args); + va_end(args); + return i; +} + +#define SUPPRESS 128 + +int _IO_sscanf(const char *str, const char *fmt, ...) +{ + va_list args; + int ret = EOF; + unsigned long long lnum; + unsigned long num; + int suppress, base, numbersigned; + int field_width; /* width of output field */ + int qualifier; /* 'h', 'l', or 'L' for integer fields */ + char *s, *p, *q; + const char *start = str; + + va_start(args, fmt); + + for (; *fmt ; ++fmt) { + if (isspace(*fmt)) { + while (isspace(*str)) + str++; + continue; + } + if (*fmt != '%') { + if (*str++ != *fmt) + goto done; + continue; + } + + if (ret == EOF) ret = 0; + + suppress = 0; + if (*++fmt == '*') { + suppress = 1; + fmt++; + } + + /* get field width */ + field_width = -1; + if (isdigit(*fmt)) + field_width = skip_atoi(&fmt); + + /* get the conversion qualifier */ + qualifier = -1; + if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') { + qualifier = *fmt; + ++fmt; + if (qualifier == 'l' && *fmt == 'l') { + qualifier = 'L'; + ++fmt; + } + } + + if (strchr ("%c[", *fmt) == NULL) { + while (isspace(*str)) + str++; + } + + base = 0; + numbersigned = 0; + + switch (*fmt) { + case 'c': + if (field_width == -1) + field_width = 1; + if (strlen(str) < field_width) + goto done; + if (!suppress) { + p = va_arg(args, char *); + if (!p) goto done; + memcpy(p, str, field_width); + ret++; + } + str += field_width; + continue; + case 's': + for (s = (char *)str; *s && !isspace(*s) && field_width != 0; s++) + field_width--; +finish_s: + if (s == str) + goto done; + if (!suppress) { + p = va_arg(args, char *); + if (!p) goto done; + memcpy(p, str, s - str); + p[s - str] = '\0'; + ret++; + } + str = s; + continue; + case '[': { + int not_in = 0; + memset(bigbuf, 0, 256); + if (*++fmt == '^') { + not_in = 1; + fmt++; + } + if (*fmt == ']') { + bigbuf[']'] = 1; + fmt++; + } + while (*fmt != ']') { + if (!*fmt) goto done; + bigbuf[(unsigned char)*fmt] = 1; + if (fmt[1] == '-' && fmt[2] != ']') { + unsigned char c = (unsigned char)*fmt + 1; + while (c <= (unsigned char)fmt[2]) + bigbuf[c++] = 1; + fmt += 2; + } + fmt++; + } + if (not_in) { + int i; + for (i = 1; i < 256; i++) + bigbuf[i] ^= 1; + } + for (s = (char *)str; bigbuf[(unsigned char)*s] && field_width != 0; s++) + field_width--; + } + goto finish_s; + + case 'n': + if (qualifier == 'l') { + long * ip = va_arg(args, long *); + *ip = (str - start); + } else { + int * ip = va_arg(args, int *); + *ip = (str - start); + } + continue; + + case '%': + if (*str++ != '%') + goto done; + continue; + + case 'e': + case 'E': + case 'f': + case 'g': + case 'G': + fputs("Floating point output not supported by xprintf\n", stderr); + exit(1); + + default: + goto done; + + /* integer number formats - set up the flags and "break" */ + case 'o': + base = 8; + break; + + case 'p': + qualifier = 'l'; + case 'X': + case 'x': + base = 16; + break; + + case 'd': + base = 10; + case 'i': + numbersigned = 1; + break; + case 'u': + base = 10; + break; + } + p = (char *)str; + if (field_width >= 0) { + strncpy(bigbuf, str, field_width); + bigbuf[field_width] = 0; + p = bigbuf; + } + if (numbersigned) { + if (qualifier == 'L') + lnum = strtoll(p, &q, base); + else + num = strtol(p, &q, base); + } else { + if (qualifier == 'L') + lnum = strtoull(p, &q, base); + else + num = strtoull(p, &q, base); + } + if (p == q) + goto done; + str += (q - p); + if (!suppress) { + p = (char *)va_arg(args, char *); + if (p == NULL) + goto done; + if (qualifier == 'L') + *(unsigned long long *)p = lnum; + else if (qualifier == 'l') + *(unsigned long *)p = num; + else if (qualifier == 'h') + *(unsigned short *)p = num; + else + *(unsigned int *)p = num; + ret++; + } + } +done: + va_end (args); + return ret; +} + +strong_alias (_IO_vfprintf, vfprintf); +strong_alias (_IO_sscanf, sscanf); diff --git a/loader/pwd-stub.c b/loader/pwd-stub.c new file mode 100644 index 000000000..43da508f7 --- /dev/null +++ b/loader/pwd-stub.c @@ -0,0 +1,33 @@ +#include <sys/types.h> +#include <errno.h> +#include <pwd.h> +#include <string.h> + +static struct passwd pw_root = { + pw_name: "root", + pw_passwd: "", + pw_uid: 0, + pw_gid: 0, + pw_gecos: "root", + pw_dir: "/", + pw_shell: "/bin/bash" +}; + +struct passwd *getpwuid(uid_t u) +{ + if (u) return NULL; + return &pw_root; +} + +int __getpwnam_r(const char *name, struct passwd *result_buf, char *buf, + size_t buflen, struct passwd **result) +{ + if (strcmp (name, "root")) { + errno = 0; + *result = NULL; + return -1; + } + memcpy(result_buf, &pw_root, sizeof(struct passwd)); + *result = result_buf; + return 0; +} |