generate.c (168778) | generate.c (186647) |
---|---|
1/*- 2 * Copyright (c) 2006-2007 Robert N. M. Watson | 1/*- 2 * Copyright (c) 2006-2007 Robert N. M. Watson |
3 * Copyright (c) 2008 Apple Inc. |
|
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 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright --- 7 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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 * | 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright --- 7 unchanged lines hidden (view full) --- 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * |
26 * $P4: //depot/projects/trustedbsd/openbsm/test/bsm/generate.c#9 $ | 27 * $P4: //depot/projects/trustedbsd/openbsm/test/bsm/generate.c#12 $ |
27 */ 28 29/* 30 * Generate a series of BSM token samples in the requested directory. 31 */ 32 33#include <sys/types.h> 34#include <sys/socket.h> --- 513 unchanged lines hidden (view full) --- 548 process64_egid, process64_ruid, process64_rgid, process64_pid, 549 process64_sid, &process64_tid_addr); 550 if (process64ex_token == NULL) 551 err(EX_UNAVAILABLE, "au_to_process64_ex"); 552 write_record(directory, buf, process64ex_token, AUE_NULL); 553 free(buf); 554} 555 | 28 */ 29 30/* 31 * Generate a series of BSM token samples in the requested directory. 32 */ 33 34#include <sys/types.h> 35#include <sys/socket.h> --- 513 unchanged lines hidden (view full) --- 549 process64_egid, process64_ruid, process64_rgid, process64_pid, 550 process64_sid, &process64_tid_addr); 551 if (process64ex_token == NULL) 552 err(EX_UNAVAILABLE, "au_to_process64_ex"); 553 write_record(directory, buf, process64ex_token, AUE_NULL); 554 free(buf); 555} 556 |
556static char return32_status = 0xd7; | 557static char return32_status = EINVAL; |
557static uint32_t return32_ret = 0x12345678; 558 559static void 560generate_return32_token(const char *directory, const char *token_filename) 561{ 562 token_t *return32_token; 563 | 558static uint32_t return32_ret = 0x12345678; 559 560static void 561generate_return32_token(const char *directory, const char *token_filename) 562{ 563 token_t *return32_token; 564 |
564 return32_token = au_to_return32(return32_status, return32_ret); | 565 return32_token = au_to_return32(au_errno_to_bsm(return32_status), 566 return32_ret); |
565 if (return32_token == NULL) 566 err(EX_UNAVAILABLE, "au_to_return32"); 567 write_token(directory, token_filename, return32_token); 568} 569 570static void 571generate_return32_record(const char *directory, const char *record_filename) 572{ 573 token_t *return32_token; 574 | 567 if (return32_token == NULL) 568 err(EX_UNAVAILABLE, "au_to_return32"); 569 write_token(directory, token_filename, return32_token); 570} 571 572static void 573generate_return32_record(const char *directory, const char *record_filename) 574{ 575 token_t *return32_token; 576 |
575 return32_token = au_to_return32(return32_status, return32_ret); | 577 return32_token = au_to_return32(au_errno_to_bsm(return32_status), 578 return32_ret); |
576 if (return32_token == NULL) 577 err(EX_UNAVAILABLE, "au_to_return32"); 578 write_record(directory, record_filename, return32_token, AUE_NULL); 579} 580 581static char *text_token_text = "This is a test."; 582 583static void --- 324 unchanged lines hidden (view full) --- 908 token_t *zonename_token; 909 910 zonename_token = au_to_zonename(zonename_sample); 911 if (zonename_token == NULL) 912 err(EX_UNAVAILABLE, "au_to_zonename"); 913 write_record(directory, record_filename, zonename_token, AUE_NULL); 914} 915 | 579 if (return32_token == NULL) 580 err(EX_UNAVAILABLE, "au_to_return32"); 581 write_record(directory, record_filename, return32_token, AUE_NULL); 582} 583 584static char *text_token_text = "This is a test."; 585 586static void --- 324 unchanged lines hidden (view full) --- 911 token_t *zonename_token; 912 913 zonename_token = au_to_zonename(zonename_sample); 914 if (zonename_token == NULL) 915 err(EX_UNAVAILABLE, "au_to_zonename"); 916 write_record(directory, record_filename, zonename_token, AUE_NULL); 917} 918 |
919static u_short socketex_domain = AF_INET; 920static u_short socketex_type = SOCK_STREAM; 921static struct sockaddr_in socketex_laddr, socketex_raddr; 922 923static void 924generate_socketex_token(const char *directory, const char *token_filename) 925{ 926 token_t *socketex_token; 927 928 bzero(&socketex_laddr, sizeof(socketex_laddr)); 929 socketex_laddr.sin_family = AF_INET; 930 socketex_laddr.sin_len = sizeof(socketex_laddr); 931 socketex_laddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); 932 933 bzero(&socketex_raddr, sizeof(socketex_raddr)); 934 socketex_raddr.sin_family = AF_INET; 935 socketex_raddr.sin_len = sizeof(socketex_raddr); 936 socketex_raddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); 937 938 socketex_token = au_to_socket_ex(socketex_domain, socketex_type, 939 (struct sockaddr *)&socketex_laddr, 940 (struct sockaddr *)&socketex_raddr); 941 if (socketex_token == NULL) 942 err(EX_UNAVAILABLE, "au_to_socket_ex"); 943 write_token(directory, token_filename, socketex_token); 944} 945 946static void 947generate_socketex_record(const char *directory, const char *record_filename) 948{ 949 token_t *socketex_token; 950 951 bzero(&socketex_laddr, sizeof(socketex_laddr)); 952 socketex_laddr.sin_family = AF_INET; 953 socketex_laddr.sin_len = sizeof(socketex_laddr); 954 socketex_laddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); 955 956 bzero(&socketex_raddr, sizeof(socketex_raddr)); 957 socketex_raddr.sin_family = AF_INET; 958 socketex_raddr.sin_len = sizeof(socketex_raddr); 959 socketex_raddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); 960 961 socketex_token = au_to_socket_ex(socketex_domain, socketex_type, 962 (struct sockaddr *)&socketex_laddr, 963 (struct sockaddr *)&socketex_raddr); 964 if (socketex_token == NULL) 965 err(EX_UNAVAILABLE, "au_to_socket_ex"); 966 write_record(directory, record_filename, socketex_token, AUE_NULL); 967} 968 969/* 970 * Generate a series of error-number specific return tokens in records. 971 */ 972static void 973generate_error_record(const char *directory, const char *filename, int error) 974{ 975 char pathname[PATH_MAX]; 976 token_t *return32_token; 977 978 return32_token = au_to_return32(au_errno_to_bsm(error), -1); 979 if (return32_token == NULL) 980 err(EX_UNAVAILABLE, "au_to_return32"); 981 (void)snprintf(pathname, PATH_MAX, "%s_record", filename); 982 write_record(directory, pathname, return32_token, AUE_NULL); 983} 984 985/* 986 * Not all the error numbers, just a few present on all platforms for now. 987 */ 988const struct { 989 int error_number; 990 const char *error_name; 991} error_list[] = { 992 { EPERM, "EPERM" }, 993 { ENOENT, "ENOENT" }, 994 { ESRCH, "ESRCH" }, 995 { EINTR, "EINTR" }, 996 { EIO, "EIO" }, 997 { ENXIO, "ENXIO" }, 998 { E2BIG, "E2BIG" }, 999 { ENOEXEC, "ENOEXEC" }, 1000 { EBADF, "EBADF" }, 1001 { ECHILD, "ECHILD" }, 1002 { EDEADLK, "EDEADLK" }, 1003 { ENOMEM, "ENOMEM" }, 1004 { EACCES, "EACCES" }, 1005 { EFAULT, "EFAULT" }, 1006 { ENOTBLK, "ENOTBLK" }, 1007 { EBUSY, "EBUSY" }, 1008 { EEXIST, "EEXIST" }, 1009 { EXDEV, "EXDEV" }, 1010 { ENODEV, "ENODEV" }, 1011 { ENOTDIR, "ENOTDIR" }, 1012 { EISDIR, "EISDIR" }, 1013 { EINVAL, "EINVAL" }, 1014 { ENFILE, "ENFILE" }, 1015 { EMFILE, "EMFILE" }, 1016 { ENOTTY, "ENOTTY" }, 1017 { ETXTBSY, "ETXTBSY" }, 1018 { EFBIG, "EFBIG" }, 1019 { ENOSPC, "ENOSPC" }, 1020 { ESPIPE, "ESPIPE" }, 1021 { EROFS, "EROFS" }, 1022 { EMLINK, "EMLINK" }, 1023 { EPIPE, "EPIPE" } 1024}; 1025const int error_list_count = sizeof(error_list)/sizeof(error_list[0]); 1026 1027static void 1028do_error_records(const char *directory) 1029{ 1030 int i; 1031 1032 for (i = 0; i < error_list_count; i++) 1033 generate_error_record(directory, error_list[i].error_name, 1034 error_list[i].error_number); 1035} 1036 |
|
916int 917main(int argc, char *argv[]) 918{ 919 const char *directory; 920 int ch; 921 922 while ((ch = getopt(argc, argv, "rt")) != -1) { 923 switch (ch) { --- 51 unchanged lines hidden (view full) --- 975 generate_iport_token(directory, "iport_token"); 976 generate_arg32_token(directory, "arg32_token"); 977 generate_seq_token(directory, "seq_token"); 978 generate_attr_token(directory, "attr_token"); 979 generate_ipc_perm_token(directory, "ipc_perm_token"); 980 generate_groups_token(directory, "groups_token"); 981 generate_attr32_token(directory, "attr32_token"); 982 generate_zonename_token(directory, "zonename_token"); | 1037int 1038main(int argc, char *argv[]) 1039{ 1040 const char *directory; 1041 int ch; 1042 1043 while ((ch = getopt(argc, argv, "rt")) != -1) { 1044 switch (ch) { --- 51 unchanged lines hidden (view full) --- 1096 generate_iport_token(directory, "iport_token"); 1097 generate_arg32_token(directory, "arg32_token"); 1098 generate_seq_token(directory, "seq_token"); 1099 generate_attr_token(directory, "attr_token"); 1100 generate_ipc_perm_token(directory, "ipc_perm_token"); 1101 generate_groups_token(directory, "groups_token"); 1102 generate_attr32_token(directory, "attr32_token"); 1103 generate_zonename_token(directory, "zonename_token"); |
1104 generate_socketex_token(directory, "socketex_token"); |
|
983 } 984 985 if (do_records) { 986 generate_file_record(directory, "file_record"); 987 generate_data_record(directory, "data_record"); 988 generate_ipc_record(directory, "ipc_record"); 989 generate_path_record(directory, "path_record"); 990 generate_subject32_record(directory, "subject32_record"); --- 19 unchanged lines hidden (view full) --- 1010 generate_iport_record(directory, "iport_record"); 1011 generate_arg32_record(directory, "arg32_record"); 1012 generate_seq_record(directory, "seq_record"); 1013 generate_attr_record(directory, "attr_record"); 1014 generate_ipc_perm_record(directory, "ipc_perm_record"); 1015 generate_groups_record(directory, "groups_record"); 1016 generate_attr32_record(directory, "attr32_record"); 1017 generate_zonename_record(directory, "zonename_record"); | 1105 } 1106 1107 if (do_records) { 1108 generate_file_record(directory, "file_record"); 1109 generate_data_record(directory, "data_record"); 1110 generate_ipc_record(directory, "ipc_record"); 1111 generate_path_record(directory, "path_record"); 1112 generate_subject32_record(directory, "subject32_record"); --- 19 unchanged lines hidden (view full) --- 1132 generate_iport_record(directory, "iport_record"); 1133 generate_arg32_record(directory, "arg32_record"); 1134 generate_seq_record(directory, "seq_record"); 1135 generate_attr_record(directory, "attr_record"); 1136 generate_ipc_perm_record(directory, "ipc_perm_record"); 1137 generate_groups_record(directory, "groups_record"); 1138 generate_attr32_record(directory, "attr32_record"); 1139 generate_zonename_record(directory, "zonename_record"); |
1140 generate_socketex_record(directory, "socketex_record"); 1141 do_error_records(directory); |
|
1018 } 1019 1020 return (0); 1021} | 1142 } 1143 1144 return (0); 1145} |