aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-02-25 22:12:34 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2009-02-25 22:12:34 +0200
commit27d1256d331d45bf68d96e9a8aa8175df2584978 (patch)
treed4e28ce067fa001b7aff5a470c146a6d04eead96
parentc9178a6fef0184baed0e8456bb6c6d4091b4997c (diff)
downloadwydawca-27d1256d331d45bf68d96e9a8aa8175df2584978.tar.gz
wydawca-27d1256d331d45bf68d96e9a8aa8175df2584978.tar.bz2
Check incoming connections using libwrap; various bugfixes.
* configure.ac: Check for libwrap. * src/tcpwrap.c: New file. * src/Makefile.am (wydawca_SOURCES): Add tcpwrap.c * src/builtin.c, src/job.c, src/pidfile.c: Minor fixes. * src/config.c (assert_string_arg): Change to extern. (wydawca_kw): New block statement "tcp-wrapper" * src/net.c (wydawca_listener): Check fd using libwrap. * src/triplet.c (DECL_EXPAND_TIMER): Add missing return statement.
-rw-r--r--configure.ac20
-rw-r--r--src/Makefile.am1
-rw-r--r--src/builtin.c1
-rw-r--r--src/config.c10
-rw-r--r--src/job.c29
-rw-r--r--src/net.c45
-rw-r--r--src/pidfile.c4
-rw-r--r--src/tcpwrap.c83
-rw-r--r--src/triplet.c2
-rw-r--r--src/wydawca.h9
10 files changed, 172 insertions, 32 deletions
diff --git a/configure.ac b/configure.ac
index 4f6eaa0..737e2dc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -88,6 +88,26 @@ WD_CHECK_LIB([gpgme],[main],[],
88 [/usr/pkg/lib /opt/lib /sw/lib]) 88 [/usr/pkg/lib /opt/lib /sw/lib])
89 89
90# ********************** 90# **********************
91# TCP wrappers
92# **********************
93AC_ARG_WITH(tcp-wrappers,
94 AC_HELP_STRING([--with-tcp-wrappers],
95 [compile with TCP wrappers support (default)]),
96 [status_tcpwrap=${withval}],
97 [status_tcpwrap=yes])
98
99if test "$status_tcpwrap" = yes; then
100 AC_CHECK_LIB(nsl, main)
101 AC_CHECK_LIB(wrap, main,, [status_tcpwrap=no])
102 if test "$status_tcpwrap" = yes; then
103 AC_CHECK_HEADERS(tcpd.h,,[status_tcpwrap=no])
104 fi
105fi
106if test "$status_tcpwrap" = yes; then
107 AC_DEFINE_UNQUOTED([WITH_LIBWRAP],1,[Defined if compiling with libwrap])
108fi
109
110# **********************
91# Preprocessor 111# Preprocessor
92# ********************** 112# **********************
93AC_ARG_WITH([preprocessor], 113AC_ARG_WITH([preprocessor],
diff --git a/src/Makefile.am b/src/Makefile.am
index fcfdb78..c91669e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -34,6 +34,7 @@ wydawca_SOURCES=\
34 process.c\ 34 process.c\
35 sql.c\ 35 sql.c\
36 sql.h\ 36 sql.h\
37 tcpwrap.c\
37 triplet.c\ 38 triplet.c\
38 verify.c\ 39 verify.c\
39 wydawca.c\ 40 wydawca.c\
diff --git a/src/builtin.c b/src/builtin.c
index 90b7c2f..d70a511 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -183,7 +183,6 @@ builtin_run (struct access_method *meth, void *handle, const char *req)
183 for (i = 0; i < meth->parmc; i++) 183 for (i = 0; i < meth->parmc; i++)
184 { 184 {
185 char *pat = meth->parmv[i]; 185 char *pat = meth->parmv[i];
186 char *val;
187 186
188 if (pat[0] == '/') 187 if (pat[0] == '/')
189 { 188 {
diff --git a/src/config.c b/src/config.c
index bab1ed3..b1f339f 100644
--- a/src/config.c
+++ b/src/config.c
@@ -216,7 +216,7 @@ string_to_notification_target (gconf_locus_t *locus, const char *val,
216} 216}
217 217
218 218
219static int 219int
220assert_string_arg (gconf_locus_t *locus, 220assert_string_arg (gconf_locus_t *locus,
221 enum gconf_callback_command cmd, 221 enum gconf_callback_command cmd,
222 const gconf_value_t *value) 222 const gconf_value_t *value)
@@ -1147,7 +1147,6 @@ cb_spool (enum gconf_callback_command cmd,
1147 struct spool *spool; 1147 struct spool *spool;
1148 void **pdata = cb_data; 1148 void **pdata = cb_data;
1149 int rc, ec, i; 1149 int rc, ec, i;
1150 const char *ep = NULL;
1151 1150
1152 switch (cmd) 1151 switch (cmd)
1153 { 1152 {
@@ -1247,6 +1246,13 @@ static struct gconf_keyword wydawca_kw[] = {
1247 1246
1248 { "listen", N_("socket"), N_("Listen on this address"), 1247 { "listen", N_("socket"), N_("Listen on this address"),
1249 gconf_type_sockaddr, &listen_sockaddr, }, 1248 gconf_type_sockaddr, &listen_sockaddr, },
1249
1250#ifdef WITH_LIBWRAP
1251 { "tcp-wrapper", NULL, N_("Configure TCP wrappers"),
1252 gconf_type_section, NULL, 0,
1253 NULL, NULL, tcpwrapper_kw },
1254#endif
1255
1250 { "mailer", N_("url"), N_("Set mailer URL"), 1256 { "mailer", N_("url"), N_("Set mailer URL"),
1251 gconf_type_string, &mailer, 0, cb_mailer }, 1257 gconf_type_string, &mailer, 0, cb_mailer },
1252 { "admin-address", N_("email"), N_("Set admin email address"), 1258 { "admin-address", N_("email"), N_("Set admin email address"),
diff --git a/src/job.c b/src/job.c
index 2c177cb..1baa0af 100644
--- a/src/job.c
+++ b/src/job.c
@@ -99,7 +99,8 @@ job_start (struct job *job)
99 } 99 }
100 100
101 if (debug_level) 101 if (debug_level)
102 logmsg (LOG_DEBUG, _("starting job: %s, %lu"), job->spool->tag, job->uid); 102 logmsg (LOG_DEBUG, _("starting job: %s, %lu"),
103 job->spool->tag, (unsigned long)job->uid);
103 104
104 if (single_process) 105 if (single_process)
105 { 106 {
@@ -113,6 +114,14 @@ job_start (struct job *job)
113 pid = fork (); 114 pid = fork ();
114 if (pid == 0) 115 if (pid == 0)
115 { 116 {
117 int i;
118 signal (SIGHUP, SIG_DFL);
119 signal (SIGTERM, SIG_DFL);
120 signal (SIGQUIT, SIG_DFL);
121 signal (SIGINT, SIG_DFL);
122 signal (SIGCHLD, SIG_DFL);
123 for (i = getdtablesize (); i > 2; i--)
124 close (i);
116 exit (wydawca_scanner (job) ? WYDAWCA_EX_AGAIN : 0); 125 exit (wydawca_scanner (job) ? WYDAWCA_EX_AGAIN : 0);
117 } 126 }
118 else if (pid == -1) 127 else if (pid == -1)
@@ -135,7 +144,8 @@ job_remove (struct job *job)
135 struct job *p; 144 struct job *p;
136 145
137 if (debug_level) 146 if (debug_level)
138 logmsg (LOG_DEBUG, _("removing job: %s, %lu"), job->spool->tag, job->uid); 147 logmsg (LOG_DEBUG, _("removing job: %s, %lu"),
148 job->spool->tag, (unsigned long)job->uid);
139 p = job->prev; 149 p = job->prev;
140 if (p) 150 if (p)
141 p->next = job->next; 151 p->next = job->next;
@@ -169,7 +179,7 @@ job_insert (struct job *job, struct job *elt)
169 p->prev = job; 179 p->prev = job;
170} 180}
171 181
172int 182void
173schedule_job (const struct spool *spool, uid_t uid) 183schedule_job (const struct spool *spool, uid_t uid)
174{ 184{
175 struct job *job; 185 struct job *job;
@@ -178,7 +188,8 @@ schedule_job (const struct spool *spool, uid_t uid)
178 spool = &fake_spool; 188 spool = &fake_spool;
179 189
180 if (debug_level) 190 if (debug_level)
181 logmsg (LOG_DEBUG, _("scheduling job: %s, %lu"), spool->tag, uid); 191 logmsg (LOG_DEBUG, _("scheduling job: %s, %lu"),
192 spool->tag, (unsigned long)uid);
182 193
183 job = job_locate (spool, uid); 194 job = job_locate (spool, uid);
184 if (!job) 195 if (!job)
@@ -230,22 +241,24 @@ print_status (struct job *job, int expect_term)
230 241
231 logmsg (prio, 242 logmsg (prio,
232 _("%lu (%s, %s) terminated on signal %d"), 243 _("%lu (%s, %s) terminated on signal %d"),
233 job->pid, job->spool->tag, pw->pw_name, WTERMSIG (status)); 244 (unsigned long)job->pid, job->spool->tag,
245 pw->pw_name, WTERMSIG (status));
234 } 246 }
235 else if (WIFSTOPPED (status)) 247 else if (WIFSTOPPED (status))
236 logmsg (LOG_NOTICE, 248 logmsg (LOG_NOTICE,
237 _("%lu (%s, %s) stopped on signal %d"), 249 _("%lu (%s, %s) stopped on signal %d"),
238 job->pid, job->spool->tag, pw->pw_name, WSTOPSIG (status)); 250 (unsigned long)job->pid, job->spool->tag,
251 pw->pw_name, WSTOPSIG (status));
239#ifdef WCOREDUMP 252#ifdef WCOREDUMP
240 else if (WCOREDUMP (status)) 253 else if (WCOREDUMP (status))
241 logmsg (LOG_NOTICE, 254 logmsg (LOG_NOTICE,
242 _("%lu (%s, %s) dumped core"), 255 _("%lu (%s, %s) dumped core"),
243 job->pid, job->spool->tag, pw->pw_name); 256 (unsigned long)job->pid, job->spool->tag, pw->pw_name);
244#endif 257#endif
245 else 258 else
246 logmsg (LOG_ERR, 259 logmsg (LOG_ERR,
247 _("%lu (%s, %s) terminated with unrecognized status"), 260 _("%lu (%s, %s) terminated with unrecognized status"),
248 job->pid, job->spool->tag, pw->pw_name); 261 (unsigned long)job->pid, job->spool->tag, pw->pw_name);
249} 262}
250 263
251void 264void
diff --git a/src/net.c b/src/net.c
index 3874827..25bb4da 100644
--- a/src/net.c
+++ b/src/net.c
@@ -52,8 +52,7 @@ open_listener ()
52 /* FIXME: Check permissions? */ 52 /* FIXME: Check permissions? */
53 if (!S_ISSOCK (st.st_mode)) 53 if (!S_ISSOCK (st.st_mode))
54 { 54 {
55 logmsg (LOG_CRIT, _("%s: not a socket"), 55 logmsg (LOG_CRIT, _("%s: not a socket"), s_un->sun_path);
56 s_un->sun_path, strerror (errno));
57 exit (EX_OSFILE); 56 exit (EX_OSFILE);
58 } 57 }
59 unlink (s_un->sun_path); 58 unlink (s_un->sun_path);
@@ -94,17 +93,17 @@ trim_crlf (char *s)
94 s[--len] = 0; 93 s[--len] = 0;
95 } 94 }
96} 95}
97 96
98void 97void
99handle_connection (FILE *fp) 98handle_connection (FILE *in, FILE *out)
100{ 99{
101 char *buf = NULL; 100 char *buf = NULL;
102 size_t buflen = 0; 101 size_t buflen = 0;
103 const struct spool *spool; 102 const struct spool *spool;
104 char *p; 103 char *p;
105 struct passwd *pw; 104 struct passwd *pw;
106 105