diff --git a/MANIFEST b/MANIFEST index 12d4c7d36..5e453cca0 100644 --- a/MANIFEST +++ b/MANIFEST @@ -271,6 +271,7 @@ plugins/sudoers/regress/logging/check_wrap.in plugins/sudoers/regress/logging/check_wrap.out.ok plugins/sudoers/regress/parser/check_addr.c plugins/sudoers/regress/parser/check_addr.in +plugins/sudoers/regress/parser/check_base64.c plugins/sudoers/regress/parser/check_digest.c plugins/sudoers/regress/parser/check_digest.out.ok plugins/sudoers/regress/parser/check_fill.c diff --git a/plugins/sudoers/Makefile.in b/plugins/sudoers/Makefile.in index eb363eb6a..8c0a8c342 100644 --- a/plugins/sudoers/Makefile.in +++ b/plugins/sudoers/Makefile.in @@ -124,7 +124,7 @@ SHELL = @SHELL@ PROGS = sudoers.la visudo sudoreplay testsudoers TEST_PROGS = check_iolog_path check_fill check_wrap check_addr check_symbols \ - check_digest + check_digest check_base64 AUTH_OBJS = sudo_auth.lo @AUTH_OBJS@ @@ -147,6 +147,8 @@ TEST_OBJS = group_plugin.o interfaces.o locale.o net_ifs.o \ CHECK_ADDR_OBJS = check_addr.o interfaces.o locale.o match_addr.o +CHECK_BASE64_OBJS = check_base64.o base64.o locale.o + CHECK_DIGEST_OBJS = check_digest.o sha2.o CHECK_FILL_OBJS = check_fill.o hexchar.o locale.o toke_util.o @@ -205,6 +207,9 @@ testsudoers: libparsesudoers.la $(TEST_OBJS) $(LT_LIBS) check_addr: $(CHECK_ADDR_OBJS) $(LT_LIBS) $(LIBTOOL) --mode=link $(CC) -o $@ $(CHECK_ADDR_OBJS) $(LDFLAGS) $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(LIBS) $(NET_LIBS) +check_base64: $(CHECK_BASE64_OBJS) $(LT_LIBS) + $(LIBTOOL) --mode=link $(CC) -o $@ $(CHECK_BASE64_OBJS) $(LDFLAGS) $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(LIBS) + check_digest: $(CHECK_DIGEST_OBJS) $(LT_LIBS) $(LIBTOOL) --mode=link $(CC) -o $@ $(CHECK_DIGEST_OBJS) $(LDFLAGS) $(PIE_LDFLAGS) $(SSP_LDFLAGS) $(LIBS) @@ -318,6 +323,7 @@ check: $(TEST_PROGS) visudo testsudoers CWD=`pwd`; \ mkdir -p regress/parser; \ ./check_addr $(srcdir)/regress/parser/check_addr.in || rval=`expr $$rval + $$?`; \ + ./check_base64 || rval=`expr $$rval + $$?`; \ ./check_digest > regress/parser/check_digest.out; \ diff regress/parser/check_digest.out $(srcdir)/regress/parser/check_digest.out.ok || rval=`expr $$rval + $$?`; \ ./check_fill || rval=`expr $$rval + $$?`; \ @@ -454,6 +460,7 @@ audit.lo: $(srcdir)/audit.c $(top_builddir)/config.h \ base64.lo: $(srcdir)/base64.c $(top_builddir)/config.h $(incdir)/missing.h \ $(incdir)/sudo_debug.h $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/base64.c +base64.o: base64.lo boottime.lo: $(srcdir)/boottime.c $(top_builddir)/config.h $(incdir)/missing.h \ $(incdir)/sudo_debug.h $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/boottime.c @@ -485,6 +492,9 @@ check_addr.o: $(srcdir)/regress/parser/check_addr.c $(top_builddir)/config.h \ $(incdir)/sudo_debug.h $(incdir)/gettext.h $(srcdir)/parse.h \ $(srcdir)/interfaces.h $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/regress/parser/check_addr.c +check_base64.o: $(srcdir)/regress/parser/check_base64.c \ + $(top_builddir)/config.h $(incdir)/missing.h $(srcdir)/sha2.h + $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/regress/parser/check_base64.c check_digest.o: $(srcdir)/regress/parser/check_digest.c \ $(top_builddir)/config.h $(incdir)/missing.h $(srcdir)/sha2.h $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $(srcdir)/regress/parser/check_digest.c diff --git a/plugins/sudoers/regress/parser/check_base64.c b/plugins/sudoers/regress/parser/check_base64.c new file mode 100644 index 000000000..ccbfd0c79 --- /dev/null +++ b/plugins/sudoers/regress/parser/check_base64.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2013 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +#include +#ifdef STDC_HEADERS +# include +# include +#else +# ifdef HAVE_STDLIB_H +# include +# endif +#endif /* STDC_HEADERS */ +#ifdef HAVE_STRING_H +# if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS) +# include +# endif +# include +#endif /* HAVE_STRING_H */ +#ifdef HAVE_STRINGS_H +# include +#endif /* HAVE_STRINGS_H */ +#if defined(HAVE_STDINT_H) +# include +#elif defined(HAVE_INTTYPES_H) +# include +#endif + +#define SUDO_ERROR_WRAP 0 + +#include "missing.h" + +extern size_t base64_decode(const char *str, unsigned char *dst, size_t dsize); + +__dso_public int main(int argc, char *argv[]); + +struct base64_test { + const char *ascii; + const char *encoded; +} test_strings[] = { + { + "any carnal pleasure.", + "YW55IGNhcm5hbCBwbGVhc3VyZS4=" + }, + { + "any carnal pleasure", + "YW55IGNhcm5hbCBwbGVhc3VyZQ==" + }, + { + "any carnal pleasur", + "YW55IGNhcm5hbCBwbGVhc3Vy" + }, + { + "any carnal pleasu", + "YW55IGNhcm5hbCBwbGVhc3U=" + }, + { + "any carnal pleas", + "YW55IGNhcm5hbCBwbGVhcw==" + } +}; + +int +main(int argc, char *argv[]) +{ + const int ntests = (sizeof(test_strings) / sizeof(test_strings[0])); + int i, errors = 0; + char buf[32]; + size_t len; + + for (i = 0; i < ntests; i++) { + len = base64_decode(test_strings[i].encoded, buf, sizeof(buf)); + buf[len] = '\0'; + if (strcmp(test_strings[i].ascii, buf) != 0) { + fprintf(stderr, "check_base64: expected %s, got %s", + test_strings[i].ascii, buf); + errors++; + } + } + printf("check_base64: %d tests run, %d errors, %d%% success rate\n", + ntests, errors, (ntests - errors) * 100 / ntests); + exit(errors); +}