fclist.hh File Reference


Detailed Description

Defines the public interface for the file context list abstract object.

A user must call a constructor for one of sefs_fcfile_t, sefs_db_t, or sefs_filesystem_t to create a sefs_fclist_t object.

Author:
Jeremy A. Mowery jmowery@tresys.com

Jason Tang jtang@tresys.com

Copyright (C) 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 fclist.hh.

#include <sefs/entry.hh>
#include <sefs/query.hh>
#include <selinux/selinux.h>
#include <stdarg.h>
#include <apol/policy.h>
#include <stdexcept>

Go to the source code of this file.


Classes

class  sefs_fclist
 An abstract class the represents a list of file contexts. More...

Defines

#define SEFS_MSG_ERR   1
#define SEFS_MSG_WARN   2
#define SEFS_MSG_INFO   3
#define SEFS_ERR(fclist, format,)   sefs_fclist_handleMsg(fclist, SEFS_MSG_ERR, format, __VA_ARGS__)
 Invoke a sefs_fclist_t's callback for an error, passing it a format string and arguments.
#define SEFS_WARN(fclist, format,)   sefs_fclist_handleMsg(fclist, SEFS_MSG_WARN, format, __VA_ARGS__)
 Invoke a sefs_fclist_t's callback for a warning, passing it a format string and arguments.
#define SEFS_INFO(fclist, format,)   sefs_fclist_handleMsg(fclist, SEFS_MSG_INFO, format, __VA_ARGS__)
 Invoke a sefs_fclist's callback for an informational message, passing it a format string and arguments.
#define SEFS_MAP_FUNC_DEFINED

Typedefs

typedef void(* sefs_callback_fn_t )(void *varg, const struct sefs_fclist *fclist, int level, const char *fmt, va_list argp)
typedef enum sefs_fclist_type sefs_fclist_type_e
 Possible types of fclist for use with sefs_fclist_get_data().
typedef int(* sefs_fclist_map_fn_t )(sefs_fclist *, const sefs_entry *, void *)
 Function invoked upon each matching file context entry during a query.
typedef sefs_fclist sefs_fclist_t

Enumerations

enum  sefs_fclist_type { SEFS_FCLIST_TYPE_NONE = 0, SEFS_FCLIST_TYPE_FILESYSTEM, SEFS_FCLIST_TYPE_FCFILE, SEFS_FCLIST_TYPE_DB }
 Possible types of fclist for use with sefs_fclist_get_data(). More...

Functions

void sefs_fclist_handleMsg (const struct sefs_fclist *fclist, int level, const char *fmt,...)
 __attribute__ ((format(printf, 3, 4))) void sefs_fclist_handleMsg(const struct sefs_fclist *fclist
void sefs_fclist_destroy (sefs_fclist_t **fclist)
 Deallocate all memory associated with the referenced fclist object, and then set it to NULL.
int sefs_fclist_run_query_map (sefs_fclist_t *fclist, sefs_query_t *query, sefs_fclist_map_fn_t fn, void *data)
 Perform a sefs query on the given file context list object.
apol_vector_tsefs_fclist_run_query (sefs_fclist_t *fclist, sefs_query_t *query)
 Perform a sefs query on the given file context list object.
bool sefs_fclist_get_is_mls (const sefs_fclist_t *fclist)
 Determine if the contexts in the fclist contain MLS fields.
void sefs_fclist_associate_policy (sefs_fclist_t *fclist, apol_policy_t *policy)
 Associate a policy with the fclist.
sefs_fclist_type_e sefs_fclist_get_fclist_type (const sefs_fclist_t *fclist)
 Get the type of fclist object represented by fclist.

Variables

int level
int const char * fmt

Define Documentation

#define SEFS_MSG_ERR   1
 

Message describes a fatal error.

Definition at line 47 of file fclist.hh.

Referenced by sefs_handle_default_callback().

#define SEFS_MSG_WARN   2
 

Message is issued as a warning but does not represent a fatal error.

Definition at line 48 of file fclist.hh.

Referenced by sefs_handle_default_callback().

#define SEFS_MSG_INFO   3
 

Message is issued for inormational reasons and does not represent an atypical state.

Definition at line 49 of file fclist.hh.

Referenced by sefs_handle_default_callback().

#define SEFS_ERR fclist,
format   )     sefs_fclist_handleMsg(fclist, SEFS_MSG_ERR, format, __VA_ARGS__)
 

Invoke a sefs_fclist_t's callback for an error, passing it a format string and arguments.

Definition at line 71 of file fclist.hh.

Referenced by sefs_fcfile::appendFile(), sefs_fcfile::appendFileList(), sefs_filesystem::buildDevMap(), db_convert::db_convert(), db_create_from_filesystem(), filesystem_ftw_handler(), sefs_fclist::getContext(), sefs_filesystem::getEntry(), sefs_db::getEntry(), db_convert::getID(), sefs_db::isMLS(), sefs_filesystem::isQueryMatch(), sefs_fcfile::parse_line(), sefs_filesystem::runQueryMap(), sefs_fcfile::runQueryMap(), sefs_db::runQueryMap(), sefs_db::save(), sefs_db::sefs_db(), sefs_db_get_ctime(), sefs_db_save(), sefs_fcfile::sefs_fcfile(), sefs_fcfile_append_file(), sefs_fcfile_append_file_list(), sefs_fcfile_get_file_list(), sefs_fclist_associate_policy(), sefs_fclist_get_fclist_type(), sefs_fclist_get_is_mls(), sefs_fclist_run_query(), sefs_fclist_run_query_map(), sefs_filesystem::sefs_filesystem(), sefs_filesystem_get_dev_name(), sefs_filesystem_get_root(), sefs_entry::toString(), and sefs_db::upgradeToDB2().

#define SEFS_WARN fclist,
format   )     sefs_fclist_handleMsg(fclist, SEFS_MSG_WARN, format, __VA_ARGS__)
 

Invoke a sefs_fclist_t's callback for a warning, passing it a format string and arguments.

Definition at line 77 of file fclist.hh.

Referenced by filesystem_ftw_handler(), and sefs_db::sefs_db().

#define SEFS_INFO fclist,
format   )     sefs_fclist_handleMsg(fclist, SEFS_MSG_INFO, format, __VA_ARGS__)
 

Invoke a sefs_fclist's callback for an informational message, passing it a format string and arguments.

Definition at line 83 of file fclist.hh.

Referenced by sefs_db::sefs_db().

#define SEFS_MAP_FUNC_DEFINED
 

Definition at line 98 of file fclist.hh.


Typedef Documentation

typedef void(* sefs_callback_fn_t)(void *varg, const struct sefs_fclist *fclist, int level, const char *fmt, va_list argp)
 

Definition at line 53 of file fclist.hh.

typedef enum sefs_fclist_type sefs_fclist_type_e
 

Possible types of fclist for use with sefs_fclist_get_data().

Referenced by sefs_fclist::fclist_type(), and sefs_fclist_get_fclist_type().

typedef int(* sefs_fclist_map_fn_t)(sefs_fclist *, const sefs_entry *, void *)
 

Function invoked upon each matching file context entry during a query.

Definition at line 103 of file fclist.hh.

typedef struct sefs_fclist sefs_fclist_t
 

Definition at line 269 of file fclist.hh.

Referenced by sechk_lib_load_fc(), sefs_db_create_from_file(), sefs_db_create_from_filesystem(), sefs_fcfile_create(), sefs_fcfile_create_from_file(), sefs_fcfile_create_from_file_list(), sefs_fclist_associate_policy(), sefs_fclist_destroy(), sefs_fclist_get_fclist_type(), sefs_fclist_get_is_mls(), sefs_fclist_run_query(), and sefs_fclist_run_query_map().


Enumeration Type Documentation

enum sefs_fclist_type
 

Possible types of fclist for use with sefs_fclist_get_data().

Enumeration values:
SEFS_FCLIST_TYPE_NONE  Not an actual type, used for error conditions
SEFS_FCLIST_TYPE_FILESYSTEM  get_data returns sefs_filesystem_t, a representation of a file system
SEFS_FCLIST_TYPE_FCFILE  get_data returns sefs_fcfile_t, a representation of a collection of file_context files
SEFS_FCLIST_TYPE_DB  get_data returns sefs_db_t, a representation of a database of file system contexts

Definition at line 59 of file fclist.hh.

00060         {
00061                 SEFS_FCLIST_TYPE_NONE = 0,      /*!< Not an actual type, used for error conditions */
00062                 SEFS_FCLIST_TYPE_FILESYSTEM,    /*!< get_data returns sefs_filesystem_t, a representation of a file system */
00063                 SEFS_FCLIST_TYPE_FCFILE,        /*!< get_data returns sefs_fcfile_t, a representation of a collection of file_context files */
00064                 SEFS_FCLIST_TYPE_DB    /*!< get_data returns sefs_db_t, a representation of a database of file system contexts */
00065         } sefs_fclist_type_e;


Function Documentation

void sefs_fclist_handleMsg const struct sefs_fclist fclist,
int  level,
const char *  fmt,
  ...
 

Definition at line 455 of file fclist.cc.

References fmt, sefs_fclist::handleMsg(), level, and sefs_handle_default_callback().

00456 {
00457         va_list ap;
00458         va_start(ap, fmt);
00459         if (fclist == NULL)
00460         {
00461                 sefs_handle_default_callback(NULL, NULL, level, fmt, ap);
00462         }
00463         else
00464         {
00465                 fclist->handleMsg(level, fmt, ap);
00466         }
00467         va_end(ap);
00468 }

__attribute__ (format(printf, 3, 4))   )  const
 

void sefs_fclist_destroy sefs_fclist_t **  fclist  ) 
 

Deallocate all memory associated with the referenced fclist object, and then set it to NULL.

This function does nothing if the fclist object is already NULL.

Parameters:
Reference to a fclist object to destroy.

Definition at line 470 of file fclist.cc.

References sefs_fclist_t.

Referenced by sechk_lib_destroy().

00471 {
00472         if (fclist != NULL && *fclist != NULL)
00473         {
00474                 delete(*fclist);
00475                 *fclist = NULL;
00476         }
00477 }

int sefs_fclist_run_query_map sefs_fclist_t fclist,
sefs_query_t query,
sefs_fclist_map_fn_t  fn,
void *  data
 

Perform a sefs query on the given file context list object.

See also:
sefs_fclist::runQueryMap()

Definition at line 479 of file fclist.cc.

References sefs_fclist::runQueryMap(), SEFS_ERR, sefs_fclist_t, and sefs_query_t.

00480 {
00481         if (fclist == NULL)
00482         {
00483                 SEFS_ERR(NULL, "%s", strerror(EINVAL));
00484                 errno = EINVAL;
00485                 return -1;
00486         }
00487         int retval;
00488         try
00489         {
00490                 retval = fclist->runQueryMap(query, fn, data);
00491         }
00492         catch(...)
00493         {
00494                 return -1;
00495         }
00496         return retval;
00497 }

apol_vector_t* sefs_fclist_run_query sefs_fclist_t fclist,
sefs_query_t query
 

Perform a sefs query on the given file context list object.

See also:
sefs_fclist::runQuery()

Definition at line 499 of file fclist.cc.

References apol_vector_t, sefs_fclist::runQuery(), SEFS_ERR, sefs_fclist_t, and sefs_query_t.

Referenced by sechk_lib_load_fc().

00500 {
00501         if (fclist == NULL)
00502         {
00503                 SEFS_ERR(NULL, "%s", strerror(EINVAL));
00504                 errno = EINVAL;
00505                 return NULL;
00506         }
00507         apol_vector_t *v = NULL;
00508         try
00509         {
00510                 v = fclist->runQuery(query);
00511         }
00512         catch(...)
00513         {
00514                 return NULL;
00515         }
00516         return v;
00517 }

bool sefs_fclist_get_is_mls const sefs_fclist_t fclist  ) 
 

Determine if the contexts in the fclist contain MLS fields.

See also:
sefs_fclist::isMLS()

Definition at line 519 of file fclist.cc.

References sefs_fclist::isMLS(), SEFS_ERR, and sefs_fclist_t.

00520 {
00521         if (fclist == NULL)
00522         {
00523                 SEFS_ERR(NULL, "%s", strerror(EINVAL));
00524                 return false;
00525         }
00526         return fclist->isMLS();
00527 }

void sefs_fclist_associate_policy sefs_fclist_t fclist,
apol_policy_t policy
 

Associate a policy with the fclist.

See also:
sefs_fclist::associatePolicy()

sefs_query_set_type()

sefs_query_set_range()

Definition at line 529 of file fclist.cc.

References apol_policy_t, sefs_fclist::associatePolicy(), SEFS_ERR, and sefs_fclist_t.

00530 {
00531         if (fclist == NULL)
00532         {
00533                 SEFS_ERR(NULL, "%s", strerror(EINVAL));
00534                 errno = EINVAL;
00535         }
00536         else
00537         {
00538                 fclist->associatePolicy(policy);
00539         }
00540 }

sefs_fclist_type_e sefs_fclist_get_fclist_type const sefs_fclist_t fclist  ) 
 

Get the type of fclist object represented by fclist.

See also:
sefs_fclist::fclist_type()

Definition at line 542 of file fclist.cc.

References sefs_fclist::fclist_type(), SEFS_ERR, sefs_fclist_t, and sefs_fclist_type_e.

00543 {
00544         if (fclist == NULL)
00545         {
00546                 SEFS_ERR(NULL, "%s", strerror(EINVAL));
00547                 return SEFS_FCLIST_TYPE_NONE;
00548         }
00549         return fclist->fclist_type();
00550 }


Variable Documentation

int level
 

Definition at line 87 of file fclist.hh.

int const char* fmt
 

Definition at line 87 of file fclist.hh.