From 9d97bd6a2d3d7aebeef0e2d5f06f83fa5c3743a4 Mon Sep 17 00:00:00 2001 From: ray Date: Wed, 21 Jul 2010 09:22:17 +0000 Subject: [PATCH] Only use username if author is NULL. Fixes "ci -wusername" when run as root. OK nicm --- usr.bin/cvs/rcs.c | 24 +++++++++--------------- usr.bin/rcs/rcs.c | 24 +++++++++--------------- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c index 1067620f10b..41281ffb423 100644 --- a/usr.bin/cvs/rcs.c +++ b/usr.bin/cvs/rcs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.c,v 1.294 2010/07/13 20:41:55 nicm Exp $ */ +/* $OpenBSD: rcs.c,v 1.295 2010/07/21 09:22:17 ray Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. @@ -1194,20 +1194,18 @@ rcs_delta_stats(struct rcs_delta *rdp, int *ladded, int *lremoved) * one). The argument specifies the log message for that revision, and * specifies the revision's date (a value of -1 is * equivalent to using the current time). - * If is NULL, set the author for this revision to the current user. - * Otherwise, set it to . + * If is NULL, set the author for this revision to the current user. * Returns 0 on success, or -1 on failure. */ int rcs_rev_add(RCSFILE *rf, RCSNUM *rev, const char *msg, time_t date, - const char *username) + const char *author) { time_t now; RCSNUM *root = NULL; struct passwd *pw; struct rcs_branch *brp, *obrp; struct rcs_delta *ordp, *rdp; - uid_t uid; if (rev == RCS_HEAD_REV) { if (rf->rf_flags & RCS_CREATE) { @@ -1227,10 +1225,6 @@ rcs_rev_add(RCSFILE *rf, RCSNUM *rev, const char *msg, time_t date, return (-1); } - uid = getuid(); - if ((pw = getpwuid(uid)) == NULL) - fatal("getpwuid failed"); - rdp = xcalloc(1, sizeof(*rdp)); TAILQ_INIT(&(rdp->rd_branches)); @@ -1240,12 +1234,12 @@ rcs_rev_add(RCSFILE *rf, RCSNUM *rev, const char *msg, time_t date, rdp->rd_next = rcsnum_alloc(); - if (uid == 0) - username = getlogin(); - if (username == NULL || *username == '\0') - username = pw->pw_name; - - rdp->rd_author = xstrdup(username); + if (!author && !(author = getlogin())) { + if (!(pw = getpwuid(getuid()))) + fatal("getpwuid failed"); + author = pw->pw_name; + } + rdp->rd_author = xstrdup(author); rdp->rd_state = xstrdup(RCS_STATE_EXP); rdp->rd_log = xstrdup(msg); diff --git a/usr.bin/rcs/rcs.c b/usr.bin/rcs/rcs.c index 1e51db144b5..f62a9418c9b 100644 --- a/usr.bin/rcs/rcs.c +++ b/usr.bin/rcs/rcs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.c,v 1.56 2010/07/13 20:07:24 nicm Exp $ */ +/* $OpenBSD: rcs.c,v 1.57 2010/07/21 09:22:19 ray Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau * All rights reserved. @@ -1344,18 +1344,16 @@ rcs_delta_stats(struct rcs_delta *rdp, int *ladded, int *lremoved) * one). The argument specifies the log message for that revision, and * specifies the revision's date (a value of -1 is * equivalent to using the current time). - * If is NULL, set the author for this revision to the current user. - * Otherwise, set it to . + * If is NULL, set the author for this revision to the current user. * Returns 0 on success, or -1 on failure. */ int rcs_rev_add(RCSFILE *rf, RCSNUM *rev, const char *msg, time_t date, - const char *username) + const char *author) { time_t now; struct passwd *pw; struct rcs_delta *ordp, *rdp; - uid_t uid; if (rev == RCS_HEAD_REV) { if (rf->rf_flags & RCS_CREATE) { @@ -1373,10 +1371,6 @@ rcs_rev_add(RCSFILE *rf, RCSNUM *rev, const char *msg, time_t date, } } - uid = getuid(); - if ((pw = getpwuid(uid)) == NULL) - errx(1, "getpwuid failed"); - rdp = xcalloc(1, sizeof(*rdp)); TAILQ_INIT(&(rdp->rd_branches)); @@ -1392,12 +1386,12 @@ rcs_rev_add(RCSFILE *rf, RCSNUM *rev, const char *msg, time_t date, rcsnum_cpy(ordp->rd_num, rdp->rd_next, 0); } - if (uid == 0) - username = getlogin(); - if (username == NULL || *username == '\0') - username = pw->pw_name; - - rdp->rd_author = xstrdup(username); + if (!author && !(author = getlogin())) { + if (!(pw = getpwuid(getuid()))) + errx(1, "getpwuid failed"); + author = pw->pw_name; + } + rdp->rd_author = xstrdup(author); rdp->rd_state = xstrdup(RCS_STATE_EXP); rdp->rd_log = xstrdup(msg); -- 2.20.1