Commit 3a469917 authored by Guillem Jover's avatar Guillem Jover Committed by Hans de Goede
Browse files

Xorg.wrap: Clarify error messages



Not printing the program name produces very confusing messages that
might be difficult to attribute while trying to diagnose problems,
let's be explicit about who we are.

Also add a missing "/" between SUID_WRAPPER_DIR and "Xorg.bin".

Signed-off-by: Guillem Jover's avatarGuillem Jover <guillem@hadrons.org>
Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
parent 50b6e1b0
......@@ -25,6 +25,7 @@
#include "dix-config.h"
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdint.h>
......@@ -40,6 +41,8 @@
#define CONFIG_FILE SYSCONFDIR "/X11/Xwrapper.config"
static const char *progname;
enum { ROOT_ONLY, CONSOLE_ONLY, ANYBODY };
/* KISS non locale / LANG parsing isspace version */
......@@ -88,18 +91,21 @@ static void parse_config(int *allowed, int *needs_root_rights)
/* Split in a key + value pair */
equals = strchr(stripped, '=');
if (!equals) {
fprintf(stderr, "Syntax error at %s line %d\n", CONFIG_FILE, line);
fprintf(stderr, "%s: Syntax error at %s line %d\n", progname,
CONFIG_FILE, line);
exit(1);
}
*equals = 0;
key = strip(stripped); /* To remove trailing whitespace from key */
value = strip(equals + 1); /* To remove leading whitespace from val */
if (!key[0]) {
fprintf(stderr, "Missing key at %s line %d\n", CONFIG_FILE, line);
fprintf(stderr, "%s: Missing key at %s line %d\n", progname,
CONFIG_FILE, line);
exit(1);
}
if (!value[0]) {
fprintf(stderr, "Missing value at %s line %d\n", CONFIG_FILE, line);
fprintf(stderr, "%s: Missing value at %s line %d\n", progname,
CONFIG_FILE, line);
exit(1);
}
......@@ -113,8 +119,8 @@ static void parse_config(int *allowed, int *needs_root_rights)
*allowed = ANYBODY;
else {
fprintf(stderr,
"Invalid value '%s' for 'allowed_users' at %s line %d\n",
value, CONFIG_FILE, line);
"%s: Invalid value '%s' for 'allowed_users' at %s line %d\n",
progname, value, CONFIG_FILE, line);
exit(1);
}
}
......@@ -127,8 +133,8 @@ static void parse_config(int *allowed, int *needs_root_rights)
*needs_root_rights = -1;
else {
fprintf(stderr,
"Invalid value '%s' for 'needs_root_rights' at %s line %d\n",
value, CONFIG_FILE, line);
"%s: Invalid value '%s' for 'needs_root_rights' at %s line %d\n",
progname, value, CONFIG_FILE, line);
exit(1);
}
}
......@@ -136,8 +142,8 @@ static void parse_config(int *allowed, int *needs_root_rights)
/* Backward compatibility with older Debian Xwrapper, ignore */
}
else {
fprintf(stderr, "Invalid key '%s' at %s line %d\n", key,
CONFIG_FILE, line);
fprintf(stderr, "%s: Invalid key '%s' at %s line %d\n", key,
progname, CONFIG_FILE, line);
exit(1);
}
}
......@@ -155,6 +161,8 @@ int main(int argc, char *argv[])
int allowed = CONSOLE_ONLY;
int needs_root_rights = -1;
progname = argv[0];
parse_config(&allowed, &needs_root_rights);
/* For non root users check if they are allowed to run the X server */
......@@ -207,11 +215,13 @@ int main(int argc, char *argv[])
uid_t realuid = getuid();
if (setresgid(-1, realgid, realgid) != 0) {
perror("Could not drop setgid privileges");
fprintf(stderr, "%s: Could not drop setgid privileges: %s\n",
progname, strerror(errno));
exit(1);
}
if (setresuid(-1, realuid, realuid) != 0) {
perror("Could not drop setuid privileges");
fprintf(stderr, "%s: Could not drop setuid privileges: %s\n",
progname, strerror(errno));
exit(1);
}
}
......@@ -220,12 +230,14 @@ int main(int argc, char *argv[])
/* Check if the server is executable by our real uid */
if (access(buf, X_OK) != 0) {
perror("Missing execute permissions for " SUID_WRAPPER_DIR "Xorg.bin");
fprintf(stderr, "%s: Missing execute permissions for %s/Xorg.bin: %s\n",
progname, SUID_WRAPPER_DIR, strerror(errno));
exit(1);
}
argv[0] = buf;
(void) execv(argv[0], argv);
perror("Failed to execute " SUID_WRAPPER_DIR "/Xorg.bin");
fprintf(stderr, "%s: Failed to execute %s/Xorg.bin: %s\n",
progname, SUID_WRAPPER_DIR, strerror(errno));
exit(1);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment