Separate constructing the path to the policy away from systrace_addpolicy() and

into systrace_getpolicyfilename().
This commit is contained in:
elad 2005-08-10 18:19:21 +00:00
parent b0282a1ea0
commit e4088913b5
2 changed files with 18 additions and 11 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: policy.c,v 1.17 2005/06/24 23:21:09 christos Exp $ */
/* $NetBSD: policy.c,v 1.18 2005/08/10 18:19:21 elad Exp $ */
/* $OpenBSD: policy.c,v 1.15 2002/08/07 00:34:17 vincent Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
@ -30,7 +30,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: policy.c,v 1.17 2005/06/24 23:21:09 christos Exp $");
__RCSID("$NetBSD: policy.c,v 1.18 2005/08/10 18:19:21 elad Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -327,24 +327,30 @@ systrace_policyfilename(const char *dirname, const char *name)
return (file);
}
int
systrace_addpolicy(const char *name)
char *
systrace_getpolicyfilename(const char *name)
{
char *file = NULL;
if (userpolicy) {
file = systrace_policyfilename(policydir, name);
/* Check if the user policy file exists */
if (file != NULL && access(file, R_OK) == -1)
file = NULL;
}
/* Read global policy */
if (file == NULL) {
if (file == NULL)
file = systrace_policyfilename(POLICY_PATH, name);
if (file == NULL)
return (-1);
}
return (file);
}
int
systrace_addpolicy(const char *name)
{
char *file = NULL;
if ((file = systrace_getpolicyfilename(name)) == NULL)
return (-1);
return (systrace_readpolicy(file));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: systrace.h,v 1.20 2005/06/25 12:22:43 elad Exp $ */
/* $NetBSD: systrace.h,v 1.21 2005/08/10 18:19:21 elad Exp $ */
/* $OpenBSD: systrace.h,v 1.14 2002/08/05 23:27:53 provos Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
@ -146,6 +146,7 @@ struct policy *systrace_findpolicy(const char *);
struct policy *systrace_findpolnr(int);
int systrace_dumppolicy(void);
int systrace_readpolicy(char *);
char *systrace_getpolicyfilename(const char *);
int systrace_addpolicy(const char *);
struct filterq *systrace_policyflq(struct policy *, const char *, const char *);