ia64/xen-unstable

view tools/flask/loadpolicy/loadpolicy.c @ 19835:edfdeb150f27

Fix buildsystem to detect udev > version 124

udev removed the udevinfo symlink from versions higher than 123 and
xen's build-system could not detect if udev is in place and has the
required version.

Signed-off-by: Marc-A. Dahlhaus <mad@wol.de>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 25 13:02:37 2009 +0100 (2009-06-25)
parents 789e4303b330
children
line source
1 /*
2 *
3 * Authors: Michael LeMay, <mdlemay@epoch.ncsc.mil>
4 * George Coker, <gscoker@alpha.ncsc.mil>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2,
8 * as published by the Free Software Foundation.
9 */
11 #include <stdlib.h>
12 #include <errno.h>
13 #include <stdio.h>
14 #include <xenctrl.h>
15 #include <fcntl.h>
16 #include <sys/mman.h>
17 #include <sys/stat.h>
18 #include <string.h>
19 #include <unistd.h>
20 #include <flask.h>
22 #define USE_MMAP
24 static void usage (int argCnt, const char *args[])
25 {
26 fprintf(stderr, "Usage: %s <policy.file>\n", args[0]);
27 exit(1);
28 }
30 int main (int argCnt, const char *args[])
31 {
32 const char *polFName;
33 int polFd = 0;
34 void *polMem = NULL;
35 void *polMemCp = NULL;
36 struct stat info;
37 int ret;
38 int xch = 0;
40 if (argCnt != 2)
41 usage(argCnt, args);
43 polFName = args[1];
44 polFd = open(polFName, O_RDONLY);
45 if ( polFd < 0 )
46 {
47 fprintf(stderr, "Error occurred opening policy file '%s': %s\n",
48 polFName, strerror(errno));
49 ret = -1;
50 goto cleanup;
51 }
53 ret = stat(polFName, &info);
54 if ( ret < 0 )
55 {
56 fprintf(stderr, "Error occurred retrieving information about"
57 "policy file '%s': %s\n", polFName, strerror(errno));
58 goto cleanup;
59 }
61 polMemCp = malloc(info.st_size);
63 #ifdef USE_MMAP
64 polMem = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, polFd, 0);
65 if ( !polMem )
66 {
67 fprintf(stderr, "Error occurred mapping policy file in memory: %s\n",
68 strerror(errno));
69 ret = -1;
70 goto cleanup;
71 }
73 xch = xc_interface_open();
74 if ( xch < 0 )
75 {
76 fprintf(stderr, "Unable to create interface to xenctrl: %s\n",
77 strerror(errno));
78 ret = -1;
79 goto cleanup;
80 }
82 memcpy(polMemCp, polMem, info.st_size);
83 #else
84 ret = read(polFd, polMemCp, info.st_size);
85 if ( ret < 0 )
86 {
87 fprintf(stderr, "Unable to read new Flask policy file: %s\n",
88 strerror(errno));
89 goto cleanup;
90 }
91 else
92 {
93 printf("Read %d bytes from policy file '%s'.\n", ret, polFName);
94 }
95 #endif
97 ret = flask_load(xch, polMemCp, info.st_size);
98 if ( ret < 0 )
99 {
100 errno = -ret;
101 fprintf(stderr, "Unable to load new Flask policy: %s\n",
102 strerror(errno));
103 ret = -1;
104 goto cleanup;
105 }
106 else
107 {
108 printf("Successfully loaded policy.\n");
109 }
111 done:
112 if ( polMemCp )
113 free(polMemCp);
114 if ( polMem )
115 {
116 ret = munmap(polMem, info.st_size);
117 if ( ret < 0 )
118 fprintf(stderr, "Unable to unmap policy memory: %s\n", strerror(errno));
119 }
120 if ( polFd )
121 close(polFd);
122 if ( xch )
123 xc_interface_close(xch);
125 return ret;
127 cleanup:
128 goto done;
129 }