diff options
Diffstat (limited to 'misc.c')
-rw-r--r-- | misc.c | 31 |
1 files changed, 27 insertions, 4 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: misc.c,v 1.131 2018/07/27 05:13:02 dtucker Exp $ */ | 1 | /* $OpenBSD: misc.c,v 1.133 2018/10/05 14:26:09 naddy Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. | 4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. |
@@ -50,6 +50,7 @@ | |||
50 | #include <netinet/in_systm.h> | 50 | #include <netinet/in_systm.h> |
51 | #include <netinet/ip.h> | 51 | #include <netinet/ip.h> |
52 | #include <netinet/tcp.h> | 52 | #include <netinet/tcp.h> |
53 | #include <arpa/inet.h> | ||
53 | 54 | ||
54 | #include <ctype.h> | 55 | #include <ctype.h> |
55 | #include <errno.h> | 56 | #include <errno.h> |
@@ -333,13 +334,16 @@ pwcopy(struct passwd *pw) | |||
333 | int | 334 | int |
334 | a2port(const char *s) | 335 | a2port(const char *s) |
335 | { | 336 | { |
337 | struct servent *se; | ||
336 | long long port; | 338 | long long port; |
337 | const char *errstr; | 339 | const char *errstr; |
338 | 340 | ||
339 | port = strtonum(s, 0, 65535, &errstr); | 341 | port = strtonum(s, 0, 65535, &errstr); |
340 | if (errstr != NULL) | 342 | if (errstr == NULL) |
341 | return -1; | 343 | return (int)port; |
342 | return (int)port; | 344 | if ((se = getservbyname(s, "tcp")) != NULL) |
345 | return ntohs(se->s_port); | ||
346 | return -1; | ||
343 | } | 347 | } |
344 | 348 | ||
345 | int | 349 | int |
@@ -1996,6 +2000,25 @@ bad: | |||
1996 | return 0; | 2000 | return 0; |
1997 | } | 2001 | } |
1998 | 2002 | ||
2003 | /* | ||
2004 | * Verify that a environment variable name (not including initial '$') is | ||
2005 | * valid; consisting of one or more alphanumeric or underscore characters only. | ||
2006 | * Returns 1 on valid, 0 otherwise. | ||
2007 | */ | ||
2008 | int | ||
2009 | valid_env_name(const char *name) | ||
2010 | { | ||
2011 | const char *cp; | ||
2012 | |||
2013 | if (name[0] == '\0') | ||
2014 | return 0; | ||
2015 | for (cp = name; *cp != '\0'; cp++) { | ||
2016 | if (!isalnum((u_char)*cp) && *cp != '_') | ||
2017 | return 0; | ||
2018 | } | ||
2019 | return 1; | ||
2020 | } | ||
2021 | |||
1999 | const char * | 2022 | const char * |
2000 | atoi_err(const char *nptr, int *val) | 2023 | atoi_err(const char *nptr, int *val) |
2001 | { | 2024 | { |