getgr_test.c (315184) | getgr_test.c (319299) |
---|---|
1/*- 2 * Copyright (c) 2006 Michael Bushkov <bushman@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 12 unchanged lines hidden (view full) --- 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 */ 27 28#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2006 Michael Bushkov <bushman@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 12 unchanged lines hidden (view full) --- 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 */ 27 28#include <sys/cdefs.h> |
29__FBSDID("$FreeBSD: stable/11/lib/libc/tests/nss/getgr_test.c 315184 2017-03-13 01:34:40Z ngie $"); | 29__FBSDID("$FreeBSD: stable/11/lib/libc/tests/nss/getgr_test.c 319299 2017-05-31 08:32:05Z ngie $"); |
30 31#include <arpa/inet.h> 32#include <errno.h> 33#include <grp.h> 34#include <stdio.h> 35#include <stdlib.h> 36#include <string.h> 37#include <stringlist.h> --- 6 unchanged lines hidden (view full) --- 44enum test_methods { 45 TEST_GETGRENT = 1, 46 TEST_GETGRNAM = 2, 47 TEST_GETGRGID = 4, 48 TEST_GETGRENT_2PASS = 8, 49 TEST_BUILD_SNAPSHOT = 16, 50}; 51 | 30 31#include <arpa/inet.h> 32#include <errno.h> 33#include <grp.h> 34#include <stdio.h> 35#include <stdlib.h> 36#include <string.h> 37#include <stringlist.h> --- 6 unchanged lines hidden (view full) --- 44enum test_methods { 45 TEST_GETGRENT = 1, 46 TEST_GETGRNAM = 2, 47 TEST_GETGRGID = 4, 48 TEST_GETGRENT_2PASS = 8, 49 TEST_BUILD_SNAPSHOT = 16, 50}; 51 |
52static enum test_methods method = TEST_BUILD_SNAPSHOT; 53 | |
54DECLARE_TEST_DATA(group) 55DECLARE_TEST_FILE_SNAPSHOT(group) 56DECLARE_1PASS_TEST(group) 57DECLARE_2PASS_TEST(group) 58 59static void clone_group(struct group *, struct group const *); 60static int compare_group(struct group *, struct group *, void *); 61static void dump_group(struct group *); --- 37 unchanged lines hidden (view full) --- 99 } 100 dest->gr_gid = src->gr_gid; 101 102 if (src->gr_mem != NULL) { 103 members_num = 0; 104 for (cp = src->gr_mem; *cp; ++cp) 105 ++members_num; 106 | 52DECLARE_TEST_DATA(group) 53DECLARE_TEST_FILE_SNAPSHOT(group) 54DECLARE_1PASS_TEST(group) 55DECLARE_2PASS_TEST(group) 56 57static void clone_group(struct group *, struct group const *); 58static int compare_group(struct group *, struct group *, void *); 59static void dump_group(struct group *); --- 37 unchanged lines hidden (view full) --- 97 } 98 dest->gr_gid = src->gr_gid; 99 100 if (src->gr_mem != NULL) { 101 members_num = 0; 102 for (cp = src->gr_mem; *cp; ++cp) 103 ++members_num; 104 |
107 dest->gr_mem = calloc(1, (members_num + 1) * sizeof(char *)); | 105 dest->gr_mem = calloc(members_num + 1, sizeof(char *)); |
108 ATF_REQUIRE(dest->gr_mem != NULL); 109 110 for (cp = src->gr_mem; *cp; ++cp) { 111 dest->gr_mem[cp - src->gr_mem] = strdup(*cp); 112 ATF_REQUIRE(dest->gr_mem[cp - src->gr_mem] != NULL); 113 } 114 } 115} --- 58 unchanged lines hidden (view full) --- 174sdump_group(struct group *grp, char *buffer, size_t buflen) 175{ 176 char **cp; 177 int written; 178 179 written = snprintf(buffer, buflen, "%s:%s:%d:", 180 grp->gr_name, grp->gr_passwd, grp->gr_gid); 181 buffer += written; | 106 ATF_REQUIRE(dest->gr_mem != NULL); 107 108 for (cp = src->gr_mem; *cp; ++cp) { 109 dest->gr_mem[cp - src->gr_mem] = strdup(*cp); 110 ATF_REQUIRE(dest->gr_mem[cp - src->gr_mem] != NULL); 111 } 112 } 113} --- 58 unchanged lines hidden (view full) --- 172sdump_group(struct group *grp, char *buffer, size_t buflen) 173{ 174 char **cp; 175 int written; 176 177 written = snprintf(buffer, buflen, "%s:%s:%d:", 178 grp->gr_name, grp->gr_passwd, grp->gr_gid); 179 buffer += written; |
182 if (written > buflen) | 180 if (written > (int)buflen) |
183 return; 184 buflen -= written; 185 186 if (grp->gr_mem != NULL) { 187 if (*(grp->gr_mem) != '\0') { 188 for (cp = grp->gr_mem; *cp; ++cp) { 189 written = snprintf(buffer, buflen, "%s%s", 190 cp == grp->gr_mem ? "" : ",", *cp); 191 buffer += written; | 181 return; 182 buflen -= written; 183 184 if (grp->gr_mem != NULL) { 185 if (*(grp->gr_mem) != '\0') { 186 for (cp = grp->gr_mem; *cp; ++cp) { 187 written = snprintf(buffer, buflen, "%s%s", 188 cp == grp->gr_mem ? "" : ",", *cp); 189 buffer += written; |
192 if (written > buflen) | 190 if (written > (int)buflen) |
193 return; 194 buflen -= written; 195 196 if (buflen == 0) 197 return; 198 } 199 } else 200 snprintf(buffer, buflen, "nomem"); --- 103 unchanged lines hidden (view full) --- 304 return (-1); 305 } 306 endgrent(); 307 308 return (0); 309} 310 311static int | 191 return; 192 buflen -= written; 193 194 if (buflen == 0) 195 return; 196 } 197 } else 198 snprintf(buffer, buflen, "nomem"); --- 103 unchanged lines hidden (view full) --- 302 return (-1); 303 } 304 endgrent(); 305 306 return (0); 307} 308 309static int |
312group_test_correctness(struct group *grp, void *mdata) | 310group_test_correctness(struct group *grp, void *mdata __unused) |
313{ 314 printf("testing correctness with the following data:\n"); 315 dump_group(grp); 316 317 if (grp == NULL) 318 goto errfin; 319 320 if (grp->gr_name == NULL) --- 61 unchanged lines hidden (view full) --- 382 group_check_ambiguity((struct group_test_data *)mdata, grp) != 0)) { 383 return (-1); 384 } else { 385 return (0); 386 } 387} 388 389static int | 311{ 312 printf("testing correctness with the following data:\n"); 313 dump_group(grp); 314 315 if (grp == NULL) 316 goto errfin; 317 318 if (grp->gr_name == NULL) --- 61 unchanged lines hidden (view full) --- 380 group_check_ambiguity((struct group_test_data *)mdata, grp) != 0)) { 381 return (-1); 382 } else { 383 return (0); 384 } 385} 386 387static int |
390group_test_getgrent(struct group *grp, void *mdata) | 388group_test_getgrent(struct group *grp, void *mdata __unused) |
391{ 392 /* Only correctness can be checked when doing 1-pass test for 393 * getgrent(). */ 394 return (group_test_correctness(grp, NULL)); 395} 396 397static int 398run_tests(const char *snapshot_file, enum test_methods method) --- 148 unchanged lines hidden --- | 389{ 390 /* Only correctness can be checked when doing 1-pass test for 391 * getgrent(). */ 392 return (group_test_correctness(grp, NULL)); 393} 394 395static int 396run_tests(const char *snapshot_file, enum test_methods method) --- 148 unchanged lines hidden --- |