From: millert Date: Sun, 16 Sep 2018 02:38:57 +0000 (+0000) Subject: Replace the local getname() and getuserid() functions with calls X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=d6fbb2f1dca5fb2df732e8962239b8a7b681a891;p=openbsd Replace the local getname() and getuserid() functions with calls to user_from_uid(3) and uid_from_user(3). This requires sprinkling const in a few places to match the return value of user_from_uid(3). OK tb@ --- diff --git a/usr.bin/mail/Makefile b/usr.bin/mail/Makefile index caf5408573e..0cddfaf4ba9 100644 --- a/usr.bin/mail/Makefile +++ b/usr.bin/mail/Makefile @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile,v 1.11 2016/03/30 06:38:46 jmc Exp $ +# $OpenBSD: Makefile,v 1.12 2018/09/16 02:38:57 millert Exp $ PROG= mail SRCS= version.c aux.c cmd1.c cmd2.c cmd3.c cmdtab.c collect.c \ - edit.c fio.c getname.c head.c v7.local.c lex.c list.c main.c names.c \ + edit.c fio.c head.c v7.local.c lex.c list.c main.c names.c \ popen.c quit.c send.c strings.c temp.c tty.c vars.c SFILES= mail.help mail.tildehelp EFILES= mail.rc diff --git a/usr.bin/mail/aux.c b/usr.bin/mail/aux.c index 830be426c69..a7bb8d67314 100644 --- a/usr.bin/mail/aux.c +++ b/usr.bin/mail/aux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aux.c,v 1.29 2015/10/16 17:56:07 mmcc Exp $ */ +/* $OpenBSD: aux.c,v 1.30 2018/09/16 02:38:57 millert Exp $ */ /* $NetBSD: aux.c,v 1.5 1997/05/13 06:15:52 mikel Exp $ */ /* @@ -45,7 +45,7 @@ static char *save2str(char *, char *); * Return a pointer to a dynamic copy of the argument. */ char * -savestr(char *str) +savestr(const char *str) { char *new; int size = strlen(str) + 1; diff --git a/usr.bin/mail/extern.h b/usr.bin/mail/extern.h index 61f022bec25..60a1088b83b 100644 --- a/usr.bin/mail/extern.h +++ b/usr.bin/mail/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.28 2015/01/20 16:59:07 millert Exp $ */ +/* $OpenBSD: extern.h,v 1.29 2018/09/16 02:38:57 millert Exp $ */ /* $NetBSD: extern.h,v 1.7 1997/07/09 05:22:00 mikel Exp $ */ /*- @@ -30,12 +30,12 @@ * SUCH DAMAGE. * * @(#)extern.h 8.2 (Berkeley) 4/20/95 - * $OpenBSD: extern.h,v 1.28 2015/01/20 16:59:07 millert Exp $ + * $OpenBSD: extern.h,v 1.29 2018/09/16 02:38:57 millert Exp $ */ struct name; struct name *cat(struct name *, struct name *); -struct name *delname(struct name *, char *); +struct name *delname(struct name *, const char *); struct name *elide(struct name *); struct name *extract(char *, int); struct grouphead; @@ -55,7 +55,6 @@ char *copyin(char *, char **); char *detract(struct name *, int); char *expand(char *); char *getdeadletter(void); -char *getname(uid_t); struct message; char *hfield(char *, struct message *); FILE *infix(struct header *, FILE *); @@ -67,12 +66,13 @@ char *readtty(char *, char *); char *reedit(char *); FILE *run_editor(FILE *, off_t, int, int); char *salloc(int); -char *savestr(char *); +char *savestr(const char *); FILE *setinput(struct message *); char *skin(char *); char *skip_comment(char *); char *snarf(char *, int *); -char *username(void); +const char + *username(void); char *value(char *); char *vcopy(char *); char *yankword(char *, char *); @@ -119,7 +119,7 @@ void fail(char *, char *); int file(void *); struct grouphead * findgroup(char *); -void findmail(char *, char *, int); +void findmail(const char *, char *, int); void fioint(int); int first(int, int); void fixhead(struct header *, struct name *); @@ -134,7 +134,6 @@ int gethfield(FILE *, char *, int, char **); int gethfromtty(struct header *, int); int getmsglist(char *, int *, int); int getrawlist(char *, char **, int); -uid_t getuserid(char *); int grabh(struct header *, int); int group(void *); int hash(char *); diff --git a/usr.bin/mail/getname.c b/usr.bin/mail/getname.c deleted file mode 100644 index 61045d9dc44..00000000000 --- a/usr.bin/mail/getname.c +++ /dev/null @@ -1,64 +0,0 @@ -/* $OpenBSD: getname.c,v 1.8 2009/10/27 23:59:40 deraadt Exp $ */ -/* $NetBSD: getname.c,v 1.4 1996/06/08 19:48:23 christos Exp $ */ - -/* - * Copyright (c) 1980, 1993 - * The Regents of the University of California. All rights reserved. - * - * 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. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. - */ - -#include "rcv.h" -#include -#include "extern.h" - -/* Getname / getuserid for those with hashed passwd data base. */ - -/* - * Search the passwd file for a uid. Return name on success, NULL on failure - */ -char * -getname(uid_t uid) -{ - struct passwd *pw; - - if ((pw = getpwuid(uid)) == NULL) - return(NULL); - return(pw->pw_name); -} - -/* - * Convert the passed name to a user id and return it. Return -1 - * on error. - */ -uid_t -getuserid(char *name) -{ - struct passwd *pw; - - if ((pw = getpwnam(name)) == NULL) - return(UID_MAX); - return(pw->pw_uid); -} diff --git a/usr.bin/mail/glob.h b/usr.bin/mail/glob.h index 27ea07f65c8..92da4302493 100644 --- a/usr.bin/mail/glob.h +++ b/usr.bin/mail/glob.h @@ -1,4 +1,4 @@ -/* $OpenBSD: glob.h,v 1.8 2014/11/24 20:01:43 millert Exp $ */ +/* $OpenBSD: glob.h,v 1.9 2018/09/16 02:38:57 millert Exp $ */ /* $NetBSD: glob.h,v 1.4 1996/06/08 19:48:25 christos Exp $ */ /* @@ -54,7 +54,8 @@ FILE *input; /* Current command input file */ char mailname[PATHSIZE]; /* Name of current file */ char prevfile[PATHSIZE]; /* Name of previous file */ char *homedir; /* Path name of home directory */ -char *myname; /* My login name */ +const char + *myname; /* My login name */ off_t mailsize; /* Size of system mailbox */ int lexnumber; /* Number of TNUMBER from scan() */ char lexstring[STRINGLEN]; /* String from TSTRING, scan() */ diff --git a/usr.bin/mail/lex.c b/usr.bin/mail/lex.c index 2ad3ea3a898..4e2706c4809 100644 --- a/usr.bin/mail/lex.c +++ b/usr.bin/mail/lex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.c,v 1.39 2015/10/16 17:56:07 mmcc Exp $ */ +/* $OpenBSD: lex.c,v 1.40 2018/09/16 02:38:57 millert Exp $ */ /* $NetBSD: lex.c,v 1.10 1997/05/17 19:55:13 pk Exp $ */ /* @@ -58,7 +58,7 @@ setfile(char *name) int i, fd; struct stat stb; char isedit = *name != '%'; - char *who = name[1] ? name + 1 : myname; + const char *who = name[1] ? name + 1 : myname; char tempname[PATHSIZE]; static int shudclob; diff --git a/usr.bin/mail/names.c b/usr.bin/mail/names.c index 5562070c736..5b07dc6817c 100644 --- a/usr.bin/mail/names.c +++ b/usr.bin/mail/names.c @@ -1,4 +1,4 @@ -/* $OpenBSD: names.c,v 1.23 2015/10/16 17:56:07 mmcc Exp $ */ +/* $OpenBSD: names.c,v 1.24 2018/09/16 02:38:57 millert Exp $ */ /* $NetBSD: names.c,v 1.5 1996/06/08 19:48:32 christos Exp $ */ /* @@ -582,7 +582,7 @@ count(struct name *np) * Delete the given name from a namelist. */ struct name * -delname(struct name *np, char *name) +delname(struct name *np, const char *name) { struct name *p; diff --git a/usr.bin/mail/temp.c b/usr.bin/mail/temp.c index 0f25855c1c7..6f287ae3c0d 100644 --- a/usr.bin/mail/temp.c +++ b/usr.bin/mail/temp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: temp.c,v 1.17 2016/07/28 21:37:45 tedu Exp $ */ +/* $OpenBSD: temp.c,v 1.18 2018/09/16 02:38:57 millert Exp $ */ /* $NetBSD: temp.c,v 1.5 1996/06/08 19:48:42 christos Exp $ */ /* @@ -31,6 +31,7 @@ */ #include "rcv.h" +#include #include "extern.h" /* @@ -62,15 +63,17 @@ tinit(void) * do a spreserve() after us. */ if (myname != NULL) { - if (getuserid(myname) == UID_MAX) + uid_t uid; + + if (uid_from_user(myname, &uid) == -1) errx(1, "\"%s\" is not a user of this system", myname); } else { - if ((cp = username()) == NULL) { + if ((myname = username()) == NULL) { myname = "nobody"; if (rcvmode) exit(1); } else - myname = savestr(cp); + myname = savestr(myname); } if ((cp = getenv("HOME")) == NULL || *cp == '\0' || strlen(cp) >= PATHSIZE) diff --git a/usr.bin/mail/v7.local.c b/usr.bin/mail/v7.local.c index f9cf2ef7f13..555a13230ca 100644 --- a/usr.bin/mail/v7.local.c +++ b/usr.bin/mail/v7.local.c @@ -1,4 +1,4 @@ -/* $OpenBSD: v7.local.c,v 1.17 2016/07/19 06:43:27 deraadt Exp $ */ +/* $OpenBSD: v7.local.c,v 1.18 2018/09/16 02:38:57 millert Exp $ */ /* $NetBSD: v7.local.c,v 1.8 1997/05/13 06:15:58 mikel Exp $ */ /* @@ -41,6 +41,7 @@ #include "rcv.h" #include #include +#include #include "extern.h" /* @@ -48,7 +49,7 @@ * mail is queued). */ void -findmail(char *user, char *buf, int buflen) +findmail(const char *user, char *buf, int buflen) { char *mbox; struct stat sb; @@ -82,20 +83,20 @@ demail(void) /* * Discover user login name. */ -char * +const char * username(void) { - char *np; + const char *np; uid_t uid; if ((np = getenv("USER")) != NULL) return(np); if ((np = getenv("LOGNAME")) != NULL) return(np); - if ((np = getname(uid = getuid())) != NULL) + if ((np = user_from_uid(uid = getuid(), 1)) != NULL) return(np); if ((np = getlogin()) != NULL) return(np); - printf("Cannot associate a name with uid %u\n", (unsigned)uid); + printf("Cannot associate a name with uid %u\n", uid); return(NULL); }