aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2015-12-16 14:58:07 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2015-12-16 14:58:07 +0200
commit6bb908898b833ec69c66e918de732af5bad68934 (patch)
treedd715a052f67849d38aedaa25eafa93241e938df
parent9cb7455b12462a3679ed5208540793d802570481 (diff)
downloadpies-6bb908898b833ec69c66e918de732af5bad68934.tar.gz
pies-6bb908898b833ec69c66e918de732af5bad68934.tar.bz2
Implement authentication on control socket.
* Makefile.am (SUBDIRS): Add src. * configure.ac: Check for crypt.h and PAM Build ident/Makefile * grecs: Update. * ident/Makefile.am: New file. * ident/ident.c: New file. * ident/ident.h: New file. * ident/identity.h: New file. * ident/pam.c: New file. * ident/provider.c: New file. * ident/system.c: New file. * lib/Makefile.am: Add arraymember.c * lib/arraymember.c: New file. * lib/libpies.h (is_array_member): New proto. * src/Makefile.am (LDADD): Add libident.a and @PAM_LIBS@ * src/acl.c (acl_entry): Remove groups. Add new members: names and name_match. (pies_acl_create): Deep copy the locus. Set free_entry function for the list. (pies_acl_free): Free locus. (_parse_from): Set free_entry function for the list. (_parse_group): Parse the "user" construct. (parse_acl_line): Deep copy the locus. Allow for null value. (acl_keywords): Update docstrings. (_acl_check): Rewrite identity checks. * src/acl.h (acl_input)<user,groups>: Remove. <identity>: New member. (pies_acl_free): New proto. * src/ctl.c (identity): New global. (cmdtab): New command: auth (ctlio) <addr,addrlen>: New members. (ctlio_create): Start from authenticated state only if no identity_providers are configured. (cmd_auth): New function. (cmd_help): Print only commands that are available in the current state. (ctl_accept): Initialize io->addr and io->addrlen. * src/inetd-bi.c: Change call to check_acl * src/pies.c: Include identity.h (control_keywords): New statement "identity-acl" (pies_keywords): New statement "identity-provider" (config_init): Register identity mechanisms. (config_parse): New function. (config_help): Print help on identity-provider statements. (main): Use config_parse to parse grecs-style configurations. * src/pies.h: Include identity.h (check_acl): Change argument list. All callers changed. (control): Remove acl. Add conn_acl and id_acl instead. * src/progman.c (check_acl): Change argument list. Take identity as the 3rd argument.
-rw-r--r--Makefile.am2
-rw-r--r--configure.ac43
m---------grecs0
-rw-r--r--ident/Makefile.am35
-rw-r--r--ident/ident.c74
-rw-r--r--ident/ident.h51
-rw-r--r--ident/identity.h39
-rw-r--r--ident/pam.c230
-rw-r--r--ident/provider.c161
-rw-r--r--ident/system.c137
-rw-r--r--lib/Makefile.am1
-rw-r--r--lib/arraymember.c33
-rw-r--r--lib/libpies.h2
-rw-r--r--src/Makefile.am5
-rw-r--r--src/acl.c164
-rw-r--r--src/acl.h4
-rw-r--r--src/ctl.c68
-rw-r--r--src/inetd-bi.c2
-rw-r--r--src/pies.c63
-rw-r--r--src/pies.h7
-rw-r--r--src/progman.c10
21 files changed, 1053 insertions, 78 deletions
diff --git a/Makefile.am b/Makefile.am
index 63fdb48..0358e8c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -16,7 +16,7 @@
16 16
17ACLOCAL_AMFLAGS = -I m4 -I am -I grecs/am -I imprimatur 17ACLOCAL_AMFLAGS = -I m4 -I am -I grecs/am -I imprimatur
18 18
19SUBDIRS=gnu grecs lib src imprimatur doc po 19SUBDIRS=gnu grecs lib ident src imprimatur doc po
20 20
21dist-hook: 21dist-hook:
22 @PATCHLEV=`echo "$(PACKAGE_VERSION)" | \ 22 @PATCHLEV=`echo "$(PACKAGE_VERSION)" | \
diff --git a/configure.ac b/configure.ac
index 92ffbbd..8fb1eac 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
1# This file is part of GNU Pies. -*- autoconf -*- 1# This file is part of GNU Pies. -*- autoconf -*-
2# Copyright (C) 2009-2014 Sergey Poznyakoff 2# Copyright (C) 2009-2015 Sergey Poznyakoff
3# 3#
4# GNU Pies is free software; you can redistribute it and/or modify 4# GNU Pies is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by 5# it under the terms of the GNU General Public License as published by
@@ -33,9 +33,12 @@ AC_PROG_YACC
33AC_PROG_LEX 33AC_PROG_LEX
34 34
35# Checks for libraries. 35# Checks for libraries.
36AC_CHECK_LIB(crypt, crypt)
36 37
37# Checks for header files. 38# Checks for header files.
38AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/socket.h sys/time.h syslog.h unistd.h utmp.h utmpx.h]) 39AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdint.h stdlib.h\
40 string.h sys/socket.h sys/time.h syslog.h unistd.h utmp.h utmpx.h\
41 crypt.h shadow.h])
39 42
40# Checks for typedefs, structures, and compiler characteristics. 43# Checks for typedefs, structures, and compiler characteristics.
41AC_TYPE_UID_T 44AC_TYPE_UID_T
@@ -80,6 +83,41 @@ AM_ICONV
80AM_GNU_GETTEXT([external], [need-formatstring-macros]) 83AM_GNU_GETTEXT([external], [need-formatstring-macros])
81AM_GNU_GETTEXT_VERSION([0.18]) 84AM_GNU_GETTEXT_VERSION([0.18])
82 85
86# PAM
87status_pam=maybe
88AC_ARG_ENABLE([pam],
89 AC_HELP_STRING([--enable-pam],
90 [enable PAM]),
91 [
92case "${enableval}" in
93 yes) status_pam=yes ;;
94 no) status_pam=no ;;
95 *) AC_MSG_ERROR([bad value ${enableval} for --enable-pam]) ;;
96esac],[status_pam=maybe])
97
98AC_SUBST(PAM_LIBS,-lpam)
99if test "$status_pam" != "no"; then
100 pam=$status_pam
101 AC_CHECK_HEADERS(security/pam_appl.h)
102 if test "$ac_cv_header_security_pam_appl_h" = "yes"; then
103 AC_CHECK_LIB(dl, dlopen, [PAM_LIBS="$PAM_LIBS -ldl"])
104 AC_CHECK_LIB(pam, pam_start,
105 [status_pam=yes],
106 [status_pam=no], $PAM_LIBS)
107 else
108 status_pam=no
109 fi
110 if test $pam = yes && test $pam != $status_pam; then
111 AC_MSG_ERROR([required module PAM cannot be built because of missing prerequisites])
112 fi
113fi
114
115AM_CONDITIONAL([PAM_COND], [test $status_pam = yes])
116if test $status_pam = yes; then
117 AC_DEFINE_UNQUOTED(WITH_PAM, 1, [PAM support enabled])
118fi
119
120# Build inetd
83AC_ARG_ENABLE([inetd], 121AC_ARG_ENABLE([inetd],
84 AC_HELP_STRING([--enable-inetd], 122 AC_HELP_STRING([--enable-inetd],
85 [build and install a replacement for SBINDIR/inetd]), 123 [build and install a replacement for SBINDIR/inetd]),
@@ -100,6 +138,7 @@ AC_CONFIG_FILES([Makefile
100 gnu/Makefile 138 gnu/Makefile
101 lib/Makefile 139 lib/Makefile
102 src/Makefile 140 src/Makefile
141 ident/Makefile
103 doc/Makefile 142 doc/Makefile
104 po/Makefile.in]) 143 po/Makefile.in])
105AC_OUTPUT 144AC_OUTPUT
diff --git a/grecs b/grecs
Subproject e71c1a855797de245105494a05623753e32844a Subproject 9e978b089268e6bfc4b8fcdf9ef721f6fa92c11
diff --git a/ident/Makefile.am b/ident/Makefile.am
new file mode 100644
index 0000000..65ac145
--- /dev/null
+++ b/ident/Makefile.am
@@ -0,0 +1,35 @@
1# This file is part of GNU Pies.
2# Copyright (C) 2015 Sergey Poznyakoff
3#
4# GNU Pies is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# GNU Pies is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with GNU Pies. If not, see <http://www.gnu.org/licenses/>. */
16
17noinst_LIBRARIES = libident.a
18noinst_HEADERS = ident.h identity.h
19
20libident_a_SOURCES = \
21 provider.c\
22 ident.c\
23 system.c
24
25if PAM_COND
26 libident_a_SOURCES += pam.c
27endif
28
29AM_CPPFLAGS=\
30 -I$(top_srcdir)/lib\
31 -I.\
32 -I$(top_srcdir)/gnu\
33 -I$(top_builddir)/gnu\
34 @GRECS_INCLUDES@
35
diff --git a/ident/ident.c b/ident/ident.c
new file mode 100644
index 0000000..38ae1a8
--- /dev/null
+++ b/ident/ident.c
@@ -0,0 +1,74 @@
1/* This file is part of GNU Pies.
2 Copyright (C) 2015 Sergey Poznyakoff
3
4 GNU Pies is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 GNU Pies is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GNU Pies. If not, see <http://www.gnu.org/licenses/>. */
16
17#include "ident.h"
18
19pies_identity_t
20pies_identity_create (char const *user)
21{
22 pies_identity_t id = xmalloc (sizeof (*id));
23 id->provider = NULL;
24 id->username = xstrdup (user);
25 id->data = NULL;
26 return id;
27}
28
29int
30pies_authenticate (pies_identity_provider_t pr, pies_identity_t id,
31 char const *passwd)
32{
33 if (!pr || !id)
34 return -1;
35
36 if (pr->mech->authenticate (pr, id, passwd) == 0)
37 {
38 id->provider = pr;
39 return 0;
40 }
41 return 1;
42}
43
44int
45pies_identity_is_user (pies_identity_t id, char * const * users)
46{
47 if (!id)
48 return 0;
49 return is_array_member (users, id->username);
50}
51
52int
53pies_identity_is_group_member (pies_identity_t id, char * const * groups)
54{
55 pies_identity_provider_t provider;
56 if (!id)
57 return 0;
58 provider = id->provider;
59 if (!provider)
60 return 0;
61 return provider->mech->is_group_member (provider, id, groups);
62}
63
64void
65pies_identity_destroy (pies_identity_t id)
66{
67 pies_identity_provider_t provider = id->provider;
68 if (provider && provider->mech->destroy_identity)
69 provider->mech->destroy_identity (provider, id);
70 free (id);
71}
72