diff options
Diffstat (limited to 'misc.c')
-rw-r--r-- | misc.c | 31 |
1 files changed, 27 insertions, 4 deletions
@@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.131 2018/07/27 05:13:02 dtucker Exp $ */ +/* $OpenBSD: misc.c,v 1.133 2018/10/05 14:26:09 naddy Exp $ */ /* * Copyright (c) 2000 Markus Friedl. All rights reserved. * Copyright (c) 2005,2006 Damien Miller. All rights reserved. @@ -50,6 +50,7 @@ #include <netinet/in_systm.h> #include <netinet/ip.h> #include <netinet/tcp.h> +#include <arpa/inet.h> #include <ctype.h> #include <errno.h> @@ -332,13 +333,16 @@ pwcopy(struct passwd *pw) int a2port(const char *s) { + struct servent *se; long long port; const char *errstr; port = strtonum(s, 0, 65535, &errstr); - if (errstr != NULL) - return -1; - return (int)port; + if (errstr == NULL) + return (int)port; + if ((se = getservbyname(s, "tcp")) != NULL) + return ntohs(se->s_port); + return -1; } int @@ -1948,6 +1952,25 @@ bad: return 0; } +/* + * Verify that a environment variable name (not including initial '$') is + * valid; consisting of one or more alphanumeric or underscore characters only. + * Returns 1 on valid, 0 otherwise. + */ +int +valid_env_name(const char *name) +{ + const char *cp; + + if (name[0] == '\0') + return 0; + for (cp = name; *cp != '\0'; cp++) { + if (!isalnum((u_char)*cp) && *cp != '_') + return 0; + } + return 1; +} + const char * atoi_err(const char *nptr, int *val) { |