aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am5
-rw-r--r--src/acl.c128
-rw-r--r--src/acl.h4
-rw-r--r--src/ctl.c64
-rw-r--r--src/inetd-bi.c2
-rw-r--r--src/pies.c61
-rw-r--r--src/pies.h7
-rw-r--r--src/progman.c10
8 files changed, 227 insertions, 54 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 04634c7..ab4546f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -60,15 +60,18 @@ SUFFIXES=.opt .c .h
cmdline.h: cmdline.opt
LDADD = \
+ ../ident/libident.a\
../lib/libpies.a\
@GRECS_LDADD@\
../gnu/libgnu.a\
- $(MF_PROCTITLE_LIBS)
+ $(MF_PROCTITLE_LIBS)\
+ @PAM_LIBS@
pkgstatedir=$(localstatedir)/pies
AM_CPPFLAGS=\
-I$(top_srcdir)/lib\
+ -I$(top_srcdir)/ident\
-I$(top_srcdir)/gnu\
-I$(top_builddir)/gnu\
@GRECS_INCLUDES@\
diff --git a/src/acl.c b/src/acl.c
index 301f56f..fb6adfb 100644
--- a/src/acl.c
+++ b/src/acl.c
@@ -33,13 +33,21 @@ struct pies_sockaddr
struct sockaddr sa;
};
+enum name_match
+ {
+ match_none,
+ match_user_name,
+ match_group_name
+ };
+
struct acl_entry
{
grecs_locus_t locus;
int allow;
int authenticated;
pies_acl_t acl;
- struct grecs_list *groups;
+ enum name_match name_match;
+ char **names;
struct grecs_list *sockaddrs;
};
@@ -53,14 +61,61 @@ struct pies_acl
/* ACL creation */
+void
+grecs_locus_point_copy (struct grecs_locus_point *dst,
+ struct grecs_locus_point *src)
+{
+ dst->file = grecs_strdup (src->file);
+ dst->line = src->line;
+ dst->col = src->col;
+}
+
+void
+grecs_locus_copy (struct grecs_locus *dst, struct grecs_locus *src)
+{
+ grecs_locus_point_copy (&dst->beg, &src->beg);
+ grecs_locus_point_copy (&dst->end, &src->end);
+}
+
+void
+grecs_locus_point_free (struct grecs_locus_point *p)
+{
+ grecs_free (p->file);
+}
+
+void
+grecs_locus_free (struct grecs_locus *loc)
+{
+ grecs_locus_point_free (&loc->beg);
+ grecs_locus_point_free (&loc->end);
+}
+
+static void
+acl_free_entry (void *p)
+{
+ struct acl_entry *ent = p;
+ pies_acl_free (ent->acl);
+ grecs_locus_free (&ent->locus);
+ grecs_list_free (ent->sockaddrs);
+ if (ent->names)
+ {
+ size_t i;
+
+ for (i = 0; ent->names[i]; i++)
+ free (ent->names[i]);
+ free (ent->names);
+ }
+ free (ent);
+}
pies_acl_t
pies_acl_create (const char *name, grecs_locus_t *locus)
{
pies_acl_t acl = xmalloc (sizeof (acl[0]));
acl->name = name ? xstrdup (name) : NULL;
- acl->locus = *locus;
+ grecs_locus_copy (&acl->locus, locus);
acl->list = grecs_list_create ();
+ acl->list->free_entry = acl_free_entry;
return acl;
}
@@ -68,6 +123,7 @@ void
pies_acl_free (pies_acl_t acl)
{
free (acl->name);
+ grecs_locus_free (&acl->locus);
grecs_list_free (acl->list);
free (acl);
}
@@ -196,6 +252,12 @@ _parse_sockaddr (struct acl_entry *entry, const grecs_value_t *value)
return 0;
}
+static void
+sockaddr_free (void *p)
+{
+ free (p);
+}
+
static int
_parse_from (struct acl_entry *entry, size_t argc, grecs_value_t **argv)
{
@@ -223,6 +285,7 @@ _parse_from (struct acl_entry *entry, size_t argc, grecs_value_t **argv)
}
entry->sockaddrs = grecs_list_create ();
+ entry->sockaddrs->free_entry = sockaddr_free;
if (argv[0]->type == GRECS_TYPE_STRING)
{
if (_parse_sockaddr (entry, argv[0]))
@@ -288,22 +351,38 @@ static int
_parse_group (struct acl_entry *entry, size_t argc, grecs_value_t **argv)
{
if (strcmp (argv[0]->v.string, "group") == 0)
+ entry->name_match = match_group_name;
+ else if (strcmp (argv[0]->v.string, "user") == 0)
+ entry->name_match = match_user_name;
+ else
+ entry->name_match = match_none;
+
+ if (entry->name_match != match_none)
{
argc--;
argv++;
if (argc == 0)
{
grecs_error (&entry->locus, 0,
- _("expected group list, but found end of statement"));
+ _("expected identity list, but found end of statement"));
return 1;
}
if (argv[0]->type == GRECS_TYPE_STRING)
{
- entry->groups = grecs_list_create ();
- grecs_list_append (entry->groups, xstrdup (argv[0]->v.string));
+ entry->names = xcalloc (2, sizeof (entry->names[0]));
+ entry->names[0] = xstrdup (argv[0]->v.string);
+ entry->names[1] = NULL;
}
else
- entry->groups = argv[0]->v.list;
+ {
+ size_t i;
+ struct grecs_list_entry *ep;
+ entry->names = xcalloc (argv[0]->v.list->count + 1,
+ sizeof (entry->names[0]));
+ for (i = 0, ep = argv[0]->v.list->head; ep; ep = ep->next, ++i)
+ entry->names[i] = xstrdup (ep->data);
+ entry->names[i] = NULL;
+ }
argc--;
argv++;
}
@@ -327,9 +406,10 @@ parse_acl_line (grecs_locus_t *locus, int allow, pies_acl_t acl,
{
struct acl_entry *entry = xzalloc (sizeof (*entry));
- entry->locus = *locus;
+ grecs_locus_copy (&entry->locus, locus);
entry->allow = allow;
+ if (value)
switch (value->type)
{
case GRECS_TYPE_STRING:
@@ -480,12 +560,12 @@ deny_cb (enum grecs_callback_command cmd,
struct grecs_keyword acl_keywords[] = {
/* TRANSLATORS: only words within angle brackets are translatable */
- { "allow", N_("[all|authenticated|group <grp: list>] [from <addr: list>]"),
+ { "allow", N_("[all|authenticated|user <usr: list>|group <grp: list>] [from <addr: list>]"),
N_("Allow access"),
grecs_type_string, GRECS_MULT, NULL, 0,
allow_cb },
/* TRANSLATORS: only words within angle brackets are translatable */
- { "deny", N_("[all|authenticated|group <grp: list>] [from <addr: list>]"),
+ { "deny", N_("[all|authenticated|user <usr: list>|group <grp: list>] [from <addr: list>]"),
N_("Deny access"),
grecs_type_string, GRECS_MULT, NULL, 0,
deny_cb },
@@ -534,32 +614,30 @@ _check_sockaddr (struct pies_sockaddr *sptr, struct acl_input *input)
}
static int
-match_group (const char **groups, const char *arg)
-{
- for (; *groups; groups++)
- if (strcmp (*groups, arg) == 0)
- return 1;
- return 0;
-}
-
-static int
_acl_check (struct acl_entry *ent, struct acl_input *input)
{
int result = 1;
if (ent->authenticated)
{
- result = input->user != NULL;
+ result = input->identity != NULL;
if (!result)
return result;
}
- if (ent->groups)
+ switch (ent->name_match)
{
- struct grecs_list_entry *ep;
+ case match_none:
+ break;
+
+ case match_user_name:
+ result = pies_identity_is_user (input->identity, ent->names);
+ if (!result)
+ return result;
+ break;
- for (ep = ent->groups->head; result && ep; ep = ep->next)
- result = match_group (input->groups, ep->data);
+ case match_group_name:
+ result = pies_identity_is_group_member (input->identity, ent->names);
if (!result)
return result;
}
@@ -646,7 +724,7 @@ acl_copy (void *a, void *b)
}
static void
-acl_free_entry (void *p)
+acl_free (void *p)
{
pies_acl_free (p);
}
@@ -664,7 +742,7 @@ pies_acl_install (pies_acl_t acl)
acl_compare,
acl_copy,
NULL,
- acl_free_entry);
+ acl_free);
if (!acl_table)
xalloc_die ();
}
diff --git a/src/acl.h b/src/acl.h
index dc09d7b..757104d 100644
--- a/src/acl.h
+++ b/src/acl.h
@@ -21,11 +21,11 @@ struct acl_input
{
struct sockaddr *addr;
socklen_t addrlen;
- const char *user;
- const char **groups;
+ pies_identity_t identity;
};
pies_acl_t pies_acl_create (const char *name, grecs_locus_t *locus);
+void pies_acl_free (pies_acl_t acl);
int pies_acl_check (pies_acl_t acl, struct acl_input *input, int result);
int parse_acl_line (grecs_locus_t *locus, int allow, pies_acl_t acl,
grecs_value_t *value);
diff --git a/src/ctl.c b/src/ctl.c
index f9f2d76..20c16e1 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -17,11 +17,14 @@
#include "pies.h"
#include "prog.h"
#include "xvasprintf.h"
+#include "identity.h"
#define DEFAULT_CONTROL_URL "unix:///tmp/%s.ctl"
struct control control;
+pies_identity_t identity;
+
struct ctlbuf
{
@@ -107,6 +110,7 @@ ctlbuf_chomp (struct ctlbuf *buf)
struct ctlio;
+static void cmd_auth (struct ctlio *, size_t, char **);
static void cmd_quit (struct ctlio *, size_t, char **);
static void cmd_noop (struct ctlio *, size_t, char **);
static void cmd_help (struct ctlio *, size_t, char **);
@@ -129,6 +133,8 @@ struct ctlio_command
};
static struct ctlio_command cmdtab[] = {
+ { "auth", "authenticate",
+ CTL_INITIAL_STATE, 3, 3, cmd_auth },
{ "noop", "no operation",
CTL_ALL_STATES, 1, 1, cmd_noop },
{ "id", "identify the instance",
@@ -167,6 +173,8 @@ ctlio_command_find (char const *verb)
struct ctlio
{
+ union pies_sockaddr_storage addr;
+ socklen_t addrlen;
int state;
int action;
struct ctlbuf ibuf;
@@ -181,7 +189,8 @@ ctlio_create (void)
struct ctlio *io;
io = xmalloc (sizeof (*io));
- io->state = CTL_AUTHENTICATED_STATE; //FIXME CTL_INITIAL_STATE;
+ io->state = identity_provider_list
+ ? CTL_INITIAL_STATE : CTL_AUTHENTICATED_STATE;
io->action = ACTION_CONT;
ctlbuf_init (&io->ibuf);
ctlbuf_init (&io->obuf);
@@ -308,12 +317,56 @@ static void
ctlio_initial_reply (struct ctlio *io)
{
ctlio_printf (io, "220 %s", instance);
- ctlio_printf (io, " <%s>", "foobarbaz");
//FIXME: auth mechanisms
ctlio_eol (io);
}
static void
+cmd_auth (struct ctlio *io, size_t argc, char **argv)
+{
+ struct grecs_list_entry *ep;
+ pies_identity_t id = pies_identity_create (argv[1]);
+ int auth = 0;
+
+ for (ep = identity_provider_list->head; ep; ep = ep->next)
+ {
+ pies_identity_provider_t provider = ep->data;
+ char const *pname = pies_identity_provider_name (provider);
+
+ debug(1, ("trying %s...", pname));
+ if (pies_authenticate (provider, id, argv[2]) == 0)
+ {
+ if (check_acl (control.id_acl,
+ (struct sockaddr *)&io->addr, io->addrlen, id))
+ {
+ logmsg (LOG_AUTH, "%s authenticated via %s, but failed ACL check",
+ argv[1], pname);
+ auth = 0;
+ }
+ else
+ {
+ logmsg (LOG_AUTH, "%s authenticated via %s",
+ argv[1], pname);
+ auth = 1;
+ }
+ break;
+ }
+ }
+
+ if (auth)
+ {
+ ctlio_reply (io, "230", "authentication successful");
+ identity = id;
+ io->state = CTL_AUTHENTICATED_STATE;
+ }
+ else
+ {
+ pies_identity_destroy (id);
+ ctlio_reply (io, "531", "access denied");
+ }
+}
+
+static void
cmd_noop (struct ctlio *io, size_t argc, char **argv)
{
ctlio_reply (io, "220", "%s attending", instance);
@@ -347,9 +400,12 @@ cmd_help (struct ctlio *io, size_t argc, char **argv)
ctlio_reply (io, "113", "help text follows");
for (cp = cmdtab; cp->verb; cp++)
{
+ if (cp->states & io->state)
+ {
ctlio_printf (io, "%-9s%s", cp->verb, cp->descr);
ctlio_eol (io);
}
+ }
ctlio_eot (io);
}
@@ -1000,7 +1056,7 @@ ctl_accept (int socket, void *data)
free (s);
}
- if (check_acl (control.acl, (struct sockaddr *)&addr, addrlen))
+ if (check_acl (control.conn_acl, (struct sockaddr *)&addr, addrlen, NULL))
{
close (fd);
return 1;
@@ -1008,6 +1064,8 @@ ctl_accept (int socket, void *data)
/* FIXME: Check number of connections? */
io = ctlio_create ();
+ io->addr = addr;
+ io->addrlen = addrlen;
ctlio_initial_reply (io);
register_socket (fd, NULL, ctlwr, NULL, io);
diff --git a/src/inetd-bi.c b/src/inetd-bi.c
index e472390..de9cfa0 100644
--- a/src/inetd-bi.c
+++ b/src/inetd-bi.c
@@ -357,7 +357,7 @@ tcpmux (int fd, struct component const *comp)
return;
}
- if (check_acl (comp->acl, (struct sockaddr *) &sa, salen))
+ if (check_acl (comp->acl, (struct sockaddr *) &sa, salen, NULL))
{
fd_report (fd, "-Service not available\r\n");
return;
diff --git a/src/pies.c b/src/pies.c
index 696e9f0..9f5f174 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -18,6 +18,7 @@
#include <locale.h>
#include <configmake.h>
#include "meta1lex.h"
+#include "identity.h"
int preprocess_only; /* Preprocess config, do nothing more */
int lint_mode; /* Test configuration syntax and exit */
@@ -1541,9 +1542,15 @@ struct grecs_keyword control_keywords[] = {
&control.url, 0, _cb_url},
{"acl",
N_("name: string"),
- N_("Set ACL."),
+ N_("Set connection ACL."),
grecs_type_section, GRECS_DFLT,
- &control.acl, 0,
+ &control.conn_acl, 0,
+ acl_section_parser, NULL, acl_keywords},
+ {"identity-acl",
+ N_("name: string"),
+ N_("Set identity ACL."),
+ grecs_type_section, GRECS_DFLT,
+ &control.id_acl, 0,
acl_section_parser, NULL, acl_keywords},
{"idle-timeout",
"n",
@@ -1760,6 +1767,8 @@ struct grecs_keyword pies_keywords[] = {
&mailer_command_line, 0,
NULL
},
+ { "identity-provider", "name: string", "Configure identity provider",
+ grecs_type_section, GRECS_INAC | GRECS_HIDDEN },
{NULL}
};
@@ -1775,6 +1784,39 @@ config_init ()
obstack_grow (&pp_stk, DEFAULT_PREPROCESSOR,
sizeof (DEFAULT_PREPROCESSOR) - 1);
}
+ pies_identity_mechanism_register (&system_identity_mechanism);
+#ifdef WITH_PAM
+ pies_identity_mechanism_register (&pam_identity_mechanism);
+#endif
+}
+
+static void
+config_error ()
+{
+ if (!init_process)
+ exit (EX_CONFIG);
+}
+
+void
+config_parse (char const *name)
+{
+ struct grecs_node *node;
+ struct grecs_node *tree = grecs_parse (name);
+ if (!tree)
+ config_error ();
+
+ for (node = tree; node; node = node->next)
+ {
+ node = grecs_find_node (node, "identity-provider");
+ if (!node)
+ break;
+ pies_config_provider (node);
+ }
+
+ if (grecs_tree_process (tree, pies_keywords))
+ config_error ();
+
+ grecs_tree_free (tree);
}
void
@@ -1786,6 +1828,7 @@ config_help ()
"For more information, use `info pies configuration'.");
grecs_print_docstring (docstring, 0, stdout);
grecs_print_statement_array (pies_keywords, 1, 0, stdout);
+ pies_config_identity_mechanisms_help ();
}
static enum config_syntax current_syntax = CONF_PIES;
@@ -2241,13 +2284,6 @@ set_state_file_names (const char *base)
qotdfile = mkfilename (statedir, base, ".qotd");
}
-static void
-config_error ()
-{
- if (!init_process)
- exit (EX_CONFIG);
-}
-
int
main (int argc, char **argv)
{
@@ -2367,13 +2403,8 @@ main (int argc, char **argv)
switch (file->syntax)
{
case CONF_PIES:
- {
- struct grecs_node *tree = grecs_parse (file->name);
- if (!tree || grecs_tree_process (tree, pies_keywords))
- config_error ();
- grecs_tree_free (tree);
+ config_parse (file->name);
break;
- }
case CONF_INETD:
if (inetd_parse_conf (file->name))
diff --git a/src/pies.h b/src/pies.h
index 82ffddb..3919703 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -58,6 +58,7 @@
#include "quotearg.h"
#include "fprintftime.h"
+#include "identity.h"
#include "acl.h"
#include "libpies.h"
@@ -338,7 +339,8 @@ void progman_iterate_comp (int (*fun) (struct component *, void *),
void fd_report (int fd, const char *msg);
-int check_acl (pies_acl_t acl, struct sockaddr *s, socklen_t salen);
+int check_acl (pies_acl_t acl, struct sockaddr *s, socklen_t salen,
+ pies_identity_t identity);
void log_setup (int want_stderr);
void signal_setup (RETSIGTYPE (*sf)(int));
@@ -561,7 +563,8 @@ void sysvinit_acct (int what, const char *user, const char *id, pid_t pid,
struct control
{
struct pies_url *url;
- pies_acl_t acl;
+ pies_acl_t conn_acl;
+ pies_acl_t id_acl;
unsigned int idle_timeout;
};
diff --git a/src/progman.c b/src/progman.c
index 12969ab..1ec5a8d 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -1301,7 +1301,8 @@ prog_start (struct prog *prog)
}
int
-check_acl (pies_acl_t acl, struct sockaddr *s, socklen_t salen)
+check_acl (pies_acl_t acl, struct sockaddr *s, socklen_t salen,
+ pies_identity_t identity)
{
struct acl_input input;
int rc;
@@ -1311,8 +1312,7 @@ check_acl (pies_acl_t acl, struct sockaddr *s, socklen_t salen)
input.addr = s;
input.addrlen = salen;
- input.user = NULL;
- input.groups = NULL;
+ input.identity = identity;
rc = pies_acl_check (acl, &input, 1);
if (rc == 0)
@@ -1374,8 +1374,8 @@ _prog_accept (struct prog *p)
free (s);
}
- if (check_acl (p->v.p.comp->acl, (struct sockaddr *)&addr, addrlen)
- || check_acl (pies_acl, (struct sockaddr *)&addr, addrlen))
+ if (check_acl (p->v.p.comp->acl, (struct sockaddr *)&addr, addrlen, NULL)
+ || check_acl (pies_acl, (struct sockaddr *)&addr, addrlen, NULL))
{
fd_report (fd, p->v.p.comp->access_denied_message);
close (fd);

Return to:

Send suggestions and report system problems to the System administrator.