Changeset 9
- Timestamp:
- 04/20/07 15:42:40
(2 years ago)
- Author:
- bwilliams
- Message:
Removing requirement for libary used only in the examples
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r6 |
r9 |
|
| 19 | 19 | |
|---|
| 20 | 20 | OBJS=mq_creator mq_destroyer mq_sender mq_reader mq_bin_sender mq_bin_reader shm_creator shm_destroyer shm_sender shm_reader |
|---|
| 21 | | LDFLAGS=-L../src -lsepol -lsipc -Wl,-rpath,$(SHLIBDIR) |
|---|
| | 21 | LDFLAGS=-L../src -lsipc -Wl,-rpath,$(SHLIBDIR) |
|---|
| 22 | 22 | SUBDIRS=policy |
|---|
| 23 | 23 | |
|---|
| r6 |
r9 |
|
| 28 | 28 | #include <sys/types.h> |
|---|
| 29 | 29 | #include <sys/ipc.h> |
|---|
| 30 | | #include <sepol/policydb.h> |
|---|
| | 30 | //#include <sepol/policydb.h> |
|---|
| 31 | 31 | |
|---|
| 32 | 32 | /* Key which sender and receiver have agreed upon */ |
|---|
| … | … | |
| 39 | 39 | #define DATA_END "0xDEADBEEF" |
|---|
| 40 | 40 | |
|---|
| 41 | | int main() |
|---|
| | 41 | int main(int argc, char **argv) |
|---|
| 42 | 42 | { |
|---|
| 43 | 43 | int msglen = 0; |
|---|
| 44 | 44 | char *data = NULL; |
|---|
| 45 | | sepol_policy_file_t *pf = NULL; |
|---|
| 46 | | sepol_policydb_t *policydb = NULL; |
|---|
| | 45 | FILE *outfile; |
|---|
| | 46 | if (argc<2) { |
|---|
| | 47 | printf("usage: %s <output file>\n",argv[0]); |
|---|
| | 48 | exit(1); |
|---|
| | 49 | } |
|---|
| | 50 | |
|---|
| | 51 | outfile=fopen(argv[1],"wb"); |
|---|
| | 52 | if (!outfile) |
|---|
| | 53 | { |
|---|
| | 54 | printf("Can't open output file %s\n",argv[1]); |
|---|
| | 55 | exit(1); |
|---|
| | 56 | } |
|---|
| 47 | 57 | |
|---|
| 48 | 58 | /* Initialize the IPC handle */ |
|---|
| … | … | |
| 59 | 69 | } |
|---|
| 60 | 70 | |
|---|
| 61 | | if (sepol_policy_file_create(&pf)) { |
|---|
| 62 | | fprintf(stderr, "Error creating policy file\n"); |
|---|
| 63 | | return 1; |
|---|
| 64 | | } |
|---|
| 65 | | if (sepol_policydb_create(&policydb)) { |
|---|
| 66 | | fprintf(stderr, "Error creating policydb\n"); |
|---|
| 67 | | free(pf); |
|---|
| 68 | | return 1; |
|---|
| 69 | | } |
|---|
| 70 | 71 | |
|---|
| 71 | | /* First receive the policydb */ |
|---|
| | 72 | |
|---|
| | 73 | /* First receive the file */ |
|---|
| 72 | 74 | sipc_recv_data(ipc, &data, &msglen); |
|---|
| 73 | 75 | printf("Received %d bytes.\n", msglen); |
|---|
| 74 | | sepol_policy_file_set_mem(pf, data, msglen); |
|---|
| 75 | | if (sepol_policydb_read(policydb, pf)) { |
|---|
| 76 | | fprintf(stderr, "Error receiving policydb\n"); |
|---|
| 77 | | return 1; |
|---|
| 78 | | } |
|---|
| | 76 | /* Write it to disk */ |
|---|
| | 77 | fwrite(data,1,msglen,outfile); |
|---|
| | 78 | fclose(outfile); |
|---|
| 79 | 79 | |
|---|
| 80 | 80 | printf("Successfully received policydb\n"); |
|---|
| … | … | |
| 84 | 84 | |
|---|
| 85 | 85 | /* Cleanup */ |
|---|
| 86 | | sepol_policydb_free(policydb); |
|---|
| 87 | | sepol_policy_file_free(pf); |
|---|
| 88 | 86 | sipc_disconnect(ipc); |
|---|
| 89 | 87 | sipc_destroy_handle(ipc); |
|---|
| r6 |
r9 |
|
| 33 | 33 | #include <fcntl.h> |
|---|
| 34 | 34 | #include <errno.h> |
|---|
| 35 | | #include <sepol/policydb.h> |
|---|
| | 35 | |
|---|
| 36 | 36 | |
|---|
| 37 | 37 | /* Key which sender and receiver have agreed upon */ |
|---|
| … | … | |
| 48 | 48 | #define DATA_END "0xDEADBEEF" |
|---|
| 49 | 49 | |
|---|
| 50 | | #define POLICY_FILE "/etc/selinux/targeted/policy/policy.21" |
|---|
| | 50 | //#define POLICY_FILE "/etc/selinux/targeted/policy/policy.21" |
|---|
| 51 | 51 | |
|---|
| 52 | 52 | /* Send an end of transmission marker */ |
|---|
| 53 | 53 | static int send_end_xmit(sipc_t *ipc); |
|---|
| 54 | 54 | |
|---|
| 55 | | int main() |
|---|
| | 55 | int main(int argc, char **argv) |
|---|
| 56 | 56 | { |
|---|
| 57 | 57 | int retv = -1; |
|---|
| … | … | |
| 59 | 59 | int file_data_len = 0; |
|---|
| 60 | 60 | sipc_t *ipc = NULL; |
|---|
| 61 | | |
|---|
| | 61 | if (argc<2) { printf("Usage is %s <input file>\n", argv[0]); |
|---|
| | 62 | exit(1); |
|---|
| | 63 | } |
|---|
| | 64 | |
|---|
| 62 | 65 | /* Initialize and connect IPC handle */ |
|---|
| 63 | 66 | ipc = sipc_init(SIPC_KEY, SIPC_SYSV_MQUEUES, IPC_LEN, 1); |
|---|
| … | … | |
| 80 | 83 | int fd; |
|---|
| 81 | 84 | struct stat sb; |
|---|
| 82 | | fd = open(POLICY_FILE, O_RDONLY); |
|---|
| | 85 | fd = open(argv[1], O_RDONLY); |
|---|
| 83 | 86 | if (fd < 0) { |
|---|
| 84 | | fprintf(stderr, "Failed to open %s: %s\n", POLICY_FILE, |
|---|
| | 87 | fprintf(stderr, "Failed to open %s: %s\n", argv[1], |
|---|
| 85 | 88 | strerror(errno)); |
|---|
| 86 | 89 | return -1; |
|---|
| … | … | |
| 88 | 91 | if (fstat(fd, &sb) < 0) { |
|---|
| 89 | 92 | fprintf(stderr, "Failed to fstat %s: %s\n", |
|---|
| 90 | | POLICY_FILE, strerror(errno)); |
|---|
| | 93 | argv[1], strerror(errno)); |
|---|
| 91 | 94 | return -1; |
|---|
| 92 | 95 | } |
|---|
| … | … | |
| 94 | 97 | file_data = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); |
|---|
| 95 | 98 | if (file_data == MAP_FAILED) { |
|---|
| 96 | | fprintf(stderr, "Failed to mmap %s: %s\n", POLICY_FILE, |
|---|
| | 99 | fprintf(stderr, "Failed to mmap %s: %s\n", argv[1], |
|---|
| 97 | 100 | strerror(errno)); |
|---|
| 98 | 101 | return -1; |
|---|
| … | … | |
| 102 | 105 | close(fd); |
|---|
| 103 | 106 | |
|---|
| 104 | | /* Place the policydb into the handle's internal buffer */ |
|---|
| | 107 | /* Place the file into the handle's internal buffer */ |
|---|
| 105 | 108 | memcpy(data, file_data, file_data_len); |
|---|
| 106 | 109 | |
|---|
| 107 | | /* Send the policydb */ |
|---|
| | 110 | /* Send the file */ |
|---|
| 108 | 111 | if (sipc_send_data(ipc, file_data_len) < 0) { |
|---|
| 109 | 112 | sipc_error(ipc, "Unable to send message!\n"); |
|---|
Download in other formats:
* Generating other formats may take time.