summaryrefslogtreecommitdiff
path: root/libmisc/idmapping.c
diff options
context:
space:
mode:
Diffstat (limited to 'libmisc/idmapping.c')
-rw-r--r--libmisc/idmapping.c70
1 files changed, 24 insertions, 46 deletions
diff --git a/libmisc/idmapping.c b/libmisc/idmapping.c
index 3324f671..8b64a26a 100644
--- a/libmisc/idmapping.c
+++ b/libmisc/idmapping.c
@@ -1,30 +1,7 @@
/*
- * Copyright (c) 2013 Eric Biederman
- * All rights reserved.
+ * SPDX-FileCopyrightText: 2013 Eric Biederman
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the copyright holders or contributors may not be used to
- * endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPDX-License-Identifier: BSD-3-Clause
*/
#include <config.h>
@@ -40,6 +17,7 @@
#include <sys/prctl.h>
#include <sys/capability.h>
#endif
+#include "shadowlog.h"
struct map_range *get_map_ranges(int ranges, int argc, char **argv)
{
@@ -47,28 +25,28 @@ struct map_range *get_map_ranges(int ranges, int argc, char **argv)
int idx, argidx;
if (ranges < 0 || argc < 0) {
- fprintf(shadow_logfd, "%s: error calculating number of arguments\n", Prog);
+ fprintf(log_get_logfd(), "%s: error calculating number of arguments\n", log_get_progname());
return NULL;
}
if (ranges != ((argc + 2) / 3)) {
- fprintf(shadow_logfd, "%s: ranges: %u is wrong for argc: %d\n", Prog, ranges, argc);
+ fprintf(log_get_logfd(), "%s: ranges: %u is wrong for argc: %d\n", log_get_progname(), ranges, argc);
return NULL;
}
if ((ranges * 3) > argc) {
- fprintf(shadow_logfd, "ranges: %u argc: %d\n",
+ fprintf(log_get_logfd(), "ranges: %u argc: %d\n",
ranges, argc);
- fprintf(shadow_logfd,
+ fprintf(log_get_logfd(),
_( "%s: Not enough arguments to form %u mappings\n"),
- Prog, ranges);
+ log_get_progname(), ranges);
return NULL;
}
mappings = calloc(ranges, sizeof(*mappings));
if (!mappings) {
- fprintf(shadow_logfd, _( "%s: Memory allocation failure\n"),
- Prog);
+ fprintf(log_get_logfd(), _( "%s: Memory allocation failure\n"),
+ log_get_progname());
exit(EXIT_FAILURE);
}
@@ -88,24 +66,24 @@ struct map_range *get_map_ranges(int ranges, int argc, char **argv)
return NULL;
}
if (ULONG_MAX - mapping->upper <= mapping->count || ULONG_MAX - mapping->lower <= mapping->count) {
- fprintf(shadow_logfd, _( "%s: subuid overflow detected.\n"), Prog);
+ fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname());
exit(EXIT_FAILURE);
}
if (mapping->upper > UINT_MAX ||
mapping->lower > UINT_MAX ||
mapping->count > UINT_MAX) {
- fprintf(shadow_logfd, _( "%s: subuid overflow detected.\n"), Prog);
+ fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname());
exit(EXIT_FAILURE);
}
if (mapping->lower + mapping->count > UINT_MAX ||
mapping->upper + mapping->count > UINT_MAX) {
- fprintf(shadow_logfd, _( "%s: subuid overflow detected.\n"), Prog);
+ fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname());
exit(EXIT_FAILURE);
}
if (mapping->lower + mapping->count < mapping->lower ||
mapping->upper + mapping->count < mapping->upper) {
/* this one really shouldn't be possible given previous checks */
- fprintf(shadow_logfd, _( "%s: subuid overflow detected.\n"), Prog);
+ fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname());
exit(EXIT_FAILURE);
}
}
@@ -176,19 +154,19 @@ void write_mapping(int proc_dir_fd, int ranges, struct map_range *mappings,
} else if (strcmp(map_file, "gid_map") == 0) {
cap = CAP_SETGID;
} else {
- fprintf(shadow_logfd, _("%s: Invalid map file %s specified\n"), Prog, map_file);
+ fprintf(log_get_logfd(), _("%s: Invalid map file %s specified\n"), log_get_progname(), map_file);
exit(EXIT_FAILURE);
}
/* Align setuid- and fscaps-based new{g,u}idmap behavior. */
if (geteuid() == 0 && geteuid() != ruid) {
if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) < 0) {
- fprintf(shadow_logfd, _("%s: Could not prctl(PR_SET_KEEPCAPS)\n"), Prog);
+ fprintf(log_get_logfd(), _("%s: Could not prctl(PR_SET_KEEPCAPS)\n"), log_get_progname());
exit(EXIT_FAILURE);
}
if (seteuid(ruid) < 0) {
- fprintf(shadow_logfd, _("%s: Could not seteuid to %d\n"), Prog, ruid);
+ fprintf(log_get_logfd(), _("%s: Could not seteuid to %d\n"), log_get_progname(), ruid);
exit(EXIT_FAILURE);
}
}
@@ -204,12 +182,12 @@ void write_mapping(int proc_dir_fd, int ranges, struct map_range *mappings,
data[0].effective |= CAP_TO_MASK(CAP_SETFCAP);
data[0].permitted = data[0].effective;
if (capset(&hdr, data) < 0) {
- fprintf(shadow_logfd, _("%s: Could not set caps\n"), Prog);
+ fprintf(log_get_logfd(), _("%s: Could not set caps\n"), log_get_progname());
exit(EXIT_FAILURE);
}
#endif
- bufsize = ranges * ((ULONG_DIGITS + 1) * 3);
+ bufsize = ranges * ((ULONG_DIGITS + 1) * 3);
pos = buf = xmalloc(bufsize);
/* Build the mapping command */
@@ -222,7 +200,7 @@ void write_mapping(int proc_dir_fd, int ranges, struct map_range *mappings,
mapping->lower,
mapping->count);
if ((written <= 0) || (written >= (bufsize - (pos - buf)))) {
- fprintf(shadow_logfd, _("%s: snprintf failed!\n"), Prog);
+ fprintf(log_get_logfd(), _("%s: snprintf failed!\n"), log_get_progname());
exit(EXIT_FAILURE);
}
pos += written;
@@ -231,13 +209,13 @@ void write_mapping(int proc_dir_fd, int ranges, struct map_range *mappings,
/* Write the mapping to the mapping file */
fd = openat(proc_dir_fd, map_file, O_WRONLY);
if (fd < 0) {
- fprintf(shadow_logfd, _("%s: open of %s failed: %s\n"),
- Prog, map_file, strerror(errno));
+ fprintf(log_get_logfd(), _("%s: open of %s failed: %s\n"),
+ log_get_progname(), map_file, strerror(errno));
exit(EXIT_FAILURE);
}
if (write(fd, buf, pos - buf) != (pos - buf)) {
- fprintf(shadow_logfd, _("%s: write to %s failed: %s\n"),
- Prog, map_file, strerror(errno));
+ fprintf(log_get_logfd(), _("%s: write to %s failed: %s\n"),
+ log_get_progname(), map_file, strerror(errno));
exit(EXIT_FAILURE);
}
close(fd);