diff --git a/Makefile.in b/Makefile.in index 9f9e67e..b4b1f8c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -29,7 +29,7 @@ LIBDIR=$(PREFIX)/lib$(MARK64) BINDIR=$(PREFIX)/bin DATADIR=$(PREFIX)/var/pseudo -CFLAGS_BASE=-pipe -std=gnu99 -Wall +CFLAGS_BASE=-pipe -std=gnu99 -Wall -W -Wextra CFLAGS_CODE=-fPIC -D_LARGEFILE64_SOURCE -D_ATFILE_SOURCE -m$(BITS) CFLAGS_DEFS=-DPSEUDO_PREFIX='"$(PREFIX)"' -DPSEUDO_SUFFIX='"$(SUFFIX)"' -DPSEUDO_VERSION='"$(VERSION)"' CFLAGS_DEBUG=-O2 -g @@ -92,8 +92,6 @@ pseudo_client.o: pseudo_client.h pseudo_server.o: pseudo_server.h -pseudo_wrappers.o: $(GUTS) - wrappers: wrapfuncs.in $(USE_64) makewrappers ./makewrappers wrapfuncs.in $(USE_64) @@ -102,7 +100,7 @@ wrappers: wrapfuncs.in $(USE_64) makewrappers pseudo_wrappers.c: wrappers # no-strict-aliasing is needed for the function pointer trickery. -pseudo_wrappers.o: pseudo_wrappers.c +pseudo_wrappers.o: $(GUTS) pseudo_wrappers.c $(CC) -fno-strict-aliasing $(CFLAGS) -D_GNU_SOURCE -c -o pseudo_wrappers.o pseudo_wrappers.c offsets32: diff --git a/guts/fchown.c b/guts/fchown.c index 53a34de..4e717ea 100644 --- a/guts/fchown.c +++ b/guts/fchown.c @@ -14,7 +14,7 @@ errno = save_errno; return -1; } - if (owner == -1 || group == -1) { + if (owner == (uid_t) -1 || group == (gid_t) -1) { msg = pseudo_client_op(OP_STAT, fd, -1, NULL, &buf); /* copy in any existing values... */ if (msg) { @@ -30,10 +30,10 @@ } } /* now override with arguments */ - if (owner != -1) { + if (owner != (uid_t) -1) { buf.st_uid = owner; } - if (group != -1) { + if (group != (gid_t) -1) { buf.st_gid = group; } pseudo_debug(2, "fchown, fd %d: %d:%d -> %d:%d\n", diff --git a/guts/fchownat.c b/guts/fchownat.c index 181fa6d..23dac7b 100644 --- a/guts/fchownat.c +++ b/guts/fchownat.c @@ -30,22 +30,24 @@ } save_errno = errno; - msg = pseudo_client_op(OP_STAT, -1, -1, path, &buf); - /* copy in any existing values... */ - if (msg) { - if (msg->result == RESULT_SUCCEED) { - pseudo_stat_msg(&buf, msg); - } else { - pseudo_debug(2, "chownat to %d:%d on %d/%s, ino %llu, new file.\n", - owner, group, dirfd, path, - (unsigned long long) buf.st_ino); + if (owner == (uid_t) -1 || group == (gid_t) -1) { + msg = pseudo_client_op(OP_STAT, -1, -1, path, &buf); + /* copy in any existing values... */ + if (msg) { + if (msg->result == RESULT_SUCCEED) { + pseudo_stat_msg(&buf, msg); + } else { + pseudo_debug(2, "chownat to %d:%d on %d/%s, ino %llu, new file.\n", + owner, group, dirfd, path, + (unsigned long long) buf.st_ino); + } } } /* now override with arguments */ - if (owner != -1) { + if (owner != (uid_t) -1) { buf.st_uid = owner; } - if (group != -1) { + if (group != (gid_t) -1) { buf.st_gid = group; } msg = pseudo_client_op(OP_CHOWN, -1, dirfd, path, &buf); diff --git a/guts/fts_open.c b/guts/fts_open.c index d244861..bd71a8e 100644 --- a/guts/fts_open.c +++ b/guts/fts_open.c @@ -4,7 +4,7 @@ * FTS * rc = NULL; */ char **rpath_argv; - size_t args = 0; + int args = 0; int errored = 0; int i; diff --git a/guts/lchown.c b/guts/lchown.c index 2d0aff2..be06a8d 100644 --- a/guts/lchown.c +++ b/guts/lchown.c @@ -2,49 +2,8 @@ * static int * wrap_lchown(const char *path, uid_t owner, gid_t group) { */ - pseudo_msg_t *msg; - struct stat64 buf; - if (!path) { - errno = EFAULT; - return -1; - } - pseudo_debug(2, "lchown(%s, %d, %d)\n", - path ? path : "", owner, group); - if (real___lxstat64(_STAT_VER, path, &buf) == -1) { - return -1; - } - if (owner == -1 || group == -1) { - msg = pseudo_client_op(OP_STAT, -1, -1, path, &buf); - /* copy in any existing values... */ - if (msg) { - if (msg->result == RESULT_SUCCEED) { - pseudo_stat_msg(&buf, msg); - } else { - pseudo_debug(2, "lchown to %d:%d on %s, ino %llu, new file.\n", - owner, group, path, - (unsigned long long) buf.st_ino); - } - } else { - pseudo_diag("stat within lchown of '%s' [%llu] failed.\n", - path, (unsigned long long) buf.st_ino); - } - } - if (owner != -1) { - buf.st_uid = owner; - } - if (group != -1) { - buf.st_gid = group; - } - msg = pseudo_client_op(OP_CHOWN, -1, -1, path, &buf); - if (!msg) { - errno = ENOSYS; - rc = -1; - } else if (msg->result != RESULT_SUCCEED) { - errno = msg->xerrno; - rc = -1; - } else { - rc = 0; - } + + rc = wrap_fchownat(AT_FDCWD, path, owner, group, AT_SYMLINK_NOFOLLOW); /* return rc; * } diff --git a/guts/realpath.c b/guts/realpath.c index 5b1a5f8..2f2dcf6 100644 --- a/guts/realpath.c +++ b/guts/realpath.c @@ -4,7 +4,7 @@ * char * rc = NULL; */ char *rname = PSEUDO_ROOT_PATH(AT_FDCWD, name, 0); - size_t len; + ssize_t len; if (!rname) { errno = ENAMETOOLONG; return NULL; diff --git a/guts/setregid.c b/guts/setregid.c index 2444390..0be0146 100644 --- a/guts/setregid.c +++ b/guts/setregid.c @@ -4,20 +4,20 @@ * int rc = -1; */ rc = 0; - if (pseudo_euid != 0 && rgid != -1 && + if (pseudo_euid != 0 && rgid != (gid_t) -1 && rgid != pseudo_egid && rgid != pseudo_rgid && rgid != pseudo_sgid) { rc = -1; errno = EPERM; } - if (pseudo_euid != 0 && egid != -1 && + if (pseudo_euid != 0 && egid != (gid_t) -1 && egid != pseudo_egid && egid != pseudo_rgid && egid != pseudo_sgid) { rc = -1; errno = EPERM; } if (rc != -1) { - if (rgid != -1) + if (rgid != (gid_t) -1) pseudo_rgid = rgid; - if (egid != -1) + if (egid != (gid_t) -1) pseudo_egid = egid; pseudo_fgid = pseudo_egid; pseudo_client_touchuid(); diff --git a/guts/setresgid.c b/guts/setresgid.c index 455fe62..b6491ad 100644 --- a/guts/setresgid.c +++ b/guts/setresgid.c @@ -4,27 +4,27 @@ * int rc = -1; */ rc = 0; - if (pseudo_euid != 0 && rgid != -1 && + if (pseudo_euid != 0 && rgid != (gid_t) -1 && rgid != pseudo_egid && rgid != pseudo_rgid && rgid != pseudo_sgid) { rc = -1; errno = EPERM; } - if (pseudo_euid != 0 && egid != -1 && + if (pseudo_euid != 0 && egid != (gid_t) -1 && egid != pseudo_egid && egid != pseudo_rgid && egid != pseudo_sgid) { rc = -1; errno = EPERM; } - if (pseudo_euid != 0 && sgid != -1 && + if (pseudo_euid != 0 && sgid != (gid_t) -1 && sgid != pseudo_egid && sgid != pseudo_rgid && sgid != pseudo_sgid) { rc = -1; errno = EPERM; } if (rc != -1) { - if (rgid != -1) + if (rgid != (gid_t) -1) pseudo_rgid = rgid; - if (egid != -1) + if (egid != (gid_t) -1) pseudo_egid = egid; - if (sgid != -1) + if (sgid != (gid_t) -1) pseudo_sgid = sgid; pseudo_fgid = pseudo_egid; pseudo_client_touchuid(); diff --git a/guts/setresuid.c b/guts/setresuid.c index 41dd81d..9c07e4c 100644 --- a/guts/setresuid.c +++ b/guts/setresuid.c @@ -4,27 +4,27 @@ * int rc = -1; */ rc = 0; - if (pseudo_euid != 0 && ruid != -1 && + if (pseudo_euid != 0 && ruid != (uid_t) -1 && ruid != pseudo_euid && ruid != pseudo_ruid && ruid != pseudo_suid) { rc = -1; errno = EPERM; } - if (pseudo_euid != 0 && euid != -1 && + if (pseudo_euid != 0 && euid != (uid_t) -1 && euid != pseudo_euid && euid != pseudo_ruid && euid != pseudo_suid) { rc = -1; errno = EPERM; } - if (pseudo_euid != 0 && suid != -1 && + if (pseudo_euid != 0 && suid != (uid_t) -1 && suid != pseudo_euid && suid != pseudo_ruid && suid != pseudo_suid) { rc = -1; errno = EPERM; } if (rc != -1) { - if (ruid != -1) + if (ruid != (uid_t) -1) pseudo_ruid = ruid; - if (euid != -1) + if (euid != (uid_t) -1) pseudo_euid = euid; - if (suid != -1) + if (suid != (uid_t) -1) pseudo_suid = suid; pseudo_fuid = pseudo_euid; pseudo_client_touchuid(); diff --git a/guts/setreuid.c b/guts/setreuid.c index 3669581..7b7fe52 100644 --- a/guts/setreuid.c +++ b/guts/setreuid.c @@ -4,20 +4,20 @@ * int rc = -1; */ rc = 0; - if (pseudo_euid != 0 && ruid != -1 && + if (pseudo_euid != 0 && ruid != (uid_t) -1 && ruid != pseudo_euid && ruid != pseudo_ruid && ruid != pseudo_suid) { rc = -1; errno = EPERM; } - if (pseudo_euid != 0 && euid != -1 && + if (pseudo_euid != 0 && euid != (uid_t) -1 && euid != pseudo_euid && euid != pseudo_ruid && euid != pseudo_suid) { rc = -1; errno = EPERM; } if (rc != -1) { - if (ruid != -1) + if (ruid != (uid_t) -1) pseudo_ruid = ruid; - if (euid != -1) + if (euid != (uid_t) -1) pseudo_euid = euid; pseudo_fuid = pseudo_euid; pseudo_client_touchuid(); diff --git a/makewrappers b/makewrappers index bc01e0d..905372f 100755 --- a/makewrappers +++ b/makewrappers @@ -163,6 +163,7 @@ do set -- $args IFS=$save_IFS args='' + dummy_args='' optional_arg=false prepend='' depth=0 @@ -207,6 +208,7 @@ do ...*) optional_arg=true args="$args${args:+, }..." + dummy_args="$dummy_args${dummy_args:+, }..." arg=`expr "$arg" : '\.\.\.{\(.*\)}'` argname=`expr "$arg" : '.*[^a-zA-Z0-9_]\([a-zA-Z0-9_]*\)$'` argnames="$argnames${argnames:+, }$argname" @@ -221,6 +223,7 @@ do *\(*) # function pointer argname=`expr "$arg" : '[^(]*(\*\([a-zA-Z0-9_]*\).*'` args="$args${args:+, }$arg" + dummy_args="$dummy_args${dummy_args:+, }$arg __attribute__((unused))" wrapargnames="$wrapargnames${wrapargnames:+, }$argname" argnames="$argnames${argnames:+, }$argname" prev_argname=$argname @@ -228,6 +231,7 @@ do *) argname=`expr "$arg" : '.*[^a-zA-Z0-9_](*\([a-zA-Z0-9_]*\))*(*)*$'` args="$args${args:+, }$arg" + dummy_args="$dummy_args${dummy_args:+, }$arg __attribute__((unused))" # special handling for canonicalization # set this before changing path -> rpath, for guts files wrapargnames="$wrapargnames${wrapargnames:+, }$argname" @@ -278,7 +282,7 @@ Unknown type '$type'." ; exit 1 ;; # first the dummy, and the function pointer: cat >&5 <tail, b->buflen - curlen, fmt, ap); va_end(ap); - if (rc >= (b->buflen - curlen)) { + if ((rc > 0) && ((size_t) rc >= (b->buflen - curlen))) { size_t newlen = b->buflen; while (newlen <= (rc + curlen)) newlen *= 2; @@ -819,7 +819,7 @@ frag(buffer *b, char *fmt, ...) { va_start(ap, fmt); rc = vsnprintf(b->tail, b->buflen - curlen, fmt, ap); va_end(ap); - if (rc >= (b->buflen - curlen)) { + if ((rc > 0) && ((size_t) rc >= (b->buflen - curlen))) { pseudo_diag("tried to reallocate larger buffer, failed. giving up.\n"); return -1; } diff --git a/pseudo_ipc.c b/pseudo_ipc.c index cd18140..61e00b8 100644 --- a/pseudo_ipc.c +++ b/pseudo_ipc.c @@ -37,7 +37,7 @@ static sig_atomic_t pipe_error = 0; static void (*old_handler)(int) = SIG_DFL; static void -sigpipe_trap(int unused) { +sigpipe_trap(int unused __attribute__((unused))) { pipe_error = 1; } @@ -86,7 +86,7 @@ pseudo_msg_send(int fd, pseudo_msg_t *msg, size_t len, const char *path) { if (path) { pseudo_debug(4, "msg type %d (%s), external path %s, mode 0%o\n", msg->type, pseudo_op_name(msg->op), path, (int) msg->mode); - if (len == -1) + if (len == (size_t) -1) len = strlen(path) + 1; msg->pathlen = len; ignore_sigpipe(); @@ -98,7 +98,7 @@ pseudo_msg_send(int fd, pseudo_msg_t *msg, size_t len, const char *path) { pseudo_debug(5, "wrote %d bytes\n", r); if (pipe_error || (r == -1 && errno == EBADF)) return -1; - return (r != PSEUDO_HEADER_SIZE + len); + return ((size_t) r != PSEUDO_HEADER_SIZE + len); } else { pseudo_debug(4, "msg type %d (%s), result %d (%s), path %.*s, mode 0%o\n", msg->type, pseudo_op_name(msg->op), @@ -111,7 +111,7 @@ pseudo_msg_send(int fd, pseudo_msg_t *msg, size_t len, const char *path) { pseudo_debug(5, "wrote %d bytes\n", r); if (pipe_error || (r == -1 && errno == EBADF)) return -1; - return (r != PSEUDO_HEADER_SIZE + msg->pathlen); + return ((size_t) r != PSEUDO_HEADER_SIZE + msg->pathlen); } } @@ -153,7 +153,7 @@ pseudo_msg_receive(int fd) { *incoming = header; if (incoming->pathlen) { r = read(fd, incoming->path, incoming->pathlen); - if (r < incoming->pathlen) { + if (r < (int) incoming->pathlen) { pseudo_debug(2, "short read on path, expecting %d, got %d\n", (int) incoming->pathlen, r); return 0; diff --git a/pseudo_server.c b/pseudo_server.c index 81fbd4a..7563700 100644 --- a/pseudo_server.c +++ b/pseudo_server.c @@ -71,7 +71,7 @@ quit_now(int signal) { } static int messages = 0; -static struct timeval message_time = { 0 }; +static struct timeval message_time = { .tv_sec = 0 }; static void pseudo_server_loop(void); diff --git a/pseudo_util.c b/pseudo_util.c index dcd571f..a57f8ac 100644 --- a/pseudo_util.c +++ b/pseudo_util.c @@ -457,7 +457,7 @@ pseudo_prefix_path(char *file) { rc = snprintf(path, len, "%s", prefix); /* this certainly SHOULD be impossible */ - if (rc >= len) + if ((size_t) rc >= len) rc = len - 1; endptr = path + rc; /* strip extra slashes. @@ -494,7 +494,7 @@ pseudo_get_prefix(char *pathname) { } tmp_path = pseudo_fix_path(NULL, mypath, 0, 0, 0, AT_SYMLINK_NOFOLLOW); /* point s to the end of the fixed path */ - if (strlen(tmp_path) >= pseudo_path_max()) { + if ((int) strlen(tmp_path) >= pseudo_path_max()) { pseudo_diag("Can't expand path '%s' -- expansion exceeds %d.\n", mypath, (int) pseudo_path_max()); free(tmp_path); diff --git a/pseudodb.c b/pseudodb.c index 15bc158..9203648 100644 --- a/pseudodb.c +++ b/pseudodb.c @@ -33,7 +33,7 @@ main(int argc, char **argv) { pseudo_msg_t *msg; int rc; - if (!argv[1]) { + if (argc < 2) { fprintf(stderr, "Usage: pseudodb \n"); exit(1); } diff --git a/pseudolog.c b/pseudolog.c index ddce948..ae405c5 100644 --- a/pseudolog.c +++ b/pseudolog.c @@ -38,7 +38,7 @@ static int opt_D = 0; static int opt_l = 0; static void display(log_entry *, char *format); -static unsigned long format_scan(char *format); +static int format_scan(char *format); void usage(int status) { @@ -268,13 +268,13 @@ parse_mode_string(char *string) { if (len == 10) { mode |= parse_file_type(string); ++string; - if (mode == -1) { + if (mode == (mode_t) -1) { pseudo_diag("mode strings with a file type must use a valid type [-bcdflps]\n"); return -1; } } bits = parse_partial_mode(string); - if (bits == -1) + if (bits == (mode_t) -1) return -1; if (bits & 010) { mode |= S_ISUID; @@ -283,7 +283,7 @@ parse_mode_string(char *string) { mode |= bits << 6; string += 3; bits = parse_partial_mode(string); - if (bits == -1) + if (bits == (mode_t) -1) return -1; if (bits & 010) { mode |= S_ISGID; @@ -292,7 +292,7 @@ parse_mode_string(char *string) { mode |= bits << 3; string += 3; bits = parse_partial_mode(string); - if (bits == -1) + if (bits == (mode_t) -1) return -1; if (bits & 010) { mode |= S_ISVTX; @@ -390,7 +390,7 @@ plog_trait(int opt, char *string) { return 0; } new_trait->data.ivalue = parse_file_type(string); - if (new_trait->data.ivalue == -1) { + if (new_trait->data.ivalue == (mode_t) -1) { free(new_trait); return 0; } @@ -417,7 +417,7 @@ plog_trait(int opt, char *string) { break; case PSQF_STAMP: new_trait->data.ivalue = parse_timestamp(string); - if (new_trait->data.ivalue == (time_t) -1) { + if ((time_t) new_trait->data.ivalue == (time_t) -1) { free(new_trait); return 0; } @@ -444,7 +444,7 @@ plog_trait(int opt, char *string) { } /* maybe it's a mode string? */ new_trait->data.ivalue = parse_mode_string(string); - if (new_trait->data.ivalue == -1) { + if (new_trait->data.ivalue == (mode_t) -1) { free(new_trait); return 0; } @@ -578,7 +578,7 @@ main(int argc, char **argv) { if (opt_l) { pdb_log_traits(traits); } else { - unsigned long fields; + int fields; fields = format_scan(format); if (fields == -1) { pseudo_diag("couldn't parse format string (%s).\n", format); @@ -720,11 +720,11 @@ format_one(log_entry *e, char *format) { return format + len; } -static unsigned long +static int format_scan(char *format) { char *s; size_t len; - unsigned long fields = 0; + int fields = 0; pseudo_query_field_t field; for (s = format; (s = strchr(s, '%')) != NULL; ++s) {