From owner-p4-projects@FreeBSD.ORG Thu Oct 9 18:17:36 2003 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 1DE6116A4C0; Thu, 9 Oct 2003 18:17:36 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id ED94116A4B3 for ; Thu, 9 Oct 2003 18:17:35 -0700 (PDT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4EFE243FBD for ; Thu, 9 Oct 2003 18:17:35 -0700 (PDT) (envelope-from Hrishikesh_Dandekar@NAI.com) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.9/8.12.9) with ESMTP id h9A1HZXJ031277 for ; Thu, 9 Oct 2003 18:17:35 -0700 (PDT) (envelope-from Hrishikesh_Dandekar@NAI.com) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.9/8.12.9/Submit) id h9A1HYut031274 for perforce@freebsd.org; Thu, 9 Oct 2003 18:17:34 -0700 (PDT) (envelope-from Hrishikesh_Dandekar@NAI.com) Date: Thu, 9 Oct 2003 18:17:34 -0700 (PDT) Message-Id: <200310100117.h9A1HYut031274@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to Hrishikesh_Dandekar@NAI.com using -f From: Hrishikesh Dandekar To: Perforce Change Reviews Subject: PERFORCE change 39435 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Oct 2003 01:17:36 -0000 http://perforce.freebsd.org/chv.cgi?CH=39435 Change 39435 by hdandeka@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;