aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-10-22 23:03:24 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-10-23 00:42:30 +0300
commit21ffba77b92f79a59c62728ede4ad7a4ecb5a0ee (patch)
treec3204285a3ba57d590d815c682f1113b6f48d834
parenteb8797c9a28f3f4e238bad89b56d331492df7828 (diff)
downloadpies-21ffba77b92f79a59c62728ede4ad7a4ecb5a0ee.tar.gz
pies-21ffba77b92f79a59c62728ede4ad7a4ecb5a0ee.tar.bz2
Switch to the latest Grecs.
* Makefile.am (ChangeLog): Use git2chg.awk to build it. * NEWS: Update. * bootstrap.conf (gnulib_modules): Grecs does not depend on gnulib any more. * configure.ac: Version 1.2.90. Define GRECS_HOST_PROJECT_INCLUDES, remove grecs Makefiles from AC_CONFIG_FILES: it is now done by GRECS_SETUP itself. * gnulib.modules (gitlog-to-changelog,argp): Remove. (configmake): New module. * grecs: Update to a52ab6c6. * lib/libpies.h: Remove redefinitions of _() and N_(). * src/Makefile.am: Update for the recent grecs. * src/acl.c: Rewrite using Grecs support for lists and symtabs. * src/acl.h: Likewise. * src/diag.c: Likewise. * src/inetd.c: Likewise. * src/meta1gram.y: Likewise. * src/meta1lex.h: Likewise. * src/meta1lex.l: Likewise. * src/pies.c: Likewise. * src/pies.h: Likewise. * src/progman.c: Likewise. * src/userprivs.c: Likewise.
-rw-r--r--Makefile.am42
-rw-r--r--NEWS8
-rw-r--r--bootstrap.conf9
-rw-r--r--configure.ac9
-rw-r--r--gnulib.modules3
m---------grecs0
-rw-r--r--lib/libpies.h6
-rw-r--r--src/.gitignore1
-rw-r--r--src/Makefile.am17
-rw-r--r--src/acl.c206
-rw-r--r--src/acl.h4
-rw-r--r--src/cmdline.opt193
-rw-r--r--src/diag.c40
-rw-r--r--src/inetd.c18
-rw-r--r--src/meta1gram.y47
-rw-r--r--src/meta1lex.h3
-rw-r--r--src/meta1lex.l55
-rw-r--r--src/pies.c329
-rw-r--r--src/pies.h12
-rw-r--r--src/progman.c86
-rw-r--r--src/userprivs.c49
21 files changed, 562 insertions, 575 deletions
diff --git a/Makefile.am b/Makefile.am
index b3c49a2..de4bf81 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,3 +1,3 @@
1# This file is part of GNU Pies. 1# This file is part of GNU Pies.
2# Copyright (C) 2008, 2009, 2010 Sergey Poznyakoff 2# Copyright (C) 2008, 2009, 2010, 2011 Sergey Poznyakoff
3# 3#
@@ -36,35 +36,17 @@ alphacheck:
36 36
37# Define the following variables in order to use the ChangeLog rule below: 37# Name of the previous ChangeLog file.
38# prev_change_log [optional] Name of the previous ChangeLog file.
39# gen_start_date [optional] Start ChangeLog from this date.
40# changelog_dir [mandatory] Directory where to create ChangeLog
41prev_change_log = ChangeLog.mfd 38prev_change_log = ChangeLog.mfd
39# Start Git ChangeLog from this date.
42gen_start_date = 2009-09-04 40gen_start_date = 2009-09-04
43changelog_dir = .
44 41
45.PHONY: ChangeLog 42.PHONY: ChangeLog
46ChangeLog: 43ChangeLog:
47 @if test -d .git; then \ 44 $(AM_V_GEN)if test -d .git; then \
48 cmd=$(top_srcdir)/build-aux/gitlog-to-changelog; \ 45 git log --pretty='format:%ct %an <%ae>%n%n%s%n%n%b%n' | \
49 if test -n "$(gen_start_date)"; then \ 46 awk -f $(top_srcdir)/@GRECS_SUBDIR@/build-aux/git2chg.awk \
50 cmd="$$cmd --since=\"$(gen_start_date)\""; \ 47 -vsince=\"$(gen_start_date)\" -vappend=\"$(prev_change_log)\" \
51 fi; \ 48 > ChangeLog.tmp; \
52 $$cmd --format='%s%n%n%b%n' | \ 49 cmp ChangeLog ChangeLog.tmp > /dev/null 2>&1 || \
53 sed '/<unknown>$$/d' | fmt -s > $(changelog_dir)/cl-t; \ 50 mv ChangeLog.tmp ChangeLog; \
54 if test -n "$(prev_change_log)" && test -f "$(prev_change_log)"; \ 51 rm -f ChangeLog.tmp; \
55 then \
56 echo "" >> $(changelog_dir)/cl-t; \
57 cat "$(prev_change_log)" | \
58 sed '/^Local Variables:/,/^End:/d' >> $(changelog_dir)/cl-t; \
59 fi; \
60 echo "Local Variables:" >> $(changelog_dir)/cl-t; \
61 echo "mode: change-log" >> $(changelog_dir)/cl-t; \
62 echo "version-control: never" >> $(changelog_dir)/cl-t; \
63 echo "buffer-read-only: t" >> $(changelog_dir)/cl-t; \
64 echo "End:" >> $(changelog_dir)/cl-t; \
65 echo "" >> $(changelog_dir)/cl-t; \
66 sed -n '1,/^[^#]/s/^#//p' $(top_srcdir)/Makefile.am \
67 >> $(changelog_dir)/cl-t; \
68 rm -f $(changelog_dir)/ChangeLog; \
69 mv $(changelog_dir)/cl-t $(changelog_dir)/ChangeLog; \
70 fi 52 fi
diff --git a/NEWS b/NEWS
index d4b2392..9bc6609 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,3 @@
1GNU Pies NEWS -- history of user-visible changes. 2009-12-11 1GNU Pies NEWS -- history of user-visible changes. 2011-10-23
2Copyright (C) 2009, 2010 Sergey Poznyakoff 2Copyright (C) 2009, 2010, 2011 Sergey Poznyakoff
3See the end of file for copying conditions. 3See the end of file for copying conditions.
@@ -8,2 +8,4 @@ Please send Pies bug reports to <bug-pies@gnu.org> or
8 8
9Version 1.2.90 (Git)
10
9Version 1.2, 2009-12-11 11Version 1.2, 2009-12-11
@@ -74,3 +76,3 @@ Copyright information:
74 76
75Copyright (C) 2009 Sergey Poznyakoff 77Copyright (C) 2009, 2010, 2011 Sergey Poznyakoff
76 78
diff --git a/bootstrap.conf b/bootstrap.conf
index 364978b..492aa78 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -1,3 +1,3 @@
1# Bootstrap configuration for GNU Pies. -*- shell-script -*- 1# Bootstrap configuration for GNU Pies. -*- shell-script -*-
2# Copyright (C) 2008, 2009, 2010 Sergey Poznyakoff 2# Copyright (C) 2008, 2009, 2010, 2011 Sergey Poznyakoff
3# 3#
@@ -33,7 +33,8 @@ fi
33# gnulib modules used by this package. 33# gnulib modules used by this package.
34gnulib_modules=`grep -h '^[^#]' gnulib.modules grecs/gnulib.modules | sort | uniq` 34gnulib_modules=`grep -h '^[^#]' gnulib.modules | sort | uniq`
35 35
36NLS_MARKERS="\ 36NLS_MARKERS="\
37 mu_error:1" 37 mu_error:1\
38 38 grecs_error:3\
39 grecs_warning:3"
39 40
diff --git a/configure.ac b/configure.ac
index a8848dd..0c1d2b9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,3 +1,3 @@
1# This file is part of GNU Pies. -*- autoconf -*- 1# This file is part of GNU Pies. -*- autoconf -*-
2# Copyright (C) 2009, 2010 Sergey Poznyakoff 2# Copyright (C) 2009, 2010, 2011 Sergey Poznyakoff
3# 3#
@@ -17,3 +17,3 @@
17AC_PREREQ([2.63]) 17AC_PREREQ([2.63])
18AC_INIT([GNU Pies], [1.2], [bug-pies@gnu.org.ua]) 18AC_INIT([GNU Pies], [1.2.90], [bug-pies@gnu.org.ua])
19AC_CONFIG_SRCDIR([src/pies.h]) 19AC_CONFIG_SRCDIR([src/pies.h])
@@ -59,3 +59,4 @@ gl_INIT
59# Grecs 59# Grecs
60GRECS_SETUP 60GRECS_SETUP([grecs],[tests git2chg getopt])
61GRECS_HOST_PROJECT_INCLUDES='-I$(top_srcdir)/gnu -I$(top_builddir)/gnu'
61 62
@@ -87,4 +88,2 @@ AC_CONFIG_FILES([Makefile
87 gnu/Makefile 88 gnu/Makefile
88 grecs/Makefile
89 grecs/src/Makefile
90 lib/Makefile 89 lib/Makefile
diff --git a/gnulib.modules b/gnulib.modules
index d62e1a3..1e01a93 100644
--- a/gnulib.modules
+++ b/gnulib.modules
@@ -3,8 +3,7 @@
3 3
4argp
5c-ctype 4c-ctype
6c-strcase 5c-strcase
6configmake
7fprintftime 7fprintftime
8gettext 8gettext
9gitlog-to-changelog
10inttostr 9inttostr
diff --git a/grecs b/grecs
Subproject edcc575bcdc9e50bdb79f422ad0f11dc79f3eaa Subproject a52ab6c6c38e1dca047ada4d60249fb323942f0
diff --git a/lib/libpies.h b/lib/libpies.h
index 04910d5..d071846 100644
--- a/lib/libpies.h
+++ b/lib/libpies.h
@@ -1,3 +1,3 @@
1/* This file is part of GNU Pies. 1/* This file is part of GNU Pies.
2 Copyright (C) 2009, 2010 Sergey Poznyakoff 2 Copyright (C) 2009, 2010, 2011 Sergey Poznyakoff
3 3
@@ -21,6 +21,2 @@
21 21
22#define _(String) gettext(String)
23#define N_(String) String
24
25
26#if defined HAVE_SYSCONF && defined _SC_OPEN_MAX 22#if defined HAVE_SYSCONF && defined _SC_OPEN_MAX
diff --git a/src/.gitignore b/src/.gitignore
index 18a7111..4ad4290 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -1 +1,2 @@
1cmdline.h
1inetd 2inetd
diff --git a/src/Makefile.am b/src/Makefile.am
index 19c6483..455b2c2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,3 +1,3 @@
1# This file is part of GNU Pies. 1# This file is part of GNU Pies.
2# Copyright (C) 2008, 2009, 2010 Sergey Poznyakoff 2# Copyright (C) 2008, 2009, 2010, 2011 Sergey Poznyakoff
3# 3#
@@ -37,2 +37,3 @@ noinst_HEADERS = \
37 acl.h\ 37 acl.h\
38 cmdline.h\
38 meta1gram.h\ 39 meta1gram.h\
@@ -43,5 +44,13 @@ meta1lex.c: meta1gram.h
43 44
45BUILT_SOURCES=cmdline.h
46
44incdir=$(pkgdatadir)/$(VERSION)/include 47incdir=$(pkgdatadir)/$(VERSION)/include
45inc_DATA = pp-setup 48inc_DATA = pp-setup
46EXTRA_DIST = pp-setup inetd.in 49EXTRA_DIST = cmdline.opt pp-setup inetd.in
50
51SUFFIXES=.opt .c .h
52.opt.h:
53 $(AM_V_GEN)m4 -s $(top_srcdir)/@GRECS_SUBDIR@/build-aux/getopt.m4 $< > $@
54
55cmdline.h: cmdline.opt
47 56
@@ -51,3 +60,3 @@ INCLUDES = \
51 -I$(top_builddir)/gnu\ 60 -I$(top_builddir)/gnu\
52 -I$(top_srcdir)/grecs/src 61 @GRECS_INCLUDES@
53 62
@@ -55,3 +64,3 @@ LDADD = \
55 ../lib/libpies.a\ 64 ../lib/libpies.a\
56 ../grecs/src/libgrecs.a\ 65 @GRECS_LDADD@\
57 ../gnu/libgnu.a\ 66 ../gnu/libgnu.a\
diff --git a/src/acl.c b/src/acl.c
index a0ee85e..dc459f5 100644
--- a/src/acl.c
+++ b/src/acl.c
@@ -1,3 +1,3 @@
1/* This file is part of GNU Pies 1/* This file is part of GNU Pies
2 Copyright (C) 2009, 2010 Sergey Poznyakoff 2 Copyright (C) 2009, 2010, 2011 Sergey Poznyakoff
3 3
@@ -27,3 +27,2 @@
27#include <netdb.h> 27#include <netdb.h>
28#include <hash.h>
29 28
@@ -42,4 +41,4 @@ struct acl_entry
42 pies_acl_t acl; 41 pies_acl_t acl;
43 gl_list_t groups; 42 struct grecs_list *groups;
44 gl_list_t sockaddrs; 43 struct grecs_list *sockaddrs;
45}; 44};
@@ -50,3 +49,3 @@ struct pies_acl
50 grecs_locus_t locus; 49 grecs_locus_t locus;
51 gl_list_t list; 50 struct grecs_list *list;
52}; 51};
@@ -63,7 +62,3 @@ pies_acl_create (const char *name, grecs_locus_t *locus)
63 acl->locus = *locus; 62 acl->locus = *locus;
64 acl->list = gl_list_create_empty(&gl_linked_list_implementation, 63 acl->list = grecs_list_create ();
65 NULL,
66 NULL,
67 NULL,
68 false);
69 return acl; 64 return acl;
@@ -71,2 +66,10 @@ pies_acl_create (const char *name, grecs_locus_t *locus)
71 66
67void
68pies_acl_free (pies_acl_t acl)
69{
70 free (acl->name);
71 grecs_list_free (acl->list);
72 free (acl);
73}
74
72static struct pies_sockaddr * 75static struct pies_sockaddr *
@@ -191,3 +194,3 @@ _parse_sockaddr (struct acl_entry *entry, const grecs_value_t *value)
191 } 194 }
192 gl_list_add_last (entry->sockaddrs, sptr); 195 grecs_list_append (entry->sockaddrs, sptr);
193 return 0; 196 return 0;
@@ -196,3 +199,3 @@ _parse_sockaddr (struct acl_entry *entry, const grecs_value_t *value)
196static int 199static int
197_parse_from (struct acl_entry *entry, size_t argc, const grecs_value_t *argv) 200_parse_from (struct acl_entry *entry, size_t argc, grecs_value_t **argv)
198{ 201{
@@ -200,3 +203,3 @@ _parse_from (struct acl_entry *entry, size_t argc, const grecs_value_t *argv)
200 return 0; 203 return 0;
201 else if (argv->type == GRECS_TYPE_LIST) 204 else if (argv[0]->type == GRECS_TYPE_LIST)
202 { 205 {
@@ -205,6 +208,6 @@ _parse_from (struct acl_entry *entry, size_t argc, const grecs_value_t *argv)
205 } 208 }
206 else if (strcmp (argv->v.string, "from")) 209 else if (strcmp (argv[0]->v.string, "from"))
207 { 210 {
208 grecs_error (&entry->locus, 0, _("expected `from', but found `%s'"), 211 grecs_error (&entry->locus, 0, _("expected `from', but found `%s'"),
209 argv->v.string); 212 argv[0]->v.string);
210 return 1; 213 return 1;
@@ -221,10 +224,6 @@ _parse_from (struct acl_entry *entry, size_t argc, const grecs_value_t *argv)
221 224
222 entry->sockaddrs = gl_list_create_empty(&gl_linked_list_implementation, 225 entry->sockaddrs = grecs_list_create ();
223 NULL, 226 if (argv[0]->type == GRECS_TYPE_STRING)
224 NULL,
225 NULL,
226 false);
227 if (argv->type == GRECS_TYPE_STRING)
228 { 227 {
229 if (_parse_sockaddr (entry, argv)) 228 if (_parse_sockaddr (entry, argv[0]))
230 return 1; 229 return 1;
@@ -233,8 +232,7 @@ _parse_from (struct acl_entry *entry, size_t argc, const grecs_value_t *argv)
233 { 232 {
234 gl_list_iterator_t itr = gl_list_iterator (argv->v.list);
235 const void *p;
236 int rc = 0; 233 int rc = 0;
237 while (gl_list_iterator_next (&itr, &p, NULL)) 234 struct grecs_list_entry *ep;
238 rc += _parse_sockaddr (entry, (const grecs_value_t*) p); 235
239 gl_list_iterator_free (&itr); 236 for (ep = argv[0]->v.list->head; ep; ep = ep->next)
237 rc += _parse_sockaddr (entry, (const grecs_value_t*) ep->data);
240 if (rc) 238 if (rc)
@@ -252,3 +250,3 @@ _parse_from (struct acl_entry *entry, size_t argc, const grecs_value_t *argv)
252static int 250static int
253_parse_sub_acl (struct acl_entry *entry, size_t argc, grecs_value_t *argv) 251_parse_sub_acl (struct acl_entry *entry, size_t argc, grecs_value_t **argv)
254{ 252{
@@ -256,3 +254,3 @@ _parse_sub_acl (struct acl_entry *entry, size_t argc, grecs_value_t *argv)
256 return 0; 254 return 0;
257 if (strcmp (argv->v.string, "acl") == 0) 255 if (strcmp (argv[0]->v.string, "acl") == 0)
258 { 256 {
@@ -267,3 +265,3 @@ _parse_sub_acl (struct acl_entry *entry, size_t argc, grecs_value_t *argv)
267 265
268 if (argv->type != GRECS_TYPE_STRING) 266 if (argv[0]->type != GRECS_TYPE_STRING)
269 { 267 {
@@ -274,3 +272,3 @@ _parse_sub_acl (struct acl_entry *entry, size_t argc, grecs_value_t *argv)
274 272
275 entry->acl = pies_acl_lookup (argv->v.string); 273 entry->acl = pies_acl_lookup (argv[0]->v.string);
276 274
@@ -279,3 +277,3 @@ _parse_sub_acl (struct acl_entry *entry, size_t argc, grecs_value_t *argv)
279 grecs_error (&entry->locus, 0, _("ACL not defined: `%s'"), 277 grecs_error (&entry->locus, 0, _("ACL not defined: `%s'"),
280 argv->v.string); 278 argv[0]->v.string);
281 return 1; 279 return 1;
@@ -289,5 +287,5 @@ _parse_sub_acl (struct acl_entry *entry, size_t argc, grecs_value_t *argv)
289static int 287static int
290_parse_group (struct acl_entry *entry, size_t argc, grecs_value_t * argv) 288_parse_group (struct acl_entry *entry, size_t argc, grecs_value_t **argv)
291{ 289{
292 if (strcmp (argv->v.string, "group") == 0) 290 if (strcmp (argv[0]->v.string, "group") == 0)
293 { 291 {
@@ -301,13 +299,9 @@ _parse_group (struct acl_entry *entry, size_t argc, grecs_value_t * argv)
301 } 299 }
302 if (argv->type == GRECS_TYPE_STRING) 300 if (argv[0]->type == GRECS_TYPE_STRING)
303 { 301 {
304 entry->groups = gl_list_create_empty(&gl_linked_list_implementation, 302 entry->groups = grecs_list_create ();
305 NULL, 303 grecs_list_append (entry->groups, xstrdup (argv[0]->v.string));
306 NULL,
307 NULL,
308 false);
309 gl_list_add_last (entry->groups, (void *) argv->v.string);
310 } 304 }
311 else 305 else
312 entry->groups = argv->v.list; 306 entry->groups = argv[0]->v.list;
313 argc--; 307 argc--;
@@ -319,7 +313,7 @@ _parse_group (struct acl_entry *entry, size_t argc, grecs_value_t * argv)
319static int 313static int
320_parse_acl (struct acl_entry *entry, size_t argc, grecs_value_t *argv) 314_parse_acl (struct acl_entry *entry, size_t argc, grecs_value_t **argv)
321{ 315{
322 if (assert_grecs_value_type (&entry->locus, argv, GRECS_TYPE_STRING)) 316 if (assert_grecs_value_type (&entry->locus, argv[0], GRECS_TYPE_STRING))
323 return 1; 317 return 1;
324 else if (_parse_token (entry, argv) == 0) 318 else if (_parse_token (entry, argv[0]) == 0)
325 return _parse_sub_acl (entry, argc - 1, argv + 1); 319 return _parse_sub_acl (entry, argc - 1, argv + 1);
@@ -358,3 +352,3 @@ parse_acl_line (grecs_locus_t *locus, int allow, pies_acl_t acl,
358 } 352 }
359 gl_list_add_last (acl->list, entry); 353 grecs_list_append (acl->list, entry);
360 return 0; 354 return 0;
@@ -375,3 +369,2 @@ _acl_common_section_parser (enum grecs_callback_command cmd,
375 pies_acl_t acl; 369 pies_acl_t acl;
376 grecs_locus_t defn_loc;
377 const char *tag = NULL; 370 const char *tag = NULL;
@@ -414,11 +407,4 @@ _acl_common_section_parser (enum grecs_callback_command cmd,
414 acl = pies_acl_create (tag, locus); 407 acl = pies_acl_create (tag, locus);
415 if (tag && pies_acl_install (acl, &defn_loc)) 408 if (tag && (acl = pies_acl_install (acl)) == NULL)
416 { 409 return 1;
417 grecs_error (locus, 0,
418 _("redefinition of ACL %s"),
419 value->v.string);
420 grecs_error (&defn_loc, 0,
421 _("location of the previous definition"));
422 return 1;
423 }
424 if (pacl) 410 if (pacl)
@@ -572,7 +558,6 @@ _acl_check (struct acl_entry *ent, struct acl_input *input)
572 { 558 {
573 const void *p; 559 struct grecs_list_entry *ep;
574 gl_list_iterator_t itr = gl_list_iterator (ent->groups); 560
575 while (result && gl_list_iterator_next (&itr, &p, NULL)) 561 for (ep = ent->groups->head; result && ep; ep = ep->next)
576 result = match_group (input->groups, p); 562 result = match_group (input->groups, ep->data);
577 gl_list_iterator_free (&itr);
578 if (!result) 563 if (!result)
@@ -587,8 +572,8 @@ _acl_check (struct acl_entry *ent, struct acl_input *input)
587 { 572 {
588 const void *p; 573 struct grecs_list_entry *ep;
589 gl_list_iterator_t itr = gl_list_iterator (ent->sockaddrs); 574
590 result = 0; 575 result = 0;
591 while (gl_list_iterator_next (&itr, &p, NULL)) 576 for (ep = ent->sockaddrs->head; ep; ep = ep->next)
592 { 577 {
593 result = _check_sockaddr ((struct pies_sockaddr *)p, input); 578 result = _check_sockaddr ((struct pies_sockaddr *)ep->data, input);
594 if (result) 579 if (result)
@@ -596,3 +581,2 @@ _acl_check (struct acl_entry *ent, struct acl_input *input)
596 } 581 }
597 gl_list_iterator_free (&itr);
598 } 582 }
@@ -606,3 +590,3 @@ _acl_check_cb (struct acl_entry *ent, struct acl_input *input, int *pres)
606 int result = _acl_check (ent, input); 590 int result = _acl_check (ent, input);
607 debug (1, ("%s:%d: %s", ent->locus.file, ent->locus.line, 591 debug (1, ("%s:%d: %s", ent->locus.beg.file, ent->locus.beg.line,
608 /* TRANSLATORS: `MATCHES' is the verb `match' in 2nd person. 592 /* TRANSLATORS: `MATCHES' is the verb `match' in 2nd person.
@@ -624,8 +608,7 @@ pies_acl_check (pies_acl_t acl, struct acl_input *input, int result)
624 { 608 {
625 const void *p; 609 struct grecs_list_entry *ep;
626 gl_list_iterator_t itr = gl_list_iterator (acl->list); 610
627 while (gl_list_iterator_next (&itr, &p, NULL) 611 for (ep = acl->list->head; ep; ep = ep->next)
628 && !_acl_check_cb ((struct acl_entry *)p, input, &result)) 612 if (_acl_check_cb ((struct acl_entry *)ep->data, input, &result))
629 ; 613 break;
630 gl_list_iterator_free (&itr);
631 } 614 }
@@ -637,10 +620,10 @@ pies_acl_check (pies_acl_t acl, struct acl_input *input, int result)
637 620
638static Hash_table *acl_table; 621static struct grecs_symtab *acl_table;
639 622
640/* Calculate the hash of a string. */ 623/* Calculate the hash of a string. */
641static size_t 624static unsigned
642acl_hasher (void const *data, size_t n_buckets) 625acl_hasher (void *data, unsigned long n_buckets)
643{ 626{
644 const struct pies_acl *p = data; 627 const struct pies_acl *p = data;
645 return hash_string (p->name, n_buckets); 628 return grecs_hash_string (p->name, n_buckets);
646} 629}
@@ -648,3 +631,3 @@ acl_hasher (void const *data, size_t n_buckets)
648/* Compare two strings for equality. */ 631/* Compare two strings for equality. */
649static bool 632static int
650acl_compare (void const *data1, void const *data2) 633acl_compare (void const *data1, void const *data2)
@@ -653,23 +636,58 @@ acl_compare (void const *data1, void const *data2)
653 const struct pies_acl *p2 = data2; 636 const struct pies_acl *p2 = data2;
654 return strcasecmp (p1->name, p2->name) == 0; 637 return strcasecmp (p1->name, p2->name);
655} 638}
656 639
657int 640static int
658pies_acl_install (pies_acl_t acl, grecs_locus_t * locus) 641acl_copy (void *a, void *b)
642{
643 const struct pies_acl *pb = b;
644
645 memcpy (a, b, sizeof (struct pies_acl));
646 memset (b, 0, sizeof (struct pies_acl));
647 return 0;
648}
649
650static void
651acl_free_entry (void *p)
652{
653 pies_acl_free (p);
654}
655
656pies_acl_t
657pies_acl_install (pies_acl_t acl)
659{ 658{
660 pies_acl_t ret; 659 pies_acl_t ret;
661 if (!((acl_table 660 int install = 1;
662 || (acl_table = hash_initialize (0, 0, 661
663 acl_hasher, 662 if (!acl_table)
664 acl_compare, 0)))
665 && (ret = hash_insert (acl_table, acl))))
666 xalloc_die ();
667
668 if (ret != acl)
669 { 663 {
670 if (locus) 664 acl_table = grecs_symtab_create(sizeof (struct pies_acl),
671 *locus = ret->locus; 665 acl_hasher,
672 return 1; 666 acl_compare,
667 acl_copy,
668 NULL,
669 acl_free_entry);
670 if (!acl_table)
671 xalloc_die ();
673 } 672 }
674 return 0; 673
674 ret = grecs_symtab_lookup_or_install (acl_table, acl, &install);
675
676 if (!ret)
677 {
678 logmsg (LOG_ERR, _("cannot install acl: %s"), strerror (errno));
679 exit (1);
680 }
681
682 if (!install)
683 {
684 grecs_error (&acl->locus, 0,
685 _("redefinition of ACL %s"),
686 ret->name);
687 grecs_error (&ret->locus, 0,
688 _("location of the previous definition"));
689 ret = NULL;
690 }
691 pies_acl_free (acl);
692 return ret;
675} 693}
@@ -683,3 +701,3 @@ pies_acl_lookup (const char *name)
683 samp.name = (char *) name; 701 samp.name = (char *) name;
684 return hash_lookup (acl_table, &samp); 702 return grecs_symtab_lookup_or_install (acl_table, &samp, NULL);
685} 703}
diff --git a/src/acl.h b/src/acl.h
index 65dcf40..c8e4d07 100644
--- a/src/acl.h
+++ b/src/acl.h
@@ -1,3 +1,3 @@
1/* This file is part of GNU Pies 1/* This file is part of GNU Pies
2 Copyright (C) 2009, 2010 Sergey Poznyakoff 2 Copyright (C) 2009, 2010, 2011 Sergey Poznyakoff
3 3
@@ -32,3 +32,3 @@ int parse_acl_line (grecs_locus_t *locus, int allow, pies_acl_t acl,
32pies_acl_t pies_acl_lookup (const char *name); 32pies_acl_t pies_acl_lookup (const char *name);
33int pies_acl_install (pies_acl_t acl, grecs_locus_t * locus); 33pies_acl_t pies_acl_install (pies_acl_t acl);
34 34
diff --git a/src/cmdline.opt b/src/cmdline.opt
new file mode 100644
index 0000000..31fcf20
--- /dev/null
+++ b/src/cmdline.opt
@@ -0,0 +1,193 @@
1/* This file is part of GNU Pies. -*- c -*-
2 Copyright (C) 2008, 2009, 2010, 2011 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
17OPTIONS_BEGIN("pies",
18 [<process invocation and execution supervisor>],
19 [<>],
20 [<gnu>],
21 [<copyright_year=2011>],
22 [<copyright_holder=Sergey Poznyakoff>])
23
24GROUP(Operation Mode)
25
26OPTION(config-file,c,FILE,
27 [<use FILE instead of the default configuration>])
28BEGIN
29 add_config (current_syntax, optarg);
30END
31
32OPTION(config-help,,,
33 [<show configuration file summary>])
34BEGIN
35 config_help ();
36 exit (0);
37END
38
39OPTION(,E,,
40 [<preprocess config and exit>])
41BEGIN
42 preprocess_only = 1;
43END
44
45OPTION(force,,,
46 [<force startup even if another instance may be running>])
47BEGIN
48 force_option = 1;
49END
50
51OPTION(foreground,,,
52 [<remain in foreground>])
53BEGIN
54 log_to_stderr_only = 1;
55 foreground = 1;
56END
57
58OPTION(inetd,i,,
59 [<run in inetd mode>])
60BEGIN
61 if (!instance)
62 instance = "inetd";
63 current_syntax = CONF_INETD;
64 inetd_mode = 1;
65END
66
67OPTION(instance,,NAME,
68 [<set instance name>])
69BEGIN
70 instance = optarg;
71END
72
73OPTION(rate,,NUMBER,
74 [<set default maximum rate for inetd-style components>])
75BEGIN
76 char *p;
77 default_max_rate = strtoul (optarg, &p, 10);
78 if (*p)
79 {
80 logmsg (LOG_ERR, _("not a number: %s"), optarg);
81 exit (EX_USAGE);
82 }
83END
84
85OPTION(stderr,,,
86 [<log to stderr>])
87BEGIN
88 log_to_stderr_only = 1;
89END
90
91OPTION(syntax,,[<{pies|inetd|meta1}>],
92 [<expect configuration files in the given syntax>])
93BEGIN
94 if (str_to_config_syntax (optarg, &current_syntax))
95 {
96 logmsg (LOG_ERR, _("unknown syntax type: %s"), optarg);
97 exit (EX_USAGE);
98 }
99END
100
101OPTION(syslog,,,
102 [<log to syslog>])
103BEGIN
104 log_to_stderr_only = 0;
105END
106
107OPTION(lint,t,,
108 [<parse configuration file and exit>])
109BEGIN
110 log_to_stderr_only = 1;
111 lint_mode = 1;
112END
113
114GROUP(Preprocessor)
115
116OPTION(define,D,[<NAME[=VALUE]>],
117 [<define a preprocessor symbol NAME as having VALUE or empty>])
118BEGIN
119 add_pp_option ("-D", optarg);
120END
121
122OPTION(undefine,U,NAME,
123 [<undefine a preprocessor symbol NAME>])
124BEGIN
125 add_pp_option ("-U", optarg);
126END
127
128GROUP(Component Management)
129
130OPTION(reload,r,,
131 [<reload the running instance of pies>])
132ALIAS(hup)
133BEGIN
134 log_to_stderr_only = 1;
135 command = COM_RELOAD;
136END
137
138OPTION(restart-component,R,,
139 [<restart components named in the command line>])
140BEGIN
141 log_to_stderr_only = 1;
142 command = COM_RESTART;
143END
144
145OPTION(status,s,,
146 [<display info about the running instance>])
147BEGIN
148 log_to_stderr_only = 1;
149 command = COM_STATUS;
150END
151
152OPTION(stop,S,,
153 [<stop the running instance>])
154BEGIN
155 log_to_stderr_only = 1;
156 command = COM_STOP;
157END
158
159GROUP(Debugging and Additional Diagnostics)
160
161OPTION(dump-depmap,,,
162 [<dump dependency map>])
163BEGIN
164 log_to_stderr_only = 1;
165 command = COM_DUMP_DEPMAP;
166END
167
168OPTION(dump-prereq,,,
169 [<dump prerequisite charts>])
170BEGIN
171 log_to_stderr_only = 1;
172 command = COM_DUMP_PREREQ;
173END
174
175OPTION(source-info,,,
176 [<show source info with debugging messages>])
177BEGIN
178 source_info_option = 1;
179END
180
181OPTION(debug,x,LEVEL,
182 [<set debug verbosity level>])
183BEGIN
184 debug_level = strtoul (optarg, NULL, 0);
185END
186
187OPTIONS_END
188
189void
190parse_options(int argc, char *argv[], int *index)
191{
192 GETOPT(argc, argv, *index)
193}
diff --git a/src/diag.c b/src/diag.c
index 53bc044..fe057d0 100644
--- a/src/diag.c
+++ b/src/diag.c
@@ -1,3 +1,3 @@
1/* This file is part of GNU Pies. 1/* This file is part of GNU Pies.
2 Copyright (C) 2009, 2010 Sergey Poznyakoff 2 Copyright (C) 2009, 2010, 2011 Sergey Poznyakoff
3 3
@@ -127,11 +127,39 @@ grecs_print_diag (grecs_locus_t *locus, int err, int errcode, const char *msg)
127{ 127{
128 char *locstr = NULL;
129
128 if (locus) 130 if (locus)
129 { 131 {
132 size_t size = 0;
133
134 if (locus->beg.col == 0)
135 grecs_asprintf (&locstr, &size, "%s:%u",
136 locus->beg.file,
137 locus->beg.line);
138 else if (strcmp (locus->beg.file, locus->end.file))
139 grecs_asprintf (&locstr, &size, "%s:%u.%u-%s:%u.%u",
140 locus->beg.file,
141 locus->beg.line, locus->beg.col,
142 locus->end.file,
143 locus->end.line, locus->end.col);
144 else if (locus->beg.line != locus->end.line)
145 grecs_asprintf (&locstr, &size, "%s:%u.%u-%u.%u",
146 locus->beg.file,
147 locus->beg.line, locus->beg.col,
148 locus->end.line, locus->end.col);
149 else
150 grecs_asprintf (&locstr, &size, "%s:%u.%u-%u",
151 locus->beg.file,
152 locus->beg.line, locus->beg.col,
153 locus->end.col);
154 }
155
156 if (locstr)
157 {
130 if (errcode) 158 if (errcode)
131 logmsg (err ? LOG_ERR : LOG_WARNING, "%s:%lu: %s: %s", 159 logmsg (err ? LOG_ERR : LOG_WARNING, "%s: %s: %s",
132 locus->file, (unsigned long)locus->line, msg, 160 locstr, msg, strerror (errcode));
133 strerror (errcode));
134 else 161 else
135 logmsg (err ? LOG_ERR : LOG_WARNING, "%s:%lu: %s", 162 logmsg (err ? LOG_ERR : LOG_WARNING, "%s: %s",
136 locus->file, (unsigned long)locus->line, msg); 163 locstr, msg);
164 free (locstr);
137 } 165 }
diff --git a/src/inetd.c b/src/inetd.c
index 012266a..1d7798d 100644
--- a/src/inetd.c
+++ b/src/inetd.c
@@ -1,3 +1,3 @@
1/* This file is part of GNU Pies. 1/* This file is part of GNU Pies.
2 Copyright (C) 2009, 2010 Sergey Poznyakoff 2 Copyright (C) 2009, 2010, 2011 Sergey Poznyakoff
3 3
@@ -30,7 +30,7 @@
30 30
31/* FIXME: Duplicated in grex-lex.l */ 31/* FIXME: Copied from grecs/src/tree.c */
32static void 32static void
33listel_dispose(const void *el) 33listel_dispose(void *el)
34{ 34{
35 free((void*)el); 35 free(el);
36} 36}
@@ -283,9 +283,5 @@ inetd_conf_file (const char *file)
283 { 283 {
284 comp->privs.groups = 284 comp->privs.groups = grecs_list_create ();
285 gl_list_create_empty (&gl_linked_list_implementation, 285 comp->privs.groups->free_entry = listel_dispose;
286 NULL, 286 grecs_list_append (comp->privs.groups, xstrdup (group));
287 NULL,
288 listel_dispose,
289 true);
290 gl_list_add_last (comp->privs.groups, xstrdup (group));
291 } 287 }
diff --git a/src/meta1gram.y b/src/meta1gram.y
index 6256448..deaf382 100644
--- a/src/meta1gram.y
+++ b/src/meta1gram.y
@@ -2,3 +2,3 @@
2/* MeTA1 configuration parser for GNU Pies. 2/* MeTA1 configuration parser for GNU Pies.
3 Copyright (C) 2008, 2009, 2010 Sergey Poznyakoff 3 Copyright (C) 2008, 2009, 2010, 2011 Sergey Poznyakoff
4 4
@@ -22,4 +22,6 @@
22#include "pies.h" 22#include "pies.h"
23#include "grecs-locus.h"
23#include "meta1lex.h" 24#include "meta1lex.h"
24 25#include "meta1gram.h"
26
25#define META1_QUEUE_DIR() \ 27#define META1_QUEUE_DIR() \
@@ -53,3 +55,3 @@ meta1_stmt_create (enum meta1_stmt_type type, const char *ident)
53 p->ident = ident; 55 p->ident = ident;
54 p->locus = meta1_locus; 56 p->locus = meta1lloc;
55 return p; 57 return p;
@@ -86,5 +88,8 @@ static void meta1_translate (struct meta1_stmt *);
86 88
89%error-verbose
90%locations
91
87%union { 92%union {
88 char *string; 93 char *string;
89 gl_list_t list; 94 struct grecs_list *list;
90 grecs_value_t *value; 95 grecs_value_t *value;
@@ -170,9 +175,9 @@ string : META1_IDENT
170 { 175 {
171 const void *p; 176 struct grecs_list_entry *ep;
172 gl_list_iterator_t itr = gl_list_iterator ($1);
173
174 meta1_line_begin (); 177 meta1_line_begin ();
175 while (gl_list_iterator_next (&itr, &p, NULL)) 178 for (ep = $1->head; ep; ep = ep->next)
176 meta1_line_add (p, strlen (p)); 179 {
177 gl_list_iterator_free (&itr); 180 const char *p = ep->data;
181 meta1_line_add (p, strlen (p));
182 }
178 $$ = meta1_line_finish (); 183 $$ = meta1_line_finish ();
@@ -183,8 +188,4 @@ slist : META1_STRING
183 { 188 {
184 $$ = gl_list_create_empty (&gl_linked_list_implementation, 189 $$ = grecs_list_create ();
185 NULL, 190 grecs_list_append ($$, $1);
186 NULL,
187 NULL,
188 true);
189 gl_list_add_last ($$, $1);
190 } 191 }
@@ -192,3 +193,3 @@ slist : META1_STRING
192 { 193 {
193 gl_list_add_last ($1, $2); 194 grecs_list_append ($1, $2);
194 $$ = $1; 195 $$ = $1;
@@ -209,8 +210,4 @@ values : value
209 { 210 {
210 $$ = gl_list_create_empty (&gl_linked_list_implementation, 211 $$ = grecs_list_create ();
211 NULL, 212 grecs_list_append ($$, $1);
212 NULL,
213 NULL,
214 true);
215 gl_list_add_last ($$, $1);
216 } 213 }
@@ -218,3 +215,3 @@ values : value
218 { 215 {
219 gl_list_add_last ($1, $3); 216 grecs_list_append ($1, $3);
220 $$ = $1; 217 $$ = $1;
@@ -231,3 +228,3 @@ yyerror (char *s)
231{ 228{
232 meta1_parse_error ("%s", s); 229 grecs_error (&yylloc, 0, "%s", s);
233 return 0; 230 return 0;
diff --git a/src/meta1lex.h b/src/meta1lex.h
index 0f7c75d..213fb40 100644
--- a/src/meta1lex.h
+++ b/src/meta1lex.h
@@ -1,3 +1,3 @@
1/* This file is part of GNU Pies. 1/* This file is part of GNU Pies.
2 Copyright (C) 2009, 2010, 2009 Sergey Poznyakoff 2 Copyright (C) 2009, 2010, 2011 Sergey Poznyakoff
3 3
@@ -16,3 +16,2 @@
16 16
17extern grecs_locus_t meta1_locus;
18extern size_t meta1_error_count; 17extern size_t meta1_error_count;
diff --git a/src/meta1lex.l b/src/meta1lex.l
index 4eca9e2..7faaf41 100644
--- a/src/meta1lex.l
+++ b/src/meta1lex.l
@@ -3,3 +3,3 @@
3/* MeTA1 configuration lexer for GNU Pies. 3/* MeTA1 configuration lexer for GNU Pies.
4 Copyright (C) 2008, 2009, 2010 Sergey Poznyakoff 4 Copyright (C) 2008, 2009, 2010, 2011 Sergey Poznyakoff
5 5
@@ -28,2 +28,3 @@
28#include "pies.h" 28#include "pies.h"
29#include "grecs-locus.h"
29#include "meta1gram.h" 30#include "meta1gram.h"
@@ -31,4 +32,3 @@
31 32
32grecs_locus_t meta1_locus; 33static struct grecs_locus_point meta1_locus_point;
33size_t meta1_error_count;
34struct obstack meta1_stk; 34struct obstack meta1_stk;
@@ -36,4 +36,15 @@ int meta1_stk_init;
36char *meta1_queue_dir; 36char *meta1_queue_dir;
37
38#define yylval meta1lval 37#define yylval meta1lval
38
39#define YY_USER_ACTION do \
40 { \
41 if (YYSTATE == 0) \
42 { \
43 meta1lloc.beg = meta1_locus_point; \
44 meta1lloc.beg.col++; \
45 } \
46 meta1_locus_point.col += yyleng; \
47 meta1lloc.end = meta1_locus_point; \
48 } \
49 while (0);
39%} 50%}
@@ -47,6 +58,6 @@ X [0-9a-fA-F]
47<COMMENT>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */ 58<COMMENT>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
48<COMMENT>\n ++meta1_locus.line; 59<COMMENT>\n grecs_locus_point_advance_line(meta1_locus_point);
49<COMMENT>"*"+"/" BEGIN (INITIAL); 60<COMMENT>"*"+"/" BEGIN (INITIAL);
50 /* End-of-line comments */ 61 /* End-of-line comments */
51#.*\n { meta1_locus.line++; } 62#.*\n grecs_locus_point_advance_line(meta1_locus_point);
52#.* /* end-of-file comment */; 63#.* /* end-of-file comment */;
@@ -84,3 +95,3 @@ X [0-9a-fA-F]
84<STR>[^\\"\n]*\n { BEGIN (INITIAL); 95<STR>[^\\"\n]*\n { BEGIN (INITIAL);
85 meta1_parse_error (_("newline in a string")); 96 grecs_error (&meta1lloc, 0, _("newline in a string"));
86 meta1_line_add (yytext, yyleng - 1); 97 meta1_line_add (yytext, yyleng - 1);
@@ -90,8 +101,8 @@ X [0-9a-fA-F]
90[ \t\f][ \t\f]* ; 101[ \t\f][ \t\f]* ;
91\n { meta1_locus.line++; } 102\n grecs_locus_point_advance_line(meta1_locus_point);
92[,;{}=] return yytext[0]; 103[,;{}=] return yytext[0];
93. { if (isascii (yytext[0]) && isprint (yytext[0])) 104. { if (isascii (yytext[0]) && isprint (yytext[0]))
94 meta1_parse_error (_("stray character %c"), yytext[0]); 105 grecs_error (&meta1lloc, 0, _("stray character %c"), yytext[0]);
95 else 106 else
96 meta1_parse_error (_("stray character \\%03o"), 107 grecs_error (&meta1lloc, 0, _("stray character \\%03o"),
97 (unsigned char) yytext[0]); } 108 (unsigned char) yytext[0]); }
@@ -137,3 +148,3 @@ unescape_to_line (int c)
137 if (t == c && t != '\\' && t != '\"') 148 if (t == c && t != '\\' && t != '\"')
138 meta1_parse_error (_("unknown escape sequence '\\%c'"), c); 149 grecs_error (&meta1lloc, 0, _("unknown escape sequence '\\%c'"), c);
139 } 150 }
@@ -184,16 +195,2 @@ meta1_string (const char *str, size_t len)
184void 195void
185meta1_parse_error (const char *fmt, ...)
186{
187 va_list ap;
188
189 logmsg_printf (LOG_ERR, "%s:%lu: ", meta1_locus.file,
190 (unsigned long) meta1_locus.line);
191 va_start (ap, fmt);
192 logmsg_vprintf (LOG_ERR, fmt, ap);
193 va_end (ap);
194 logmsg_printf (LOG_ERR, "\n");
195 meta1_error_count++;
196}
197
198void
199meta1_lexer_set_debug () 196meta1_lexer_set_debug ()
@@ -219,4 +216,5 @@ meta1_config_parse (const char *name)
219 } 216 }
220 meta1_locus.file = meta1_string (name, strlen (name)); 217 meta1_locus_point.file = meta1_string (name, strlen (name));
221 meta1_locus.line = 1; 218 meta1_locus_point.line = 1;
219 meta1_locus_point.col = 0;
222 meta1_lexer_set_debug (); 220 meta1_lexer_set_debug ();
@@ -225,5 +223,6 @@ meta1_config_parse (const char *name)
225 yyrestart (fp); 223 yyrestart (fp);
224 grecs_error_count = 0;
226 rc = meta1parse (); 225 rc = meta1parse ();
227 fclose (fp); 226 fclose (fp);
228 if (meta1_error_count) 227 if (grecs_error_count)
229 rc = 1; 228 rc = 1;
diff --git a/src/pies.c b/src/pies.c
index 112bfb6..cc2c26b 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -1,3 +1,3 @@
1/* This file is part of GNU Pies. 1/* This file is part of GNU Pies.
2 Copyright (C) 2008, 2009, 2010 Sergey Poznyakoff 2 Copyright (C) 2008, 2009, 2010, 2011 Sergey Poznyakoff
3 3
@@ -28,3 +28,14 @@ struct pies_privs pies_privs;
28int foreground; 28int foreground;
29int command; 29
30enum pies_command {
31 COM_START,
32 COM_RESTART,
33 COM_RELOAD,
34 COM_STATUS,
35 COM_STOP,
36 COM_DUMP_PREREQ,
37 COM_DUMP_DEPMAP
38};
39
40enum pies_command command;
30char *statedir = DEFAULT_STATE_DIR; 41char *statedir = DEFAULT_STATE_DIR;
@@ -147,5 +158,2 @@ stderr_closed_p ()
147 158
148#define GRECS_VALUE_IS_EMPTY(val) \
149 (!(val) || ((val)->type == GRECS_TYPE_STRING && !(val)->v.string))
150
151int 159int
@@ -154,3 +162,3 @@ assert_grecs_value_type (grecs_locus_t *locus,
154{ 162{
155 if (GRECS_VALUE_IS_EMPTY (value)) 163 if (GRECS_VALUE_EMPTY_P (value))
156 { 164 {
@@ -414,5 +422,5 @@ _get_array_arg (grecs_value_t *val, int num, grecs_locus_t *locus)
414 { 422 {
415 if (assert_grecs_value_type (locus, &val->v.arg.v[num], 423 if (assert_grecs_value_type (locus, val->v.arg.v[num],
416 GRECS_TYPE_STRING) == 0) 424 GRECS_TYPE_STRING) == 0)
417 return val->v.arg.v[num].v.string; 425 return val->v.arg.v[num]->v.string;
418 } 426 }
@@ -424,3 +432,3 @@ _get_list_arg (grecs_value_t *val, int num, grecs_locus_t *locus)
424{ 432{
425 grecs_value_t *elt = (grecs_value_t *) gl_list_get_at (val->v.list, num); 433 grecs_value_t *elt = (grecs_value_t *) grecs_list_index (val->v.list, num);
426 if (!elt) 434 if (!elt)
@@ -447,3 +455,3 @@ return_code_section_parser (enum grecs_callback_command cmd,
447 case grecs_callback_section_begin: 455 case grecs_callback_section_begin:
448 if (GRECS_VALUE_IS_EMPTY (value)) 456 if (GRECS_VALUE_EMPTY_P (value))
449 { 457 {
@@ -465,3 +473,3 @@ return_code_section_parser (enum grecs_callback_command cmd,
465 case GRECS_TYPE_LIST: 473 case GRECS_TYPE_LIST:
466 count = gl_list_size (value->v.list); 474 count = grecs_list_size (value->v.list);
467 act = create_action (comp, locus, value, count, _get_list_arg); 475 act = create_action (comp, locus, value, count, _get_list_arg);
@@ -499,5 +507,5 @@ config_array_to_argv (grecs_value_t *val, grecs_locus_t *locus, size_t *pargc)
499 { 507 {
500 if (assert_grecs_value_type (locus, &val->v.arg.v[i], GRECS_TYPE_STRING) 508 if (assert_grecs_value_type (locus, val->v.arg.v[i], GRECS_TYPE_STRING)
501 == 0) 509 == 0)
502 argv[j++] = xstrdup (val->v.arg.v[i].v.string); 510 argv[j++] = xstrdup (val->v.arg.v[i]->v.string);
503 } 511 }
@@ -704,8 +712,8 @@ _cb_redir (enum grecs_callback_command cmd,
704 case GRECS_TYPE_ARRAY: 712 case GRECS_TYPE_ARRAY:
705 if (assert_grecs_value_type (locus, &value->v.arg.v[0], 713 if (assert_grecs_value_type (locus, value->v.arg.v[0],
706 GRECS_TYPE_STRING)) 714 GRECS_TYPE_STRING))
707 return 0; 715 return 0;
708 if (strtotok (redirtab, value->v.arg.v[0].v.string, &res)) 716 if (strtotok (redirtab, value->v.arg.v[0]->v.string, &res))
709 grecs_error (locus, 0, _("%s: unrecognised redirector type"), 717 grecs_error (locus, 0, _("%s: unrecognised redirector type"),
710 value->v.arg.v[0].v.string); 718 value->v.arg.v[0]->v.string);
711 else 719 else
@@ -719,3 +727,3 @@ _cb_redir (enum grecs_callback_command cmd,
719 } 727 }
720 if (assert_grecs_value_type (locus, &value->v.arg.v[1], 728 if (assert_grecs_value_type (locus, value->v.arg.v[1],
721 GRECS_TYPE_STRING)) 729 GRECS_TYPE_STRING))
@@ -729,3 +737,3 @@ _cb_redir (enum grecs_callback_command cmd,
729 case redir_syslog: 737 case redir_syslog:
730 if (string_to_syslog_priority (value->v.arg.v[1].v.string, 738 if (string_to_syslog_priority (value->v.arg.v[1]->v.string,
731 &rp->v.prio)) 739 &rp->v.prio))
@@ -734,3 +742,3 @@ _cb_redir (enum grecs_callback_command cmd,
734 _("unknown syslog priority `%s'"), 742 _("unknown syslog priority `%s'"),
735 value->v.arg.v[1].v.string); 743 value->v.arg.v[1]->v.string);
736 return 0; 744 return 0;
@@ -740,3 +748,3 @@ _cb_redir (enum grecs_callback_command cmd,
740 case redir_file: 748 case redir_file:
741 rp->v.file = xstrdup (value->v.arg.v[1].v.string); 749 rp->v.file = xstrdup (value->v.arg.v[1]->v.string);
742 break; 750 break;
@@ -912,8 +920,7 @@ _cb_flags (enum grecs_callback_command cmd,
912 { 920 {
913 const void *p; 921 struct grecs_list_entry *ep;
914 gl_list_iterator_t itr = gl_list_iterator (value->v.list); 922
915 923 for (ep = value->v.list->head; ep; ep = ep->next)
916 while (gl_list_iterator_next (&itr, &p, NULL))
917 { 924 {
918 const grecs_value_t *vp = p; 925 const grecs_value_t *vp = ep->data;
919 if (assert_grecs_value_type (locus, vp, GRECS_TYPE_STRING)) 926 if (assert_grecs_value_type (locus, vp, GRECS_TYPE_STRING))
@@ -1562,3 +1569,2 @@ config_init ()
1562{ 1569{
1563 grecs_set_keywords (pies_keywords);
1564 grecs_include_path_setup (DEFAULT_VERSION_INCLUDE_DIR, 1570 grecs_include_path_setup (DEFAULT_VERSION_INCLUDE_DIR,
@@ -1581,215 +1587,10 @@ config_help ()
1581 "For more information, use `info pies configuration'."); 1587 "For more information, use `info pies configuration'.");
1582 grecs_format_docstring (stdout, docstring, 0); 1588 grecs_print_docstring (docstring, 0, stdout);
1583 grecs_format_statement_array (stdout, pies_keywords, 1, 0); 1589 grecs_print_statement_array (pies_keywords, 1, 0, stdout);
1584} 1590}
1585 1591
1586
1587const char *program_version = "pies (" PACKAGE_STRING ")";
1588const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">";
1589static char doc[] = N_("pies -- process invocation and execution supervisor");
1590static char args_doc[] = "";
1591
1592enum
1593{
1594 OPT_FOREGROUND = 256,
1595 OPT_SYNTAX,
1596 OPT_SYSLOG,
1597 OPT_STDERR,
1598 OPT_DUMP_PREREQ,
1599 OPT_DUMP_DEPMAP,
1600 OPT_FORCE,
1601 OPT_CONFIG_HELP,
1602 OPT_SOURCE_INFO,
1603 OPT_RATE,
1604 OPT_INSTANCE
1605};
1606
1607#define OPT_RESTART 'R'
1608#define OPT_RELOAD 'r'
1609#define OPT_STATUS 's'
1610#define OPT_STOP 'S'
1611
1612static struct argp_option options[] = {
1613#define GRP 0
1614 {NULL, 0, NULL, 0, N_("Operation Mode"), GRP},
1615 {"foreground", OPT_FOREGROUND, 0, 0, N_("remain in foreground"), GRP + 1},
1616 {"stderr", OPT_STDERR, NULL, 0, N_("log to stderr"),},
1617 {"syslog", OPT_SYSLOG, NULL, 0, N_("log to syslog"),},
1618 {"force", OPT_FORCE, NULL, 0,
1619 N_("force startup even if another instance may be running"), GRP + 1},
1620 {"lint", 't', NULL, 0,
1621 N_("parse configuration file and exit"), GRP + 1},
1622 {NULL, 'E', NULL, 0,
1623 N_("preprocess config and exit"), GRP + 1},
1624 {"inetd", 'i', NULL, 0,
1625 N_("run in inetd mode"), GRP + 1},
1626 {"config-file", 'c', N_("FILE"), 0,
1627 N_("use FILE instead of the default configuration"), GRP + 1},
1628 {"config-help", OPT_CONFIG_HELP, NULL, 0,
1629 N_("show configuration file summary"), GRP + 1},
1630 {"syntax", OPT_SYNTAX, "{pies|inetd|meta1}", 0,
1631 N_("expect configuration files in the given syntax"), GRP+1 },
1632 {"rate", OPT_RATE, N_("NUMBER"), 0,
1633 N_("set default maximum rate for inetd-style components"),
1634 GRP + 1},
1635 {"instance", OPT_INSTANCE, N_("NAME"), 0,
1636 N_("set instance name"),
1637 GRP + 1},
1638#undef GRP
1639
1640#define GRP 5
1641 {NULL, 0, NULL, 0, N_("Preprocessor"), GRP},
1642 {"define", 'D', N_("NAME[=VALUE]"), 0,
1643 N_("define a preprocessor symbol NAME as having VALUE, or empty"), GRP+1 },
1644 {"undefine", 'U', N_("NAME"), 0,
1645 N_("undefine a preprocessor symbol NAME"), GRP+1 },
1646#undef GRP
1647
1648#define GRP 10
1649 {NULL, 0, NULL, 0, N_("Component Management"), GRP},
1650 {"restart-component", OPT_RESTART, NULL, 0,
1651 N_("restart components named in the command line"), GRP + 1},
1652 {"reload", OPT_RELOAD, NULL, 0,
1653 N_("reload the running instance of pies "), GRP + 1},
1654 {"hup", 0, NULL, OPTION_ALIAS},
1655 {"status", OPT_STATUS, NULL, 0,
1656 N_("display info about the running instance "), GRP + 1},
1657 {"stop", OPT_STOP, NULL, 0,
1658 N_("stop the running instance "), GRP + 1},
1659#undef GRP
1660
1661#define GRP 20
1662 {NULL, 0, NULL, 0, N_("Debugging and Additional Diagnostics"), GRP},
1663 {"debug", 'x', N_("LEVEL"), 0,
1664 N_("set debug verbosity level"), GRP + 1},
1665 {"source-info", OPT_SOURCE_INFO, NULL, 0,
1666 N_("show source info with debugging messages"), GRP + 1},
1667 {"dump-prereq", OPT_DUMP_PREREQ, NULL, 0,
1668 N_("dump prerequisite charts"), GRP + 1},
1669 {"dump-depmap", OPT_DUMP_DEPMAP, NULL, 0,
1670 N_("dump dependency map"), GRP + 1},
1671#undef GRP
1672 {NULL}
1673};
1674
1675static enum config_syntax current_syntax = CONF_PIES; 1592static enum config_syntax current_syntax = CONF_PIES;
1676 1593
1677static error_t 1594#include "cmdline.h"
1678parse_opt (int key, char *arg, struct argp_state *state)
1679{
1680 char *p;
1681
1682 switch (key)
1683 {
1684 case 'c':
1685 add_config (current_syntax, arg);
1686 break;
1687
1688 case 'D':
1689 add_pp_option ("-D", arg);
1690 break;
1691
1692 case 'U':
1693 add_pp_option ("-U", arg);
1694 break;
1695
1696 case 'E':
1697 preprocess_only = 1;
1698 break;
1699
1700 case 'i':
1701 if (!instance)
1702 instance = "inetd";
1703 current_syntax = CONF_INETD;
1704 inetd_mode = 1;
1705 break;
1706
1707 case 't':
1708 log_to_stderr_only = 1;
1709 lint_mode = 1;
1710 break;
1711
1712 case OPT_CONFIG_HELP:
1713 config_help ();
1714 exit (0);
1715
1716 case OPT_FOREGROUND:
1717 log_to_stderr_only = 1;
1718 foreground = 1;
1719 break;
1720
1721 case OPT_INSTANCE:
1722 instance = arg;
1723 break;
1724
1725 case OPT_SYNTAX:
1726 if (str_to_config_syntax (arg, &current_syntax))
1727 {
1728 logmsg (LOG_ERR, _("unknown syntax type: %s"), arg);
1729 exit (EX_USAGE);
1730 }
1731 break;
1732
1733 case OPT_RELOAD:
1734 case OPT_STATUS:
1735 case OPT_STOP:
1736 case OPT_RESTART:
1737 case OPT_DUMP_PREREQ:
1738 case OPT_DUMP_DEPMAP:
1739 log_to_stderr_only = 1;
1740 command = key;
1741 break;
1742
1743 case OPT_SYSLOG:
1744 log_to_stderr_only = 0;
1745 break;
1746
1747 case OPT_STDERR:
1748 log_to_stderr_only = 1;
1749 break;
1750
1751 case 'x':
1752 debug_level = strtoul (arg, NULL, 0);
1753 break;
1754
1755 case OPT_RATE:
1756 default_max_rate = strtoul (arg, &p, 10);
1757 if (*p)
1758 {
1759 logmsg (LOG_ERR, _("not a number: %s"), arg);
1760 exit (EX_USAGE);
1761 }
1762 break;
1763
1764 case OPT_SOURCE_INFO:
1765 source_info_option = 1;
1766 break;
1767
1768 case OPT_FORCE:
1769 force_option = 1;
1770 break;
1771
1772 case ARGP_KEY_INIT:
1773 break;
1774
1775 case ARGP_KEY_FINI:
1776 break;
1777
1778 default:
1779 return ARGP_ERR_UNKNOWN;
1780 }
1781 return 0;
1782}
1783
1784static struct argp argp = {
1785 options,
1786 parse_opt,
1787 args_doc,
1788 doc,
1789 NULL,
1790 NULL,
1791 NULL
1792};
1793 1595
1794
1795#define ACTION_CONT 0 1596#define ACTION_CONT 0
@@ -2158,30 +1959,2 @@ set_mailer_argcv ()
2158 1959
2159const char version_etc_copyright[] =
2160 /* Do *not* mark this string for translation. %s is a copyright
2161 symbol suitable for this locale */
2162 "Copyright %s 2009 Sergey Poznyakoff";
2163
2164
2165static void
2166version (FILE *stream, struct argp_state *state)
2167{
2168 fprintf (stream, "%s (%s) %s\n", PACKAGE, PACKAGE_NAME, PACKAGE_VERSION);
2169 /* TRANSLATORS: Translate "(C)" to the copyright symbol
2170 (C-in-a-circle), if this symbol is available in the user's
2171 locale. Otherwise, do not translate "(C)"; leave it as-is. */
2172 fprintf (stream, version_etc_copyright, _("(C)"));
2173
2174 fputs (_("\
2175\n\
2176License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n\
2177This is free software: you are free to change and redistribute it.\n\
2178There is NO WARRANTY, to the extent permitted by law.\n\
2179\n\
2180"),
2181 stream);
2182
2183 /* TRANSLATORS: %s denotes an author name. */
2184 fprintf (stream, _("Written by %s.\n"), "Sergey Poznyakoff");
2185}
2186
2187static char * 1960static char *
@@ -2250,6 +2023,4 @@ main (int argc, char **argv)
2250 config_init (); 2023 config_init ();
2251 argp_program_version_hook = version; 2024 parse_options (argc, argv, &index);
2252 if (argp_parse (&argp, argc, argv, 0, &index, NULL)) 2025
2253 exit (EX_USAGE);
2254
2255 if (!instance) 2026 if (!instance)
@@ -2291,6 +2062,10 @@ main (int argc, char **argv)
2291 case CONF_PIES: 2062 case CONF_PIES:
2292 if (grecs_parse (file->name)) 2063 {
2293 exit (EX_CONFIG); 2064 struct grecs_node *tree = grecs_parse (file->name);
2294 break; 2065 if (!tree || grecs_tree_process (tree, pies_keywords))
2295 2066 exit (EX_CONFIG);
2067 grecs_tree_free (tree);
2068 break;
2069 }
2070
2296 case CONF_INETD: 2071 case CONF_INETD:
@@ -2319,3 +2094,3 @@ main (int argc, char **argv)
2319 2094
2320 if (argc != index && command != 'R') 2095 if (argc != index && command != COM_RESTART)
2321 { 2096 {
@@ -2328,3 +2103,3 @@ main (int argc, char **argv)
2328 { 2103 {
2329 case OPT_RESTART: 2104 case COM_RESTART:
2330 pies_priv_setup (&pies_privs); 2105 pies_priv_setup (&pies_privs);
@@ -2334,12 +2109,12 @@ main (int argc, char **argv)
2334 2109
2335 case OPT_RELOAD: 2110 case COM_RELOAD:
2336 exit (pies_reload ()); 2111 exit (pies_reload ());
2337 2112
2338 case OPT_STATUS: 2113 case COM_STATUS:
2339 exit (pies_status ()); 2114 exit (pies_status ());
2340 2115
2341 case OPT_STOP: 2116 case COM_STOP:
2342 exit (pies_stop ()); 2117 exit (pies_stop ());
2343 2118
2344 case OPT_DUMP_PREREQ: 2119 case COM_DUMP_PREREQ:
2345 progman_dump_prereq (); 2120 progman_dump_prereq ();
@@ -2347,3 +2122,3 @@ main (int argc, char **argv)
2347 2122
2348 case OPT_DUMP_DEPMAP: 2123 case COM_DUMP_DEPMAP:
2349 progman_dump_depmap (); 2124 progman_dump_depmap ();
diff --git a/src/pies.h b/src/pies.h
index 6be870b..73b0583 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -1,3 +1,3 @@
1/* This file is part of GNU Pies. 1/* This file is part of GNU Pies.
2 Copyright (C) 2008, 2009, 2010 Sergey Poznyakoff 2 Copyright (C) 2008, 2009, 2010, 2011 Sergey Poznyakoff
3 3
@@ -44,3 +44,3 @@
44#include <sysexits.h> 44#include <sysexits.h>
45#include <argp.h> 45#include <ctype.h>
46 46
@@ -119,3 +119,3 @@ struct pies_privs
119 int allgroups; 119 int allgroups;
120 gl_list_t groups; 120 struct grecs_list *groups;
121}; 121};
@@ -168,4 +168,4 @@ struct component
168 char *dir; /* Working directory */ 168 char *dir; /* Working directory */
169 gl_list_t prereq; /* Prerequisites */ 169 struct grecs_list *prereq; /* Prerequisites */
170 gl_list_t depend; /* Dependency targets */ 170 struct grecs_list *depend; /* Dependency targets */
171 int flags; /* CF_ bitmask */ 171 int flags; /* CF_ bitmask */
@@ -377,3 +377,3 @@ char *sockaddr_to_astr (const struct sockaddr *sa, int salen);
377/* userprivs.c */ 377/* userprivs.c */
378int switch_to_privs (uid_t uid, gid_t gid, gl_list_t retain_groups); 378int switch_to_privs (uid_t uid, gid_t gid, struct grecs_list *retain_groups);
379 379
diff --git a/src/progman.c b/src/progman.c
index 4420a21..d24ea1a 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -1,3 +1,3 @@
1/* This file is part of GNU Pies. 1/* This file is part of GNU Pies.
2 Copyright (C) 2007, 2008, 2009, 2010 Sergey Poznyakoff 2 Copyright (C) 2007, 2008, 2009, 2010, 2011 Sergey Poznyakoff
3 3
@@ -17,3 +17,2 @@
17#include "pies.h" 17#include "pies.h"
18#include <hash.h>
19 18
@@ -91,3 +90,3 @@ static pies_depmap_t depmap;
91static int recompute_alarm; 90static int recompute_alarm;
92static Hash_table *conn_tab; 91static struct grecs_symtab *conn_tab;
93 92
@@ -359,6 +358,6 @@ prog_rebuild_prerequisites (struct prog *prog)
359 { 358 {
360 depc = gl_list_size (comp->prereq); 359 depc = grecs_list_size (comp->prereq);
361 if (depc == 1) 360 if (depc == 1)
362 { 361 {
363 const char *item = gl_list_get_at (comp->prereq, 0); 362 const char *item = grecs_list_index (comp->prereq, 0);
364 if (strcmp (item, "all") == 0) 363 if (strcmp (item, "all") == 0)
@@ -372,3 +371,3 @@ prog_rebuild_prerequisites (struct prog *prog)
372 { 371 {
373 gl_list_free (comp->prereq); 372 grecs_list_free (comp->prereq);
374 comp->prereq = NULL; 373 comp->prereq = NULL;
@@ -394,9 +393,6 @@ prog_rebuild_prerequisites (struct prog *prog)
394 { 393 {
395 const void *p; 394 struct grecs_list_entry *ep;
396 gl_list_iterator_t itr = gl_list_iterator (comp->prereq); 395
397 while (gl_list_iterator_next (&itr, &p, NULL)) 396 for (ep = comp->prereq->head; ep; ep = ep->next)
398 { 397 prog->prereq[depc++] = (char*) ep->data;
399 prog->prereq[depc++] = (char*) p;
400 }
401 gl_list_iterator_free (&itr);
402 } 398 }
@@ -523,6 +519,6 @@ open_redirector (struct prog *master, int stream)
523 519
524static size_t 520static unsigned
525conn_class_hasher (void const *data, size_t n_buckets) 521conn_class_hasher (void *data, unsigned long n_buckets)
526{ 522{
527 struct conn_class const *pcclass = data; 523 struct conn_class *pcclass = data;
528 unsigned char const *tag = (unsigned char const *)pcclass->tag; 524 unsigned char const *tag = (unsigned char const *)pcclass->tag;
@@ -544,3 +540,3 @@ conn_class_hasher (void const *data, size_t n_buckets)
544/* Compare two strings for equality. */ 540/* Compare two strings for equality. */
545static bool 541static int
546conn_class_compare (void const *data1, void const *data2) 542conn_class_compare (void const *data1, void const *data2)
@@ -550,5 +546,5 @@ conn_class_compare (void const *data1, void const *data2)
550 546
551 return p1->sa_len == p2->sa_len && 547 return !(p1->sa_len == p2->sa_len &&
552 memcmp (&p1->sa_storage, &p2->sa_storage, p1->sa_len) == 0 && 548 memcmp (&p1->sa_storage, &p2->sa_storage, p1->sa_len) == 0 &&
553 strcmp (p1->tag, p2->tag) == 0; 549 strcmp (p1->tag, p2->tag) == 0);
554} 550}
@@ -561,2 +557,10 @@ conn_class_free (void *data)
561 557
558static int
559conn_class_copy(void *a, void *b)
560{
561 memcpy(a, b, sizeof(struct conn_class));
562 memset(a, 0, sizeof(struct conn_class));
563 return 0;
564}
565
562static struct conn_class * 566static struct conn_class *
@@ -566,2 +570,3 @@ conn_class_lookup (const char *tag,
566{ 570{
571 int install = 1;
567 struct conn_class *probe, *ret; 572 struct conn_class *probe, *ret;
@@ -588,13 +593,16 @@ conn_class_lookup (const char *tag,
588 probe->count = 0; 593 probe->count = 0;
594 if (!conn_tab)
595 {
596 conn_tab = grecs_symtab_create(sizeof (struct conn_class),
597 conn_class_hasher,
598 conn_class_compare,
599 conn_class_copy,
600 NULL,
601 conn_class_free);
602 if (!conn_tab)
603 xalloc_die ();
604 }
589 605
590 if (!((conn_tab 606 ret = grecs_symtab_lookup_or_install (conn_tab, probe, &install);
591 || (conn_tab = hash_initialize (0, 0, 607 free (probe);
592 conn_class_hasher,
593 conn_class_compare,
594 conn_class_free)))
595 && (ret = hash_insert (conn_tab, probe))))
596 xalloc_die ();
597
598 if (probe != ret)
599 free (probe);
600 return ret; 608 return ret;
@@ -1413,4 +1421,3 @@ component_fixup_depend (struct component *comp)
1413{ 1421{
1414 const void *p; 1422 struct grecs_list_entry *ep;
1415 gl_list_iterator_t itr;
1416 1423
@@ -1419,6 +1426,5 @@ component_fixup_depend (struct component *comp)
1419 1426
1420 itr = gl_list_iterator (comp->depend); 1427 for (ep = comp->depend->head; ep; ep = ep->next)
1421 while (gl_list_iterator_next (&itr, &p, NULL))
1422 { 1428 {
1423 const char *tag = p; 1429 const char *tag = ep->data;
1424 struct component *tgt; 1430 struct component *tgt;
@@ -1436,12 +1442,8 @@ component_fixup_depend (struct component *comp)
1436 { 1442 {
1437 tgt->prereq = gl_list_create_empty(&gl_linked_list_implementation, 1443 tgt->prereq = grecs_list_create();
1438 NULL,
1439 NULL,
1440 NULL,
1441 false);
1442 } 1444 }
1443 /* FIXME: memory allocation */ 1445 /* FIXME: memory allocation */
1444 gl_list_add_last (tgt->prereq, xstrdup (comp->tag)); 1446 grecs_list_append (tgt->prereq, xstrdup (comp->tag));
1445 } 1447 }
1446 gl_list_free (comp->depend); 1448 grecs_list_free (comp->depend);
1447 comp->depend = NULL; 1449 comp->depend = NULL;
diff --git a/src/userprivs.c b/src/userprivs.c
index b224a00..3270905 100644
--- a/src/userprivs.c
+++ b/src/userprivs.c
@@ -1,3 +1,3 @@
1/* This file is part of GNU Pies. 1/* This file is part of GNU Pies.
2 Copyright (C) 2007, 2008, 2009, 2010 Sergey Poznyakoff 2 Copyright (C) 2007, 2008, 2009, 2010, 2011 Sergey Poznyakoff
3 3
@@ -40,4 +40,4 @@ str_dispose (const void *elt)
40 40
41gl_list_t 41struct grecs_list *
42get_user_groups (gl_list_t init_list, const char *user) 42get_user_groups (struct grecs_list *init_list, const char *user)
43{ 43{
@@ -45,9 +45,5 @@ get_user_groups (gl_list_t init_list, const char *user)
45 struct group *gr; 45 struct group *gr;
46 gl_list_t list; 46 struct grecs_list *list;
47 47
48 list = gl_list_create_empty(&gl_linked_list_implementation, 48 list = grecs_list_create();
49 str_eq,
50 NULL,
51 str_dispose,
52 false);
53 49
@@ -55,11 +51,8 @@ get_user_groups (gl_list_t init_list, const char *user)
55 { 51 {
56 const void *p; 52 struct grecs_list_entry *ep;
57 gl_list_iterator_t itr = gl_list_iterator (init_list); 53
58 while (gl_list_iterator_next (&itr, &p, NULL)) 54 for (ep = init_list->head; ep; ep = ep->next)
59 { 55 {
60 char *s = xstrdup (p); 56 grecs_list_append (list, xstrdup ((char*)ep->data));
61 if (!gl_list_add_last (list, s))
62 free (s);
63 } 57 }
64 gl_list_iterator_free (&itr);
65 } 58 }
@@ -73,5 +66,3 @@ get_user_groups (gl_list_t init_list, const char *user)
73 { 66 {
74 char *s = xstrdup (gr->gr_name); 67 grecs_list_append (list, xstrdup (gr->gr_name));
75 if (!gl_list_add_last (list, s))
76 free (s);
77 break; 68 break;
@@ -85,3 +76,3 @@ get_user_groups (gl_list_t init_list, const char *user)
85int 76int
86switch_to_privs (uid_t uid, gid_t gid, gl_list_t retain_groups) 77switch_to_privs (uid_t uid, gid_t gid, struct grecs_list *retain_groups)
87{ 78{
@@ -92,3 +83,3 @@ switch_to_privs (uid_t uid, gid_t gid, gl_list_t retain_groups)
92 /* Create a list of supplementary groups */ 83 /* Create a list of supplementary groups */
93 size = 1 + (retain_groups ? gl_list_size (retain_groups) : 0); 84 size = 1 + (retain_groups ? grecs_list_size (retain_groups) : 0);
94 emptygidset = xcalloc (size, sizeof emptygidset[0]); 85 emptygidset = xcalloc (size, sizeof emptygidset[0]);
@@ -98,10 +89,11 @@ switch_to_privs (uid_t uid, gid_t gid, gl_list_t retain_groups)
98 { 89 {
99 const void *p; 90 struct grecs_list_entry *ep;
100 gl_list_iterator_t itr = gl_list_iterator (retain_groups); 91
101 while (gl_list_iterator_next (&itr, &p, NULL)) 92 for (ep = retain_groups->head; ep; ep = ep->next)
102 { 93 {
103 struct group *group = getgrnam ((const char*)p); 94 const char *grname = ep->data;
95 struct group *group = getgrnam (grname);
104 if (!group) 96 if (!group)
105 { 97 {
106 logmsg (LOG_ERR, _("unknown group: %s"), (const char*)p); 98 logmsg (LOG_ERR, _("unknown group: %s"), grname);
107 free (emptygidset); 99 free (emptygidset);
@@ -111,3 +103,2 @@ switch_to_privs (uid_t uid, gid_t gid, gl_list_t retain_groups)
111 } 103 }
112 gl_list_iterator_free (&itr);
113 } 104 }
@@ -211,3 +202,3 @@ pies_priv_setup (struct pies_privs *privs)
211 struct passwd *pw; 202 struct passwd *pw;
212 gl_list_t grplist = 0; 203 struct grecs_list *grplist = 0;
213 204
@@ -229,3 +220,3 @@ pies_priv_setup (struct pies_privs *privs)
229 if (grplist) 220 if (grplist)
230 gl_list_free (grplist); 221 grecs_list_free (grplist);
231} 222}

Return to:

Send suggestions and report system problems to the System administrator.