From 0d38bef9a784b61338e88b45facf502ffa6f4e9c Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 24 Aug 1999 17:37:38 +0000 Subject: [PATCH] include strcasecmp() for those without it --- CHANGES | 2 + LICENSE | 6 +-- Makefile.in | 7 +-- configure | 4 +- configure.in | 4 +- parse.yacc | 4 -- strcasecmp.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++ sudo.tab.c | 122 +++++++++++++++++++++++++-------------------------- 8 files changed, 187 insertions(+), 77 deletions(-) create mode 100644 strcasecmp.c diff --git a/CHANGES b/CHANGES index 1c5801fae..06150c227 100644 --- a/CHANGES +++ b/CHANGES @@ -1161,3 +1161,5 @@ Sudo 1.5.9 released. stored with the contents. This could lead to incorrect output if the sudoers file had different alias types with the same name. Normal parsing (ie: not in '-l' mode) is unaffected. + +365) Now include strcasecmp() for those without it. diff --git a/LICENSE b/LICENSE index 0269bd4a5..dbf17e67e 100644 --- a/LICENSE +++ b/LICENSE @@ -35,11 +35,11 @@ Sudo is distributed under the following BSD-style license: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -Additionally, lsearch.c, fnmatch.c, getcwd.c, snprintf.c and fnmatch.3 bear -the following UCB license: +Additionally, lsearch.c, fnmatch.c, getcwd.c, snprintf.c, strcasecmp.c +and fnmatch.3 bear the following UCB license: /* - * Copyright (c) 1989, 1990, 1991, 1993, 1994 + * Copyright (c) 1987, 1989, 1990, 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/Makefile.in b/Makefile.in index 18c40eff3..e8dcba150 100644 --- a/Makefile.in +++ b/Makefile.in @@ -111,9 +111,9 @@ PROGS = @PROGS@ SRCS = alloc.c alloca.c check.c fileops.c find_path.c fnmatch.c getcwd.c \ getspwuid.c goodpath.c interfaces.c lex.yy.c lsearch.c logging.c \ - parse.c parse.lex parse.yacc putenv.c snprintf.c strerror.c sudo.c \ - sudo.tab.c sudo_setenv.c testsudoers.c tgetpass.c utime.c version.c \ - visudo.c $(AUTH_SRCS) + parse.c parse.lex parse.yacc putenv.c snprintf.c strcasecmp.c \ + strerror.c sudo.c sudo.tab.c sudo_setenv.c testsudoers.c tgetpass.c \ + utime.c version.c visudo.c $(AUTH_SRCS) AUTH_SRCS = auth/afs.c auth/aix_auth.c auth/dce.c auth/fwtk.c auth/kerb4.c \ auth/kerb5.c auth/pam.c auth/passwd.c auth/rfc1938.c \ @@ -211,6 +211,7 @@ getcwd.o: getcwd.c config.h compat.h lsearch.o: lsearch.c config.h compat.h emul/search.h putenv.o: putenv.c config.h compat.h snprintf.o: snprintf.c config.h compat.h +strcasecmp.o: strcasecmp.c config.h strerror.o: strerror.c config.h utime.o: utime.c config.h pathnames.h compat.h emul/utime.h diff --git a/configure b/configure index 14ab183a0..4b59bd72f 100755 --- a/configure +++ b/configure @@ -5480,7 +5480,7 @@ EOF ;; esac -for ac_func in strchr strrchr memchr memcpy memset sysconf sigaction tzset strcasecmp seteuid ftruncate +for ac_func in strchr strrchr memchr memcpy memset sysconf sigaction tzset seteuid ftruncate do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 echo "configure:5487: checking for $ac_func" >&5 @@ -6444,7 +6444,7 @@ else LIBOBJS="$LIBOBJS fnmatch.o" fi -for ac_func in strerror +for ac_func in strerror strcasecmp do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 echo "configure:6451: checking for $ac_func" >&5 diff --git a/configure.in b/configure.in index 03c3e998e..0d3dfe2dc 100644 --- a/configure.in +++ b/configure.in @@ -1405,7 +1405,7 @@ esac dnl dnl Function checks dnl -AC_CHECK_FUNCS(strchr strrchr memchr memcpy memset sysconf sigaction tzset strcasecmp seteuid ftruncate) +AC_CHECK_FUNCS(strchr strrchr memchr memcpy memset sysconf sigaction tzset seteuid ftruncate) if test -n "$SECUREWARE"; then AC_CHECK_FUNCS(bigcrypt) AC_CHECK_FUNCS(set_auth_parameters) @@ -1422,7 +1422,7 @@ AC_CHECK_FUNC(setenv, AC_DEFINE(HAVE_SETENV), AC_FUNC_CHECK(putenv, AC_DEFINE(HA AC_CHECK_FUNC(utime, AC_DEFINE(HAVE_UTIME) SUDO_FUNC_UTIME_POSIX, LIBOBJS="$LIBOBJS utime.o") SUDO_FUNC_FNMATCH(AC_DEFINE(HAVE_FNMATCH), LIBOBJS="$LIBOBJS fnmatch.o") -AC_REPLACE_FUNCS(strerror) +AC_REPLACE_FUNCS(strerror strcasecmp) AC_CHECK_FUNC(snprintf, AC_DEFINE(HAVE_SNPRINTF), NEED_SNPRINTF=1) AC_CHECK_FUNC(vsnprintf, AC_DEFINE(HAVE_VSNPRINTF), NEED_SNPRINTF=1) AC_CHECK_FUNC(asprintf, AC_DEFINE(HAVE_ASPRINTF), NEED_SNPRINTF=1) diff --git a/parse.yacc b/parse.yacc index 729da6790..c324ece9a 100644 --- a/parse.yacc +++ b/parse.yacc @@ -75,10 +75,6 @@ #include "emul/search.h" #endif /* HAVE_LSEARCH */ -#ifndef HAVE_STRCASECMP -#define strcasecmp(a,b) strcmp(a,b) -#endif /* !HAVE_STRCASECMP */ - #ifndef lint static const char rcsid[] = "$Sudo$"; #endif /* lint */ diff --git a/strcasecmp.c b/strcasecmp.c new file mode 100644 index 000000000..ffc69178d --- /dev/null +++ b/strcasecmp.c @@ -0,0 +1,115 @@ +/* + * Copyright (c) 1987, 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + * + * @(#)strcasecmp.c 8.1 (Berkeley) 6/4/93 + */ + +#include "config.h" + +#ifndef lint +static const char rcsid[] = "$Sudo$"; +#endif /* lint */ + +/* + * This array is designed for mapping upper and lower case letter + * together for a case independent comparison. The mappings are + * based upon ascii character sequences. + */ +static const unsigned char charmap[] = { + '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', + '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', + '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', + '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', + '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047', + '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057', + '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067', + '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077', + '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147', + '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', + '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', + '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137', + '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147', + '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', + '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', + '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177', + '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207', + '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217', + '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227', + '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237', + '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247', + '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257', + '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267', + '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277', + '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307', + '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317', + '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327', + '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337', + '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347', + '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', + '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', + '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377', +}; + +int +strcasecmp(s1, s2) + const char *s1, *s2; +{ + const unsigned char *cm = charmap, + *us1 = (const unsigned char *)s1, + *us2 = (const unsigned char *)s2; + + while (cm[*us1] == cm[*us2++]) + if (*us1++ == '\0') + return (0); + return (cm[*us1] - cm[*--us2]); +} + +int +strncasecmp(s1, s2, n) + const char *s1, *s2; + size_t n; +{ + + if (n != 0) { + const unsigned char *cm = charmap, + *us1 = (const unsigned char *)s1, + *us2 = (const unsigned char *)s2; + + do { + if (cm[*us1] != cm[*us2++]) + return (cm[*us1] - cm[*--us2]); + if (*us1++ == '\0') + break; + } while (--n != 0); + } + return (0); +} diff --git a/sudo.tab.c b/sudo.tab.c index e047634ec..24b511a52 100644 --- a/sudo.tab.c +++ b/sudo.tab.c @@ -93,10 +93,6 @@ static char yyrcsid[] #include "emul/search.h" #endif /* HAVE_LSEARCH */ -#ifndef HAVE_STRCASECMP -#define strcasecmp(a,b) strcmp(a,b) -#endif /* !HAVE_STRCASECMP */ - #ifndef lint static const char rcsid[] = "$Sudo$"; #endif /* lint */ @@ -224,14 +220,14 @@ yyerror(s) } parse_error = TRUE; } -#line 211 "./parse.yacc" +#line 207 "./parse.yacc" typedef union { char *string; int BOOLEAN; struct sudo_command command; int tok; } YYSTYPE; -#line 235 "sudo.tab.c" +#line 231 "sudo.tab.c" #define COMMAND 257 #define ALIAS 258 #define NTWKADDR 259 @@ -536,7 +532,7 @@ short *yyss; short *yysslim; YYSTYPE *yyvs; int yystacksize; -#line 769 "./parse.yacc" +#line 765 "./parse.yacc" #define MOREALIASES (32) aliasinfo *aliases = NULL; @@ -886,7 +882,7 @@ init_parser() if (printmatches == TRUE) expand_match_list(); } -#line 890 "sudo.tab.c" +#line 886 "sudo.tab.c" /* allocate initial stack or double stack size, up to YYMAXDEPTH */ #if defined(__cplusplus) || __STDC__ static int yygrowstack(void) @@ -1067,42 +1063,42 @@ yyreduce: switch (yyn) { case 3: -#line 256 "./parse.yacc" +#line 252 "./parse.yacc" { ; } break; case 4: -#line 258 "./parse.yacc" +#line 254 "./parse.yacc" { yyerrok; } break; case 5: -#line 259 "./parse.yacc" +#line 255 "./parse.yacc" { push; } break; case 6: -#line 259 "./parse.yacc" +#line 255 "./parse.yacc" { while (top && user_matches != TRUE) pop; } break; case 7: -#line 264 "./parse.yacc" +#line 260 "./parse.yacc" { ; } break; case 8: -#line 266 "./parse.yacc" +#line 262 "./parse.yacc" { ; } break; case 9: -#line 268 "./parse.yacc" +#line 264 "./parse.yacc" { ; } break; case 10: -#line 270 "./parse.yacc" +#line 266 "./parse.yacc" { ; } break; case 13: -#line 278 "./parse.yacc" +#line 274 "./parse.yacc" { /* * We already did a push if necessary in @@ -1115,27 +1111,27 @@ case 13: } break; case 14: -#line 290 "./parse.yacc" +#line 286 "./parse.yacc" { if (yyvsp[0].BOOLEAN != -1) host_matches = yyvsp[0].BOOLEAN; } break; case 15: -#line 294 "./parse.yacc" +#line 290 "./parse.yacc" { if (yyvsp[0].BOOLEAN != -1) host_matches = ! yyvsp[0].BOOLEAN; } break; case 16: -#line 299 "./parse.yacc" +#line 295 "./parse.yacc" { yyval.BOOLEAN = TRUE; } break; case 17: -#line 302 "./parse.yacc" +#line 298 "./parse.yacc" { if (addr_matches(yyvsp[0].string)) yyval.BOOLEAN = TRUE; @@ -1145,7 +1141,7 @@ case 17: } break; case 18: -#line 309 "./parse.yacc" +#line 305 "./parse.yacc" { if (netgr_matches(yyvsp[0].string, user_host, NULL)) yyval.BOOLEAN = TRUE; @@ -1155,7 +1151,7 @@ case 18: } break; case 19: -#line 316 "./parse.yacc" +#line 312 "./parse.yacc" { if (strcasecmp(user_shost, yyvsp[0].string) == 0) yyval.BOOLEAN = TRUE; @@ -1165,7 +1161,7 @@ case 19: } break; case 20: -#line 323 "./parse.yacc" +#line 319 "./parse.yacc" { if (strcasecmp(user_host, yyvsp[0].string) == 0) yyval.BOOLEAN = TRUE; @@ -1175,7 +1171,7 @@ case 20: } break; case 21: -#line 330 "./parse.yacc" +#line 326 "./parse.yacc" { aliasinfo *aip = find_alias(yyvsp[0].string, HOST_ALIAS); @@ -1200,7 +1196,7 @@ case 21: } break; case 24: -#line 358 "./parse.yacc" +#line 354 "./parse.yacc" { /* * Push the entry onto the stack if it is worth @@ -1223,14 +1219,14 @@ case 24: } break; case 25: -#line 380 "./parse.yacc" +#line 376 "./parse.yacc" { if (yyvsp[0].BOOLEAN != -1) cmnd_matches = yyvsp[0].BOOLEAN; } break; case 26: -#line 384 "./parse.yacc" +#line 380 "./parse.yacc" { if (printmatches == TRUE) { if (in_alias == TRUE) @@ -1242,14 +1238,14 @@ case 26: } break; case 27: -#line 392 "./parse.yacc" +#line 388 "./parse.yacc" { if (yyvsp[0].BOOLEAN != -1) cmnd_matches = ! yyvsp[0].BOOLEAN; } break; case 28: -#line 398 "./parse.yacc" +#line 394 "./parse.yacc" { if (printmatches == TRUE && host_matches == TRUE && user_matches == TRUE) { @@ -1275,18 +1271,18 @@ case 28: } break; case 29: -#line 421 "./parse.yacc" +#line 417 "./parse.yacc" { ; } break; case 32: -#line 428 "./parse.yacc" +#line 424 "./parse.yacc" { if (yyvsp[0].BOOLEAN != -1) runas_matches = yyvsp[0].BOOLEAN; } break; case 33: -#line 432 "./parse.yacc" +#line 428 "./parse.yacc" { if (printmatches == TRUE) { if (in_alias == TRUE) @@ -1298,14 +1294,14 @@ case 33: } break; case 34: -#line 440 "./parse.yacc" +#line 436 "./parse.yacc" { if (yyvsp[0].BOOLEAN != -1) runas_matches = ! yyvsp[0].BOOLEAN; } break; case 35: -#line 445 "./parse.yacc" +#line 441 "./parse.yacc" { if (printmatches == TRUE) { if (in_alias == TRUE) @@ -1322,7 +1318,7 @@ case 35: } break; case 36: -#line 459 "./parse.yacc" +#line 455 "./parse.yacc" { if (printmatches == TRUE) { if (in_alias == TRUE) @@ -1339,7 +1335,7 @@ case 36: } break; case 37: -#line 473 "./parse.yacc" +#line 469 "./parse.yacc" { if (printmatches == TRUE) { if (in_alias == TRUE) @@ -1356,7 +1352,7 @@ case 37: } break; case 38: -#line 487 "./parse.yacc" +#line 483 "./parse.yacc" { aliasinfo *aip = find_alias(yyvsp[0].string, RUNAS_ALIAS); @@ -1388,7 +1384,7 @@ case 38: } break; case 39: -#line 516 "./parse.yacc" +#line 512 "./parse.yacc" { if (printmatches == TRUE) { if (in_alias == TRUE) @@ -1401,7 +1397,7 @@ case 39: } break; case 40: -#line 528 "./parse.yacc" +#line 524 "./parse.yacc" { /* Inherit NOPASSWD/PASSWD status. */ if (printmatches == TRUE && host_matches == TRUE && @@ -1414,7 +1410,7 @@ case 40: } break; case 41: -#line 538 "./parse.yacc" +#line 534 "./parse.yacc" { no_passwd = TRUE; if (printmatches == TRUE && host_matches == TRUE && @@ -1423,7 +1419,7 @@ case 41: } break; case 42: -#line 544 "./parse.yacc" +#line 540 "./parse.yacc" { no_passwd = FALSE; if (printmatches == TRUE && host_matches == TRUE && @@ -1432,7 +1428,7 @@ case 42: } break; case 43: -#line 552 "./parse.yacc" +#line 548 "./parse.yacc" { if (printmatches == TRUE) { if (in_alias == TRUE) @@ -1452,7 +1448,7 @@ case 43: } break; case 44: -#line 569 "./parse.yacc" +#line 565 "./parse.yacc" { aliasinfo *aip; @@ -1484,7 +1480,7 @@ case 44: } break; case 45: -#line 598 "./parse.yacc" +#line 594 "./parse.yacc" { if (printmatches == TRUE) { if (in_alias == TRUE) { @@ -1513,11 +1509,11 @@ case 45: } break; case 48: -#line 630 "./parse.yacc" +#line 626 "./parse.yacc" { push; } break; case 49: -#line 630 "./parse.yacc" +#line 626 "./parse.yacc" { if ((host_matches != -1 || pedantic) && !add_alias(yyvsp[-3].string, HOST_ALIAS, host_matches)) @@ -1526,7 +1522,7 @@ case 49: } break; case 54: -#line 646 "./parse.yacc" +#line 642 "./parse.yacc" { push; if (printmatches == TRUE) { @@ -1539,7 +1535,7 @@ case 54: } break; case 55: -#line 655 "./parse.yacc" +#line 651 "./parse.yacc" { if ((cmnd_matches != -1 || pedantic) && !add_alias(yyvsp[-3].string, CMND_ALIAS, cmnd_matches)) @@ -1552,11 +1548,11 @@ case 55: } break; case 56: -#line 667 "./parse.yacc" +#line 663 "./parse.yacc" { ; } break; case 60: -#line 675 "./parse.yacc" +#line 671 "./parse.yacc" { push; if (printmatches == TRUE) { @@ -1569,7 +1565,7 @@ case 60: } break; case 61: -#line 684 "./parse.yacc" +#line 680 "./parse.yacc" { if ((runas_matches != -1 || pedantic) && !add_alias(yyvsp[-3].string, RUNAS_ALIAS, runas_matches)) @@ -1582,11 +1578,11 @@ case 61: } break; case 64: -#line 700 "./parse.yacc" +#line 696 "./parse.yacc" { push; } break; case 65: -#line 700 "./parse.yacc" +#line 696 "./parse.yacc" { if ((user_matches != -1 || pedantic) && !add_alias(yyvsp[-3].string, USER_ALIAS, user_matches)) @@ -1596,25 +1592,25 @@ case 65: } break; case 66: -#line 709 "./parse.yacc" +#line 705 "./parse.yacc" { ; } break; case 68: -#line 713 "./parse.yacc" +#line 709 "./parse.yacc" { if (yyvsp[0].BOOLEAN != -1) user_matches = yyvsp[0].BOOLEAN; } break; case 69: -#line 717 "./parse.yacc" +#line 713 "./parse.yacc" { if (yyvsp[0].BOOLEAN != -1) user_matches = ! yyvsp[0].BOOLEAN; } break; case 70: -#line 722 "./parse.yacc" +#line 718 "./parse.yacc" { if (strcmp(yyvsp[0].string, user_name) == 0) yyval.BOOLEAN = TRUE; @@ -1624,7 +1620,7 @@ case 70: } break; case 71: -#line 729 "./parse.yacc" +#line 725 "./parse.yacc" { if (usergr_matches(yyvsp[0].string, user_name)) yyval.BOOLEAN = TRUE; @@ -1634,7 +1630,7 @@ case 71: } break; case 72: -#line 736 "./parse.yacc" +#line 732 "./parse.yacc" { if (netgr_matches(yyvsp[0].string, NULL, user_name)) yyval.BOOLEAN = TRUE; @@ -1644,7 +1640,7 @@ case 72: } break; case 73: -#line 743 "./parse.yacc" +#line 739 "./parse.yacc" { aliasinfo *aip = find_alias(yyvsp[0].string, USER_ALIAS); @@ -1667,12 +1663,12 @@ case 73: } break; case 74: -#line 763 "./parse.yacc" +#line 759 "./parse.yacc" { yyval.BOOLEAN = TRUE; } break; -#line 1676 "sudo.tab.c" +#line 1672 "sudo.tab.c" } yyssp -= yym; yystate = *yyssp; -- 2.40.0