PERFORCE change 39435 for review
Hrishikesh Dandekar
hdandeka at FreeBSD.org
Fri Oct 10 01:17:34 GMT 2003
http://perforce.freebsd.org/chv.cgi?CH=39435
Change 39435 by hdandeka at hdandeka_yash on 2003/10/09 18:17:19
replace policydb_read with a call to sebsd_load_policy.
Affected files ...
.. //depot/projects/trustedbsd/sebsd/contrib/sebsd/checkpolicy/checkpolicy.c#6 edit
Differences ...
==== //depot/projects/trustedbsd/sebsd/contrib/sebsd/checkpolicy/checkpolicy.c#6 (text+ko) ====
@@ -324,7 +324,7 @@
FILE *fp, *outfp = NULL;
int fd;
void *filedata;
- struct stat fsb;
+ struct stat sb;
size_t filelen;
while ((ch = getopt(argc, argv, "o:dbV")) != EOF) {
@@ -359,18 +359,53 @@
printf("%s: loading policy configuration from %s\n", argv[0],
file);
- yyin = fopen(file, "r");
- if (!yyin) {
- fprintf(stderr, "%s: unable to open %s\n", argv[0],
- file);
- exit(1);
- }
if (binary) {
- if (policydb_read(&policydb, yyin)) {
- fprintf(stderr, "%s: error(s) encountered while parsing configuration\n", argv[0]);
+ fd = open(file, O_RDONLY);
+ if (fd < 0) {
+ printf("%s: unable to open %s\n", argv[0], ans);
+ exit(1);
+ }
+ if(fstat(fd, &sb) < 0) {
+ printf("%s: unable to get size of %s\n", argv[0], ans);
+ exit(1);
+ }
+ filelen = (size_t) sb.st_size;
+ if ( ((off_t) filelen) != sb.st_size ) {
+ printf("%s: large file, size truncated\n", argv[0]);
+ close(fd);
+ exit(1);
+ }
+
+ filedata = mmap(NULL, filelen, PROT_READ, MAP_SHARED, fd,0);
+ if (filedata == MAP_FAILED) {
+ printf("Can't map %s\n", ans);
+ close(fd);
+ exit(1);
+ }
+ ret = security_load_policy(filedata, filelen);
+ switch (ret) {
+ case 0:
+ printf("\nsuccess\n");
+ break;
+ case -EINVAL:
+ printf("\ninvalid policy\n");
+ break;
+ case -ENOMEM:
+ printf("\nout of memory\n");
+ break;
+ default:
+ printf("return code 0x%x\n", ret);
+ }
+ /* XXX: call munmap(filedata, filelen) or not ? */
+ close(fd);
+ } else {
+ yyin = fopen(file, "r");
+ if (!yyin) {
+ fprintf(stderr, "%s: unable to open %s\n", argv[0],
+ file);
exit(1);
}
- } else {
+
if (policydb_init(&policydb))
exit(1);
@@ -627,12 +662,12 @@
printf("%s: unable to open %s\n", argv[0], ans);
break;
}
- if(fstat(fd, &fsb) < 0) {
+ if(fstat(fd, &sb) < 0) {
printf("%s: unable to get size of %s\n", argv[0], ans);
break;
}
- filelen = (size_t) fsb.st_size;
- if ( ((off_t) filelen) != fsb.st_size ) {
+ filelen = (size_t) sb.st_size;
+ if ( ((off_t) filelen) != sb.st_size ) {
printf("%s: large file, size truncated\n", argv[0]);
close(fd);
break;
To Unsubscribe: send mail to majordomo at trustedbsd.org
with "unsubscribe trustedbsd-cvs" in the body of the message
More information about the trustedbsd-cvs
mailing list