diff --git a/usr.sbin/user/user.c b/usr.sbin/user/user.c index c89e940dbb99..67cad40df5b3 100644 --- a/usr.sbin/user/user.c +++ b/usr.sbin/user/user.c @@ -1,4 +1,4 @@ -/* $NetBSD: user.c,v 1.5 1999/12/07 10:42:12 lukem Exp $ */ +/* $NetBSD: user.c,v 1.6 1999/12/08 18:12:16 hubertf Exp $ */ /* * Copyright (c) 1999 Alistair G. Crooks. All rights reserved. @@ -92,6 +92,23 @@ asystem(char *fmt, ...) return ret; } +#if (__NetBSD_Version__ < 104110000) +/* + * strlcpy() can only be used in 1.4K and later, use this for + * systems older than that. + */ +/* bounds checking strncpy */ +static char * +strnncpy(char *to, size_t tosize, char *from, size_t fromsize) +{ + size_t n = MIN(tosize - 1, fromsize); + + (void) memcpy(to, from, n); + to[n] = 0; + return to; +} +#endif /* __NetBSD_Version__ < 105000000 */ + /* copy any dot files into the user's home directory */ static int copydotfiles(char *skeldir, int uid, int gid, char *dir) @@ -224,7 +241,11 @@ modify_gid(char *group, char *newent) continue; } else { cc = strlen(newent); +#if (__NetBSD_Version__ < 104110000) + (void) strnncpy(buf, sizeof(buf), newent, (unsigned) cc); +#else (void) strlcpy(buf, newent, sizeof(buf)); +#endif /* __NetBSD_Version__ < 104110000 */ } } if (fwrite(buf, sizeof(char), (unsigned) cc, to) != cc) { @@ -936,7 +957,11 @@ usermod(int argc, char **argv) break; case 'l': have_new_user = 1; +#if (__NetBSD_Version__ < 104110000) + (void) strnncpy(newuser, sizeof(newuser), optarg, strlen(optarg)); +#else (void) strlcpy(newuser, optarg, sizeof(newuser)); +#endif /* __NetBSD_Version__ < 104110000 */ break; case 'm': u.u_mkdir = 1; @@ -1224,13 +1249,11 @@ main(int argc, char **argv) for (cmdp = cmds ; cmdp->c_progname ; cmdp++) { if (strcmp(__progname, cmdp->c_progname) == 0) { return (*cmdp->c_func)(argc, argv); - } else if (strcmp(__progname, cmdp->c_word1) == 0) { - if (argc > 1 && strcmp(argv[1], cmdp->c_word2) == 0) { - return (*cmdp->c_func)(argc - 1, argv + 1); - } else { - usage(__progname); - } - } + } + + if (strcmp(__progname, cmdp->c_word1) == 0 && + argc > 1 && strcmp(argv[1], cmdp->c_word2) == 0) + return (*cmdp->c_func)(argc - 1, argv + 1); } errx(EXIT_FAILURE, "Program `%s' not recognised", __progname); /* NOTREACHED */