2 * This file is part of the OpenPTS project.
4 * The Initial Developer of the Original Code is International
5 * Business Machines Corporation. Portions created by IBM
6 * Corporation are Copyright (C) 2010 International Business
7 * Machines Corporation. All Rights Reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the Common Public License as published by
11 * IBM Corporation; either version 1 of the License, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * Common Public License for more details.
19 * You should have received a copy of the Common Public License
20 * along with this program; if not, a copy can be viewed at
21 * http://www.opensource.org/licenses/cpl1.0.php.
27 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
29 * cleanup 2011-01-22 SM
49 int freePolicyChain(OPENPTS_POLICY *pol) {
51 return PTS_INTERNAL_ERROR;
54 if (pol->next != NULL) {
55 freePolicyChain(pol->next);
69 int loadPolicyFile(OPENPTS_CONTEXT *ctx, char * filename) {
71 char buf[BUF_SIZE]; // SMBIOS
82 if ((fp = fopen(filename, "r")) == NULL) {
83 ERROR("File %s open was failed\n", filename);
89 while (fgets(buf, BUF_SIZE, fp) != NULL) { // read line
90 /* ignore comment, null line */
92 /* skip comment line */
93 } else if ((eq = strstr(buf, "=")) != NULL) {
97 if (buf[len-1] == 0x0a) buf[len-1] = 0;
104 DEBUG("%4d [%s]=[%s]\n", cnt, name, value);
107 pol = malloc(sizeof(OPENPTS_POLICY));
110 cnt = -1; // return -1;
115 memcpy(pol->name, name, strlen(name) + 1); // TODO
116 memcpy(pol->value, value, strlen(value) + 1); // TODO
119 if (ctx->policy_start == NULL) {
121 ctx->policy_start = pol;
122 ctx->policy_end = pol;
126 ctx->policy_end->next = pol;
127 ctx->policy_end = pol;
145 * check policy and properties
148 * OPENPTS_RESULT_VALID
149 * OPENPTS_RESULT_INVALID
150 * OPENPTS_RESULT_UNKNOWN
152 * hit unknown miss judge
154 * ---------------------------------------
155 * no policy => UNKNOWN
156 * ---------------------------------------
158 * some some 0 => UNKNOWN
159 * - - some => INVALID
160 * ---------------------------------------
163 int checkPolicy(OPENPTS_CONTEXT *ctx) {
165 OPENPTS_PROPERTY *prop;
170 pol = ctx->policy_start;
173 /* no policy to check */
174 return OPENPTS_RESULT_UNKNOWN;
178 while (pol != NULL) {
180 prop = getProperty(ctx, pol->name);
184 /* no prop -> Unknown */
185 addReason(ctx, "[POLICY-L%03d] %s is missing",
190 if (!strcmp(pol->value, prop->value)) {
194 addReason(ctx, "[POLICY-L%03d] %s is %s, not %s",
196 pol->name, prop->value, pol->value);
203 /* if any invalid exist */
205 return OPENPTS_RESULT_INVALID;
208 /* if any unknown exist */
210 return OPENPTS_RESULT_UNKNOWN;
213 return OPENPTS_RESULT_VALID;
217 * print policy and properties
221 int printPolicy(OPENPTS_CONTEXT *ctx) {
223 OPENPTS_PROPERTY *prop;
227 pol = ctx->policy_start;
229 printf(" id "); // id
230 printf(" name "); // name
231 printf(" value(exp) "); // value
232 printf(" value(prop) "); // value
233 printf(" status "); // status
236 printf("------"); // id
237 printf("-------------------------"); // name
238 printf("-------------"); // value
239 printf("-------------"); // value
240 printf("----------"); // value
243 while (pol != NULL) {
245 prop = getProperty(ctx, pol->name);
249 proc_value = "missing";
252 proc_value = prop->value;
253 if (!strcmp(pol->value, prop->value)) {
262 printf("%5d %-25s %-13s\n",
264 pol->name, pol->value);
266 printf("%5d %-35s %-28s %-28s %-10s\n",
268 pol->name, pol->value,