policy-path.h File Reference


Detailed Description

An opaque structure that represents a policy "path".

A policy path may really be a base policy and a number of modules, thus a single string is not sufficient.

Author:
Jeremy A. Mowery jmowery@tresys.com

Jason Tang jtang@tresys.com

Copyright (C) 2006-2007 Tresys Technology, LLC

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Definition in file policy-path.h.

#include "vector.h"

Go to the source code of this file.


Typedefs

typedef apol_policy_path apol_policy_path_t
typedef enum apol_policy_path_type apol_policy_path_type_e
 Type of policy this path represents - either a single path, for a monolithic policy, or a path + multiple modules for modular policy.

Enumerations

enum  apol_policy_path_type { APOL_POLICY_PATH_TYPE_MONOLITHIC = 0, APOL_POLICY_PATH_TYPE_MODULAR }
 Type of policy this path represents - either a single path, for a monolithic policy, or a path + multiple modules for modular policy. More...

Functions

apol_policy_path_tapol_policy_path_create (apol_policy_path_type_e path_type, const char *path, const apol_vector_t *modules)
 Create a policy path from scratch.
apol_policy_path_tapol_policy_path_create_from_policy_path (const apol_policy_path_t *path)
 Create a policy path, initialized from another policy path.
apol_policy_path_tapol_policy_path_create_from_file (const char *filename)
 Create a policy path, initialize by the contents of a policy path list file.
apol_policy_path_tapol_policy_path_create_from_string (const char *path_string)
 Create a policy path, initialized by a special path format string.
void apol_policy_path_destroy (apol_policy_path_t **path)
 Destroy the referencened policy path object.
int apol_policy_path_compare (const apol_policy_path_t *a, const apol_policy_path_t *b)
 Compare two policy paths, determining if one is different than the other.
apol_policy_path_type_e apol_policy_path_get_type (const apol_policy_path_t *path)
 Get the type of policy this path object represents.
const char * apol_policy_path_get_primary (const apol_policy_path_t *path)
 Get the primary path name from a path object.
const apol_vector_tapol_policy_path_get_modules (const apol_policy_path_t *path)
 Get the list of modules from a path object.
int apol_policy_path_to_file (const apol_policy_path_t *path, const char *filename)
 Write a human-readable policy path list to disk.
char * apol_policy_path_to_string (const apol_policy_path_t *path)
 Encode a path object into a specially formatted string.
int apol_file_is_policy_path_list (const char *filename)
 Determine if a file is a policy path list.

Typedef Documentation

typedef struct apol_policy_path apol_policy_path_t
 

Definition at line 38 of file policy-path.h.

Referenced by apol_policy_create_from_policy_path(), apol_policy_path_compare(), apol_policy_path_create(), apol_policy_path_create_from_file(), apol_policy_path_create_from_policy_path(), apol_policy_path_create_from_string(), apol_policy_path_destroy(), apol_policy_path_get_modules(), apol_policy_path_get_primary(), apol_policy_path_get_type(), apol_policy_path_to_file(), apol_policy_path_to_string(), avrule_init(), dta_init(), infoflow_init(), init_poldiff(), main(), open_policies_dialog_run(), open_policy_build_path(), open_policy_init_value(), open_policy_init_values(), open_policy_on_export_click(), open_policy_on_import_click(), open_policy_window_run(), policy_21_init(), policy_view_load_policy_source(), policy_view_source_update(), policy_view_stats_update(), policy_view_update(), preferences_add_recent_policy(), preferences_apol_policy_path_free(), preferences_get_policy(), preferences_parse_new_recent_files(), preferences_parse_old_recent_files(), preferences_policy_path_compare(), preferences_set_policy(), preferences_view_init_values(), preferences_view_on_policy_browse_click(), preferences_view_run(), preferences_write_to_conf_file(), role_init(), seaudit_get_policy_path(), seaudit_parse_command_line(), seaudit_set_policy(), sechk_lib_load_policy(), sediffx_get_policy_path(), sediffx_parse_command_line(), sediffx_set_policy(), terule_init(), toplevel_on_open_activate(), toplevel_on_open_policies_button_click(), toplevel_on_open_recent_policy_activate(), toplevel_open_policies(), toplevel_open_policy(), toplevel_open_policy_runner(), toplevel_set_recent_policies_submenu(), toplevel_update_title_bar(), user_init(), util_policy_path_to_full_string(), and util_policy_path_to_string().

typedef enum apol_policy_path_type apol_policy_path_type_e
 

Type of policy this path represents - either a single path, for a monolithic policy, or a path + multiple modules for modular policy.

Referenced by apol_policy_path_create_from_file(), apol_policy_path_create_from_string(), apol_policy_path_get_type(), main(), open_policy_build_path(), open_policy_init_value(), open_policy_init_values(), seaudit_parse_command_line(), and sediffx_parse_command_line().


Enumeration Type Documentation

enum apol_policy_path_type
 

Type of policy this path represents - either a single path, for a monolithic policy, or a path + multiple modules for modular policy.

Enumeration values:
APOL_POLICY_PATH_TYPE_MONOLITHIC 
APOL_POLICY_PATH_TYPE_MODULAR 

Definition at line 44 of file policy-path.h.

00045         {
00046                 APOL_POLICY_PATH_TYPE_MONOLITHIC = 0,
00047                 APOL_POLICY_PATH_TYPE_MODULAR
00048         } apol_policy_path_type_e;


Function Documentation

apol_policy_path_t* apol_policy_path_create apol_policy_path_type_e  path_type,
const char *  path,
const apol_vector_t modules
 

Create a policy path from scratch.

The resulting object represents the file or files needed to load a policy.

Parameters:
path_type Type of policy to represent.
path Primary path name. For modular policies this is the base policy's path.
modules Vector of strings representing modules' paths. The vector can be NULL to mean no modules. This parameter is ignored if path_type is not APOL_POLICY_PATH_TYPE_MODULAR. The function will duplicate the vector and its contents.
Returns:
An apol_policy_path object, or NULL upon error.

Definition at line 45 of file policy-path.c.

References apol_policy_path_destroy(), apol_policy_path_t, apol_str_strcmp(), apol_str_strdup(), apol_vector_create(), apol_vector_create_from_vector(), apol_vector_sort_uniquify(), apol_vector_t, apol_policy_path::modules, and apol_policy_path::path_type.

Referenced by apol_policy_path_create_from_file(), apol_policy_path_create_from_policy_path(), apol_policy_path_create_from_string(), avrule_init(), dta_init(), infoflow_init(), init_poldiff(), main(), open_policy_build_path(), policy_21_init(), preferences_create(), preferences_parse_old_recent_files(), role_init(), seaudit_parse_command_line(), sechk_lib_load_policy(), sediffx_parse_command_line(), terule_init(), and user_init().

00046 {
00047         apol_policy_path_t *p = NULL;
00048 
00049         if (path == NULL) {
00050                 errno = EINVAL;
00051                 return NULL;
00052         }
00053         if ((p = calloc(1, sizeof(*p))) == NULL) {
00054                 return NULL;
00055         }
00056         p->path_type = path_type;
00057         if ((p->base = strdup(path)) == NULL) {
00058                 apol_policy_path_destroy(&p);
00059                 return NULL;
00060         }
00061         if (p->path_type == APOL_POLICY_PATH_TYPE_MODULAR) {
00062                 if (modules == NULL) {
00063                         p->modules = apol_vector_create(free);
00064                 } else {
00065                         p->modules = apol_vector_create_from_vector(modules, apol_str_strdup, NULL, free);
00066                 }
00067                 if (p->modules == NULL) {
00068                         apol_policy_path_destroy(&p);
00069                         return NULL;
00070                 }
00071                 apol_vector_sort_uniquify(p->modules, apol_str_strcmp, NULL);
00072         }
00073         return p;
00074 }

apol_policy_path_t* apol_policy_path_create_from_policy_path const apol_policy_path_t path  ) 
 

Create a policy path, initialized from another policy path.

This function recursively duplicates all data within the original path.

Parameters:
path Policy path to duplicate.
Returns:
An apol_policy_path object, or NULL upon error.

Definition at line 76 of file policy-path.c.

References apol_policy_path_create(), apol_policy_path_t, apol_policy_path::base, apol_policy_path::modules, and apol_policy_path::path_type.

Referenced by preferences_add_recent_policy(), preferences_set_policy(), preferences_view_init_values(), preferences_view_on_policy_current_click(), seaudit_parse_command_line(), and toplevel_on_open_recent_policy_activate().

00077 {
00078         apol_policy_path_t *p;
00079         if (path == NULL) {
00080                 errno = EINVAL;
00081                 return NULL;
00082         }
00083         p = apol_policy_path_create(path->path_type, path->base, path->modules);
00084         return p;
00085 }

apol_policy_path_t* apol_policy_path_create_from_file const char *  filename  ) 
 

Create a policy path, initialize by the contents of a policy path list file.

Call apol_policy_path_to_filename() to write a policy path list to disk.

Parameters:
filename Name of the file containing a policy path list.
Returns:
An apol_policy_path object, or NULL upon error.

Definition at line 87 of file policy-path.c.

References apol_policy_path_create(), apol_policy_path_destroy(), apol_policy_path_t, apol_policy_path_type_e, apol_str_split(), apol_str_trim(), apol_vector_append(), apol_vector_destroy(), apol_vector_get_element(), apol_vector_get_size(), apol_vector_t, getline(), apol_policy_path::modules, and POLICY_PATH_MAGIC.

Referenced by main(), open_policy_on_import_click(), seaudit_parse_command_line(), and sediffx_parse_command_line().

00088 {
00089         FILE *f = NULL;
00090         apol_policy_path_t *path = NULL;
00091         apol_policy_path_type_e path_type;
00092         char *line = NULL, *s;
00093         apol_vector_t *header_tokens = NULL;
00094         size_t len;
00095         int read_base = 0, retval = -1, error = 0;
00096 
00097         if (filename == NULL) {
00098                 error = EINVAL;
00099                 goto cleanup;
00100         }
00101         if ((f = fopen(filename, "r")) == NULL) {
00102                 error = errno;
00103                 goto cleanup;
00104         }
00105 
00106         if (getline(&line, &len, f) < 0) {
00107                 error = EIO;
00108                 goto cleanup;
00109         }
00110         apol_str_trim(line);
00111         if (strncmp(line, POLICY_PATH_MAGIC, strlen(POLICY_PATH_MAGIC)) != 0) {
00112                 error = EIO;
00113                 goto cleanup;
00114         }
00115 
00116         apol_str_trim(line);
00117         if ((header_tokens = apol_str_split(line, " ")) == NULL) {
00118                 error = errno;
00119                 goto cleanup;
00120         }
00121         if (apol_vector_get_size(header_tokens) < 3) {
00122                 error = EIO;
00123                 goto cleanup;
00124         }
00125         s = apol_vector_get_element(header_tokens, 1);
00126         if (atoi(s) == 0 || atoi(s) > POLICY_PATH_MAX_VERSION) {
00127                 error = ENOTSUP;
00128                 goto cleanup;
00129         }
00130         s = apol_vector_get_element(header_tokens, 2);
00131         if (strcmp(s, "monolithic") == 0) {
00132                 path_type = APOL_POLICY_PATH_TYPE_MONOLITHIC;
00133         } else if (strcmp(s, "modular") == 0) {
00134                 path_type = APOL_POLICY_PATH_TYPE_MODULAR;
00135         } else {
00136                 error = EIO;
00137                 goto cleanup;
00138         }
00139 
00140         while (getline(&line, &len, f) >= 0) {
00141                 apol_str_trim(line);
00142                 if (line[0] == '#') {
00143                         continue;
00144                 }
00145                 if (!read_base) {
00146                         /* trying to parse a base policy / monolithic policy line */
00147                         if ((path = apol_policy_path_create(path_type, line, NULL)) == NULL) {
00148                                 error = errno;
00149                                 goto cleanup;
00150                         }
00151                         read_base = 1;
00152                 } else {
00153                         /* trying to parse a module line */
00154                         if (path_type == APOL_POLICY_PATH_TYPE_MONOLITHIC) {
00155                                 error = EIO;
00156                                 goto cleanup;
00157                         } else {
00158                                 if ((s = strdup(line)) == NULL || apol_vector_append(path->modules, s) < 0) {
00159                                         error = errno;
00160                                         free(s);
00161                                         goto cleanup;
00162                                 }
00163                         }
00164                 }
00165         }
00166         if (read_base == 0) {
00167                 error = EIO;
00168                 goto cleanup;
00169         }
00170         retval = 0;
00171       cleanup:
00172         if (f != NULL) {
00173                 fclose(f);
00174         }
00175         free(line);
00176         apol_vector_destroy(&header_tokens);
00177         if (retval != 0) {
00178                 apol_policy_path_destroy(&path);
00179                 errno = error;
00180         }
00181         return path;
00182 }

apol_policy_path_t* apol_policy_path_create_from_string const char *  path_string  ) 
 

Create a policy path, initialized by a special path format string.

Call apol_policy_path_to_string() to create this string.

Parameters:
path_string String containing initialization data for the object.
Returns:
An apol_policy_path object, or NULL upon error.

Definition at line 184 of file policy-path.c.

References apol_policy_path_create(), apol_policy_path_destroy(), apol_policy_path_t, apol_policy_path_type_e, apol_str_split(), apol_str_strcmp(), apol_vector_append(), apol_vector_destroy(), apol_vector_get_element(), apol_vector_get_size(), apol_vector_sort_uniquify(), apol_vector_t, and apol_policy_path::modules.

Referenced by preferences_create(), and preferences_parse_new_recent_files().

00185 {
00186         apol_policy_path_t *p = NULL;
00187         apol_vector_t *tokens = NULL;
00188         apol_policy_path_type_e path_type;
00189         char *s;
00190         size_t i;
00191         if (path_string == NULL) {
00192                 errno = EINVAL;
00193                 return NULL;
00194         }
00195         if ((tokens = apol_str_split(path_string, ":")) == NULL) {
00196                 return NULL;
00197         }
00198 
00199         /* first token identifies the path type */
00200         if (apol_vector_get_size(tokens) < 2) {
00201                 apol_vector_destroy(&tokens);
00202                 return NULL;
00203         }
00204         s = apol_vector_get_element(tokens, 0);
00205         if (strcmp(s, "monolithic") == 0) {
00206                 path_type = APOL_POLICY_PATH_TYPE_MONOLITHIC;
00207         } else if (strcmp(s, "modular") == 0) {
00208                 path_type = APOL_POLICY_PATH_TYPE_MODULAR;
00209         } else {
00210                 apol_vector_destroy(&tokens);
00211                 errno = EINVAL;
00212                 return NULL;
00213         }
00214 
00215         /* second token identifies gives base path */
00216         s = apol_vector_get_element(tokens, 1);
00217         if ((p = apol_policy_path_create(path_type, s, NULL)) == NULL) {
00218                 apol_vector_destroy(&tokens);
00219                 return NULL;
00220         }
00221 
00222         if (path_type == APOL_POLICY_PATH_TYPE_MODULAR) {
00223                 /* remainder are module paths */
00224                 for (i = 2; i < apol_vector_get_size(tokens); i++) {
00225                         s = apol_vector_get_element(tokens, i);
00226                         if ((s = strdup(s)) == NULL || apol_vector_append(p->modules, s) < 0) {
00227                                 free(s);
00228                                 apol_vector_destroy(&tokens);
00229                                 apol_policy_path_destroy(&p);
00230                                 return NULL;
00231                         }
00232                 }
00233                 apol_vector_sort_uniquify(p->modules, apol_str_strcmp, NULL);
00234         }
00235         return p;
00236 }

void apol_policy_path_destroy apol_policy_path_t **  path  ) 
 

Destroy the referencened policy path object.

Parameters:
path Policy path to destroy. The pointer will be set to NULL afterwards. (If pointer is already NULL then do nothing.)

Definition at line 238 of file policy-path.c.

References apol_policy_path_t, and apol_vector_destroy().

Referenced by apol_policy_path_create(), apol_policy_path_create_from_file(), apol_policy_path_create_from_string(), avrule_init(), dta_init(), infoflow_init(), init_poldiff(), main(), open_policy_on_export_click(), open_policy_on_import_click(), policy_21_init(), preferences_add_recent_policy(), preferences_apol_policy_path_free(), preferences_create(), preferences_destroy(), preferences_parse_new_recent_files(), preferences_parse_old_recent_files(), preferences_set_policy(), preferences_view_on_policy_browse_click(), preferences_view_on_policy_current_click(), role_init(), seaudit_set_policy(), sechk_lib_destroy(), sediffx_destroy(), sediffx_parse_command_line(), sediffx_set_policy(), terule_init(), toplevel_open_policies(), toplevel_open_policy(), and user_init().

00239 {
00240         if (path != NULL && *path != NULL) {
00241                 free((*path)->base);
00242                 apol_vector_destroy(&(*path)->modules);
00243                 free(*path);
00244                 *path = NULL;
00245         }
00246 }

int apol_policy_path_compare const apol_policy_path_t a,
const apol_policy_path_t b
 

Compare two policy paths, determining if one is different than the other.

The returned value is stable, in that it may be used as the basis for sorting a list of policy paths. Monolithic policies are considered "less than" modular policies.

Parameters:
a First policy path to compare.
b Second policy path to compare.
Returns:
< 0 if path A is "less than" B, > 0 if A is "greater than" B, or 0 if equivalent or undeterminable.

Definition at line 248 of file policy-path.c.

References apol_policy_path_t, apol_str_strcmp(), apol_vector_compare(), apol_policy_path::base, apol_policy_path::modules, and apol_policy_path::path_type.

Referenced by preferences_policy_path_compare().

00249 {
00250         int cmp;
00251         if (a == NULL || b == NULL) {
00252                 errno = EINVAL;
00253                 return 0;
00254         }
00255         if ((cmp = a->path_type - b->path_type) != 0) {
00256                 return cmp;
00257         }
00258         if ((cmp = strcmp(a->base, b->base)) != 0) {
00259                 return cmp;
00260         }
00261         if (a->path_type == APOL_POLICY_PATH_TYPE_MODULAR) {
00262                 /* only compare module vector if that field is relevant */
00263                 size_t i;
00264                 cmp = apol_vector_compare(a->modules, b->modules, apol_str_strcmp, NULL, &i);
00265                 if (cmp != 0) {
00266                         return cmp;
00267                 }
00268         }
00269         return 0;
00270 }

apol_policy_path_type_e apol_policy_path_get_type const apol_policy_path_t path  ) 
 

Get the type of policy this path object represents.

Parameters:
path Policy path object to query.
Returns:
Type of policy the object represents.

Definition at line 272 of file policy-path.c.

References apol_policy_path_t, apol_policy_path_type_e, and apol_policy_path::path_type.

Referenced by apol_policy_create_from_policy_path(), open_policy_init_value(), open_policy_init_values(), toplevel_set_recent_policies_submenu(), toplevel_update_title_bar(), util_policy_path_to_full_string(), and util_policy_path_to_string().

00273 {
00274         if (path == NULL) {
00275                 errno = EINVAL;
00276                 return APOL_POLICY_PATH_TYPE_MONOLITHIC;
00277         }
00278         return path->path_type;
00279 }

const char* apol_policy_path_get_primary const apol_policy_path_t path  ) 
 

Get the primary path name from a path object.

For monolithic policies this is the path to the policy. For modular policies this is the base policy path.

Parameters:
path Policy path object to query.
Returns:
Primary path, or NULL upon error. Do not modify this string.

Definition at line 281 of file policy-path.c.

References apol_policy_path_t, and apol_policy_path::base.

Referenced by apol_policy_create_from_policy_path(), open_policy_init_value(), open_policy_init_values(), policy_view_load_policy_source(), policy_view_source_update(), sechk_lib_load_policy(), toplevel_open_policy(), toplevel_set_recent_policies_submenu(), toplevel_update_title_bar(), util_policy_path_to_full_string(), and util_policy_path_to_string().

00282 {
00283         if (path == NULL) {
00284                 errno = EINVAL;
00285                 return NULL;
00286         }
00287         return path->base;
00288 }

const apol_vector_t* apol_policy_path_get_modules const apol_policy_path_t path  ) 
 

Get the list of modules from a path object.

This will be a vector of strings. It is an error to call this function for non-modular policies.

Parameters:
path Policy path object to query.
Returns:
Vector of module paths, or NULL upon error. Do not modify this vector or its contents. Note that the vector could be empty.

Definition at line 290 of file policy-path.c.

References apol_policy_path_t, apol_vector_t, apol_policy_path::modules, and apol_policy_path::path_type.

Referenced by apol_policy_create_from_policy_path(), open_policy_init_value(), open_policy_init_values(), toplevel_set_recent_policies_submenu(), util_policy_path_to_full_string(), and util_policy_path_to_string().

00291 {
00292         if (path == NULL || path->path_type != APOL_POLICY_PATH_TYPE_MODULAR) {
00293                 errno = EINVAL;
00294                 return NULL;
00295         }
00296         return path->modules;
00297 }

int apol_policy_path_to_file const apol_policy_path_t path,
const char *  filename
 

Write a human-readable policy path list to disk.

This file describes a policy path and is suitable as input to apol_policy_path_create_from_file().

Parameters:
path Policy path to write to disk.
filename Name of the file to write policy path list. If the file already exists it will be overwritten.
Returns:
0 on successful write, < 0 on error.

Definition at line 299 of file policy-path.c.

References apol_policy_path_t, apol_vector_get_element(), apol_vector_get_size(), apol_policy_path::base, apol_policy_path::modules, apol_policy_path::path_type, POLICY_PATH_MAGIC, and POLICY_PATH_MAX_VERSION.

Referenced by open_policy_on_export_click().

00300 {
00301         FILE *f = NULL;
00302         char *path_type;
00303         size_t i;
00304         int retval = -1, error = 0;
00305         if (path == NULL || filename == NULL) {
00306                 errno = EINVAL;
00307                 goto cleanup;
00308         }
00309         if ((f = fopen(filename, "w")) == NULL) {
00310                 error = errno;
00311                 goto cleanup;
00312         }
00313         if (path->path_type == APOL_POLICY_PATH_TYPE_MODULAR) {
00314                 path_type = "modular";
00315         } else {
00316                 path_type = "monolithic";
00317         }
00318         if (fprintf(f, "%s %d %s\n", POLICY_PATH_MAGIC, POLICY_PATH_MAX_VERSION, path_type) < 0) {
00319                 error = errno;
00320                 goto cleanup;
00321         }
00322         if (fprintf(f, "%s\n", path->base) < 0) {
00323                 error = errno;
00324                 goto cleanup;
00325         }
00326         if (path->path_type == APOL_POLICY_PATH_TYPE_MODULAR) {
00327                 for (i = 0; i < apol_vector_get_size(path->modules); i++) {
00328                         char *m = apol_vector_get_element(path->modules, i);
00329                         if (fprintf(f, "%s\n", m) < 0) {
00330                                 error = errno;
00331                                 goto cleanup;
00332                         }
00333                 }
00334         }
00335 
00336         retval = 0;
00337       cleanup:
00338         if (f != NULL) {
00339                 fclose(f);
00340         }
00341         if (retval != 0) {
00342                 error = errno;
00343         }
00344         return retval;
00345 }

char* apol_policy_path_to_string const apol_policy_path_t path  ) 
 

Encode a path object into a specially formatted string.

The resulting string is suitable as input to apol_policy_path_create_from_string().

Parameters:
path Policy path object to encode.
Returns:
Formatted string for the path object, or NULL upon error. The caller is responsible for calling free() upon the returned value.

Definition at line 347 of file policy-path.c.

References apol_policy_path_t, apol_str_appendf(), apol_vector_get_element(), apol_vector_get_size(), apol_policy_path::base, apol_policy_path::modules, and apol_policy_path::path_type.

Referenced by preferences_write_to_conf_file(), and sechk_lib_load_policy().

00348 {
00349         char *path_type;
00350         char *s = NULL;
00351         size_t len = 0, i;
00352         if (path == NULL) {
00353                 errno = EINVAL;
00354                 return NULL;
00355         }
00356         if (path->path_type == APOL_POLICY_PATH_TYPE_MODULAR) {
00357                 path_type = "modular";
00358         } else {
00359                 path_type = "monolithic";
00360         }
00361         if (apol_str_appendf(&s, &len, "%s:%s", path_type, path->base) < 0) {
00362                 return NULL;
00363         }
00364         if (path->path_type == APOL_POLICY_PATH_TYPE_MODULAR) {
00365                 for (i = 0; i < apol_vector_get_size(path->modules); i++) {
00366                         char *m = apol_vector_get_element(path->modules, i);
00367                         if (apol_str_appendf(&s, &len, ":%s", m) < 0) {
00368                                 return NULL;
00369                         }
00370                 }
00371         }
00372         return s;
00373 }

int apol_file_is_policy_path_list const char *  filename  ) 
 

Determine if a file is a policy path list.

Parameters:
filename Name of the file to test.
Returns:
> 0 if the file is a policy path list, 0 if it is not, and < 0 on error.

Definition at line 375 of file policy-path.c.

References apol_str_trim(), getline(), and POLICY_PATH_MAGIC.

Referenced by main(), seaudit_parse_command_line(), and sediffx_parse_command_line().

00376 {
00377         FILE *f = NULL;
00378         char *line = NULL;
00379         size_t len = 0;
00380         int retval = -1, error = 0;
00381 
00382         if (filename == NULL) {
00383                 error = EINVAL;
00384                 goto cleanup;
00385         }
00386         if ((f = fopen(filename, "r")) == NULL) {
00387                 error = errno;
00388                 goto cleanup;
00389         }
00390 
00391         if (getline(&line, &len, f) < 0) {
00392                 error = EIO;
00393                 goto cleanup;
00394         }
00395         apol_str_trim(line);
00396         if (strncmp(line, POLICY_PATH_MAGIC, strlen(POLICY_PATH_MAGIC)) != 0) {
00397                 retval = 0;
00398                 goto cleanup;
00399         }
00400         retval = 1;
00401 
00402       cleanup:
00403         if (f)
00404                 fclose(f);
00405         free(line);
00406         if (retval < 0)
00407                 errno = error;
00408         return retval;
00409 }