]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - src/fake-environ/uname.c
httpscert: Increase size of the RSA key to 4096.
[people/teissler/ipfire-2.x.git] / src / fake-environ / uname.c
CommitLineData
4c8608f0
MT
1
2
3#include <stdio.h>
4#include <string.h>
5#include <dlfcn.h>
6#include <stdlib.h> /* for EXIT_FAILURE */
7#include <unistd.h> /* for _exit() */
8#include <sys/types.h>
9#include <sys/stat.h>
10#include <fcntl.h>
11#include <sys/syslog.h>
12#include <sys/utsname.h>
13
14#ifndef RTLD_NEXT
15#define RTLD_NEXT ((void *) -1l)
16#endif
17
18typedef int (*uname_t)(struct utsname * buf);
19
20static void *get_libc_func(const char *funcname) {
21 char *error;
22
23 void *func = dlsym(RTLD_NEXT, funcname);
24 if ((error = dlerror()) != NULL) {
25 fprintf(stderr, "I can't locate libc function `%s' error: %s", funcname, error);
26 _exit(EXIT_FAILURE);
27 }
28
29 return func;
30}
31
32int uname(struct utsname *buf) {
33 char *env = NULL;
34
35 /* Call real uname to get the information we need. */
36 uname_t real_uname = (uname_t)get_libc_func("uname");
37 int ret = real_uname((struct utsname *) buf);
38
39 /* Replace release if requested. */
40 if ((env = getenv("UTS_RELEASE")) != NULL) {
41 strncpy(buf->release, env, _UTSNAME_RELEASE_LENGTH);
42 }
43
44 /* Replace machine type if requested. */
45 if ((env = getenv("UTS_MACHINE")) != NULL) {
46 strncpy(buf->machine, env, _UTSNAME_MACHINE_LENGTH);
47 }
48
49 return ret;
50}