* \brief policy
* @author Seiji Munetoh <munetoh@users.sourceforge.jp>
* @date 2010-06-19
- * cleanup 2011-01-22 SM
+ * cleanup 2012-01-05 SM
*
* Security Policy
* - load
* - verify
* - print
*
- *
*/
#include <string.h>
#include <openpts.h>
-// #include <log.h>
/**
* Free policy chain
*/
int freePolicyChain(OPENPTS_POLICY *pol) {
+ /* check */
if (pol == NULL) {
- return PTS_INTERNAL_ERROR;
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
}
+ /* chain */
if (pol->next != NULL) {
freePolicyChain(pol->next);
}
* policy number
*/
int loadPolicyFile(OPENPTS_CONTEXT *ctx, char * filename) {
- FILE *fp;
char buf[BUF_SIZE]; // SMBIOS
char *eq;
char *name;
char *value;
int cnt = 1;
int len;
- OPENPTS_POLICY *pol;
int line = 0;
+ FILE *fp;
+ OPENPTS_POLICY *pol;
- /* open */
+ /* check */
+ if (ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
+ if (filename == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
+ /* open */
if ((fp = fopen(filename, "r")) == NULL) {
- fprintf(stderr, NLS(MS_OPENPTS, OPENPTS_POLICY_FILE_OPEN_FAILED,
+ OUTPUT(NLS(MS_OPENPTS, OPENPTS_POLICY_FILE_OPEN_FAILED,
"Failed to open policy file '%s'\n"), filename);
return -1;
}
/* parse */
-
while (fgets(buf, BUF_SIZE, fp) != NULL) { // read line
/* ignore comment, null line */
if (buf[0] == '#') {
/* new */
pol = xmalloc(sizeof(OPENPTS_POLICY));
if (pol == NULL) {
- ERROR("no mem");
+ LOG(LOG_ERR, "no memory");
cnt = -1; // return -1;
goto error;
}
}
cnt++;
} else {
- //
+ // unknown eq
}
line++;
}
int unknown = 0;
int invalid = 0;
+ /* check */
+ if (ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
pol = ctx->policy_start;
if (pol == NULL) {
/* no policy to check */
+ DEBUG("There is no policy to check with. => Unknown");
return OPENPTS_RESULT_UNKNOWN;
}
/* if any invalid exist */
if (invalid > 0) {
+ DEBUG("Check policy => Invalid");
return OPENPTS_RESULT_INVALID;
}
/* if any unknown exist */
if (unknown > 0) {
+ DEBUG("Check policy => Unknown");
return OPENPTS_RESULT_UNKNOWN;
}
+ DEBUG("Check policy => Valid");
return OPENPTS_RESULT_VALID;
}
/**
* print policy and properties
*
- *
*/
int printPolicy(OPENPTS_CONTEXT *ctx) {
OPENPTS_POLICY *pol;
char *proc_value;
char *status;
+ /* check */
+ if (ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
pol = ctx->policy_start;
+ if (pol == NULL) {
+ /* no policy to print */
+ OUTPUT(NLS(MS_OPENPTS, OPENPTS_PRINT_POLICY_NULL,
+ "There is no policy to print."));
+ return PTS_SUCCESS;
+ }
OUTPUT(NLS(MS_OPENPTS, OPENPTS_PRINT_POLICY,
" id "
}
/* print */
-#if 0
- OUTPUT("%5d %-25s %-13s\n",
- pol->num,
- pol->name, pol->value);
-#else
OUTPUT("%5d %-35s %-28s %-28s %-10s\n",
pol->num,
pol->name, pol->value,
proc_value, status);
-#endif
pol = pol->next;
}
return 0;
}
-
-