Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:15.0:Staging:D
man
wrapper.c
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File wrapper.c of Package man
/* * wrapper.c - wrapper program around man and mandb * * Copyright (C) 2000 Fabrizio Polacco <fpolacco@debian.org> * Copyright (C) 2001, 2002 Colin Watson. * * This file is part of man-db. * * man-db is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * man-db is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with man-db; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifdef HAVE_CONFIG_H # include "config.h" #endif /* HAVE_CONFIG_H */ #include <string.h> #include <stdio.h> #include <unistd.h> #include <errno.h> #include <grp.h> #include <pwd.h> #include <grp.h> #include <sys/types.h> #include <stdlib.h> #include <string.h> #include "dirname.h" #include "gettext.h" #include <locale.h> #define _(Text) gettext (Text) #include "manconfig.h" /* this list is used to authenticate the program running. * it is fixed at compile time to avoid a full class of * dangers ... */ static struct { const char *prog; const char *run; const char *user; } *wlp, wrapped_list[] = { /* prog run user */ #ifdef DEBUG { "_man", "src/man", "man" }, { "_mandb", "src/mandb", "man" }, #endif { "man", "/usr/lib/man-db/man", "man" }, { "mandb", "/usr/lib/man-db/mandb", "man" }, { 0, 0, 0, }}; char *program_name; int main (int argc, char **argv, char *envp[]) { uid_t ruid, euid; gid_t rgid; argc = argc; /* not used */ /* We don't warn about this setlocale() call failing, as the program * we call will do that. */ setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); bindtextdomain (PACKAGE "-gnulib", LOCALEDIR); textdomain (PACKAGE); /* this wrapper can be run as "man" or as "mandb" */ program_name = base_name (argv[0]); ruid = getuid (); euid = geteuid(); rgid = getgid (); #ifdef DEBUG printf ("%s:\n", program_name); #endif for (wlp = wrapped_list; wlp->prog && strcmp (program_name, wlp->prog); ++wlp) /* __asm__ __volatile__("": : :"memory") */; if (!wlp->prog) { fprintf (stderr, _("Don't know which program should I run being >%s<\n"), program_name); return -ENOENT; } #ifdef DEBUG printf ("%s\n", wlp->run); #endif if (ruid == 0 || euid == 0) { static char *dummy_environ[] = { NULL }; extern char **environ; struct passwd *pwd; char *cwd; pwd = getpwnam (wlp->user); if (!pwd) { fprintf (stderr, _("%s: Failed su to user %s\n"), wlp->prog, wlp->user); return -EACCES; } if (ruid == 0) { ruid = pwd->pw_uid; rgid = pwd->pw_gid; } else { #ifndef MAN_CATS /* No permissions required to create files * under the sub directories of /var/cache/man */ pwd->pw_uid = ruid; pwd->pw_gid = rgid; #endif } if ((cwd = get_current_dir_name()) == NULL) { fprintf (stderr, _("%s: Failed su to user %s\n"), wlp->prog, wlp->user); return -EACCES; } if (setregid (rgid, pwd->pw_gid)) { fprintf (stderr, _("%s: Failed su to user %s\n"), wlp->prog, wlp->user); return -EACCES; } if (initgroups (wlp->user, rgid)) { fprintf (stderr, _("%s: Failed su to user %s\n"), wlp->prog, wlp->user); return -EACCES; } if (setreuid (ruid, pwd->pw_uid)) { fprintf (stderr, _("%s: Failed su to user %s\n"), wlp->prog, wlp->user); return -EACCES; } if (access(cwd, X_OK) < 0 && chdir(pwd->pw_dir)) { fprintf (stderr, _("%s: Failed su to user %s\n"), wlp->prog, wlp->user); return -EACCES; } free(cwd); cwd = getenv("TERM"); environ = dummy_environ; setenv("HOME", pwd->pw_dir, 1); setenv("PATH", "/bin:/usr/bin", 1); setenv("USER", pwd->pw_name, 1); setenv("LOGNAME", pwd->pw_name, 1); if (cwd) setenv("TERM", cwd, 1); envp = environ; } execve (wlp->run, argv, envp); perror ("execve"); return -errno; }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor