summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2012-09-21 10:22:30 +0000
committerEric Faurot <eric@cvs.openbsd.org>2012-09-21 10:22:30 +0000
commitf4052dcf6a490e95d9ba80644c70f44b14b072c7 (patch)
tree91351e80b67b82acc71986cff09f3e65a0c367ca
parent2e1d858eb52f280440e2f9a8249aece7ef578bf4 (diff)
Move ruleset_match() prototype to smtpd.h and make the envelope const.
Adapt a lot of functions in chain to use const args where required. ok gilles@
-rw-r--r--usr.sbin/smtpd/lka.c3
-rw-r--r--usr.sbin/smtpd/lka_session.c3
-rw-r--r--usr.sbin/smtpd/map.c8
-rw-r--r--usr.sbin/smtpd/map_db.c42
-rw-r--r--usr.sbin/smtpd/map_static.c30
-rw-r--r--usr.sbin/smtpd/map_stdio.c34
-rw-r--r--usr.sbin/smtpd/ruleset.c16
-rw-r--r--usr.sbin/smtpd/smtpd.h25
-rw-r--r--usr.sbin/smtpd/util.c28
9 files changed, 98 insertions, 91 deletions
diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c
index f444933d6f4..19ac5df8b79 100644
--- a/usr.sbin/smtpd/lka.c
+++ b/usr.sbin/smtpd/lka.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lka.c,v 1.139 2012/09/19 19:40:36 eric Exp $ */
+/* $OpenBSD: lka.c,v 1.140 2012/09/21 10:22:29 eric Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -42,7 +42,6 @@
#include "smtpd.h"
#include "log.h"
-struct rule *ruleset_match(struct envelope *);
static void lka_imsg(struct imsgev *, struct imsg *);
static void lka_shutdown(void);
static void lka_sig_handler(int, short, void *);
diff --git a/usr.sbin/smtpd/lka_session.c b/usr.sbin/smtpd/lka_session.c
index b26fbfdf987..0c88fa307d0 100644
--- a/usr.sbin/smtpd/lka_session.c
+++ b/usr.sbin/smtpd/lka_session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lka_session.c,v 1.29 2012/09/19 10:10:30 eric Exp $ */
+/* $OpenBSD: lka_session.c,v 1.30 2012/09/21 10:22:29 eric Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -51,7 +51,6 @@ static void lka_session_request_forwardfile(struct lka_session *,
static void lka_session_deliver(struct lka_session *, struct envelope *);
static int lka_session_resolve_node(struct envelope *, struct expandnode *);
static int lka_session_rcpt_action(struct envelope *);
-struct rule *ruleset_match(struct envelope *);
static struct tree sessions = SPLAY_INITIALIZER(&sessions);
diff --git a/usr.sbin/smtpd/map.c b/usr.sbin/smtpd/map.c
index 57497954fd2..e2937848535 100644
--- a/usr.sbin/smtpd/map.c
+++ b/usr.sbin/smtpd/map.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: map.c,v 1.29 2012/09/17 20:19:18 eric Exp $ */
+/* $OpenBSD: map.c,v 1.30 2012/09/21 10:22:29 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -89,7 +89,7 @@ map_find(objid_t id)
}
void *
-map_lookup(objid_t mapid, char *key, enum map_kind kind)
+map_lookup(objid_t mapid, const char *key, enum map_kind kind)
{
void *hdl = NULL;
char *ret = NULL;
@@ -114,8 +114,8 @@ map_lookup(objid_t mapid, char *key, enum map_kind kind)
}
int
-map_compare(objid_t mapid, char *key, enum map_kind kind,
- int (*func)(char *, char *))
+map_compare(objid_t mapid, const char *key, enum map_kind kind,
+ int (*func)(const char *, const char *))
{
void *hdl = NULL;
struct map *map;
diff --git a/usr.sbin/smtpd/map_db.c b/usr.sbin/smtpd/map_db.c
index 9daccbf97d6..077f4c6c264 100644
--- a/usr.sbin/smtpd/map_db.c
+++ b/usr.sbin/smtpd/map_db.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: map_db.c,v 1.7 2012/09/19 12:59:59 eric Exp $ */
+/* $OpenBSD: map_db.c,v 1.8 2012/09/21 10:22:29 eric Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -38,16 +38,16 @@
/* db(3) backend */
static void *map_db_open(struct map *);
-static void *map_db_lookup(void *, char *, enum map_kind);
-static int map_db_compare(void *, char *, enum map_kind,
- int (*)(char *, char *));
+static void *map_db_lookup(void *, const char *, enum map_kind);
+static int map_db_compare(void *, const char *, enum map_kind,
+ int (*)(const char *, const char *));
static void map_db_close(void *);
-static char *map_db_get_entry(void *, char *, size_t *);
-static void *map_db_credentials(char *, char *, size_t);
-static void *map_db_alias(char *, char *, size_t);
-static void *map_db_virtual(char *, char *, size_t);
-static void *map_db_netaddr(char *, char *, size_t);
+static char *map_db_get_entry(void *, const char *, size_t *);
+static void *map_db_credentials(const char *, char *, size_t);
+static void *map_db_alias(const char *, char *, size_t);
+static void *map_db_virtual(const char *, char *, size_t);
+static void *map_db_netaddr(const char *, char *, size_t);
struct map_backend map_backend_db = {
@@ -73,7 +73,7 @@ map_db_close(void *hdl)
}
static void *
-map_db_lookup(void *hdl, char *key, enum map_kind kind)
+map_db_lookup(void *hdl, const char *key, enum map_kind kind)
{
char *line;
size_t len;
@@ -111,8 +111,8 @@ map_db_lookup(void *hdl, char *key, enum map_kind kind)
}
static int
-map_db_compare(void *hdl, char *key, enum map_kind kind,
- int (*func)(char *, char *))
+map_db_compare(void *hdl, const char *key, enum map_kind kind,
+ int (*func)(const char *, const char *))
{
int ret = 0;
DB *db = hdl;
@@ -138,16 +138,20 @@ map_db_compare(void *hdl, char *key, enum map_kind kind,
}
static char *
-map_db_get_entry(void *hdl, char *key, size_t *len)
+map_db_get_entry(void *hdl, const char *key, size_t *len)
{
int ret;
DBT dbk;
DBT dbv;
DB *db = hdl;
char *result = NULL;
+ char pkey[MAX_LINE_SIZE];
- dbk.data = key;
- dbk.size = strlen(dbk.data) + 1;
+ /* workaround the stupidity of the DB interface */
+ if (strlcpy(pkey, key, sizeof pkey) >= sizeof pkey)
+ errx(1, "map_db_get_entry: key too long");
+ dbk.data = pkey;
+ dbk.size = strlen(pkey) + 1;
if ((ret = db->get(db, &dbk, &dbv, 0)) != 0)
return NULL;
@@ -163,7 +167,7 @@ map_db_get_entry(void *hdl, char *key, size_t *len)
}
static void *
-map_db_credentials(char *key, char *line, size_t len)
+map_db_credentials(const char *key, char *line, size_t len)
{
struct map_credentials *map_credentials = NULL;
char *p;
@@ -206,7 +210,7 @@ err:
}
static void *
-map_db_alias(char *key, char *line, size_t len)
+map_db_alias(const char *key, char *line, size_t len)
{
char *subrcpt;
char *endp;
@@ -246,7 +250,7 @@ error:
}
static void *
-map_db_virtual(char *key, char *line, size_t len)
+map_db_virtual(const char *key, char *line, size_t len)
{
char *subrcpt;
char *endp;
@@ -291,7 +295,7 @@ error:
static void *
-map_db_netaddr(char *key, char *line, size_t len)
+map_db_netaddr(const char *key, char *line, size_t len)
{
struct map_netaddr *map_netaddr = NULL;
diff --git a/usr.sbin/smtpd/map_static.c b/usr.sbin/smtpd/map_static.c
index 759198a4998..f5178fc240c 100644
--- a/usr.sbin/smtpd/map_static.c
+++ b/usr.sbin/smtpd/map_static.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: map_static.c,v 1.4 2012/09/19 12:59:59 eric Exp $ */
+/* $OpenBSD: map_static.c,v 1.5 2012/09/21 10:22:29 eric Exp $ */
/*
* Copyright (c) 2012 Gilles Chehade <gilles@openbsd.org>
@@ -37,15 +37,15 @@
/* static backend */
static void *map_static_open(struct map *);
-static void *map_static_lookup(void *, char *, enum map_kind);
-static int map_static_compare(void *, char *, enum map_kind,
- int (*)(char *, char *));
+static void *map_static_lookup(void *, const char *, enum map_kind);
+static int map_static_compare(void *, const char *, enum map_kind,
+ int (*)(const char *, const char *));
static void map_static_close(void *);
-static void *map_static_credentials(char *, char *, size_t);
-static void *map_static_alias(char *, char *, size_t);
-static void *map_static_virtual(char *, char *, size_t);
-static void *map_static_netaddr(char *, char *, size_t);
+static void *map_static_credentials(const char *, char *, size_t);
+static void *map_static_alias(const char *, char *, size_t);
+static void *map_static_virtual(const char *, char *, size_t);
+static void *map_static_netaddr(const char *, char *, size_t);
struct map_backend map_backend_static = {
map_static_open,
@@ -67,7 +67,7 @@ map_static_close(void *hdl)
}
static void *
-map_static_lookup(void *hdl, char *key, enum map_kind kind)
+map_static_lookup(void *hdl, const char *key, enum map_kind kind)
{
struct map *m = hdl;
struct mapel *me = NULL;
@@ -117,8 +117,8 @@ map_static_lookup(void *hdl, char *key, enum map_kind kind)
}
static int
-map_static_compare(void *hdl, char *key, enum map_kind kind,
- int (*func)(char *, char *))
+map_static_compare(void *hdl, const char *key, enum map_kind kind,
+ int (*func)(const char *, const char *))
{
struct map *m = hdl;
struct mapel *me = NULL;
@@ -135,7 +135,7 @@ map_static_compare(void *hdl, char *key, enum map_kind kind,
}
static void *
-map_static_credentials(char *key, char *line, size_t len)
+map_static_credentials(const char *key, char *line, size_t len)
{
struct map_credentials *map_credentials = NULL;
char *p;
@@ -178,7 +178,7 @@ err:
}
static void *
-map_static_alias(char *key, char *line, size_t len)
+map_static_alias(const char *key, char *line, size_t len)
{
char *subrcpt;
char *endp;
@@ -218,7 +218,7 @@ error:
}
static void *
-map_static_virtual(char *key, char *line, size_t len)
+map_static_virtual(const char *key, char *line, size_t len)
{
char *subrcpt;
char *endp;
@@ -263,7 +263,7 @@ error:
static void *
-map_static_netaddr(char *key, char *line, size_t len)
+map_static_netaddr(const char *key, char *line, size_t len)
{
struct map_netaddr *map_netaddr = NULL;
diff --git a/usr.sbin/smtpd/map_stdio.c b/usr.sbin/smtpd/map_stdio.c
index 770dac50b15..ef6f37ee3f2 100644
--- a/usr.sbin/smtpd/map_stdio.c
+++ b/usr.sbin/smtpd/map_stdio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: map_stdio.c,v 1.7 2012/09/19 12:59:59 eric Exp $ */
+/* $OpenBSD: map_stdio.c,v 1.8 2012/09/21 10:22:29 eric Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -37,16 +37,16 @@
/* stdio(3) backend */
static void *map_stdio_open(struct map *);
-static void *map_stdio_lookup(void *, char *, enum map_kind);
-static int map_stdio_compare(void *, char *, enum map_kind,
- int (*)(char *, char *));
+static void *map_stdio_lookup(void *, const char *, enum map_kind);
+static int map_stdio_compare(void *, const char *, enum map_kind,
+ int (*)(const char *, const char *));
static void map_stdio_close(void *);
-static char *map_stdio_get_entry(void *, char *, size_t *);
-static void *map_stdio_credentials(char *, char *, size_t);
-static void *map_stdio_alias(char *, char *, size_t);
-static void *map_stdio_virtual(char *, char *, size_t);
-static void *map_stdio_netaddr(char *, char *, size_t);
+static char *map_stdio_get_entry(void *, const char *, size_t *);
+static void *map_stdio_credentials(const char *, char *, size_t);
+static void *map_stdio_alias(const char *, char *, size_t);
+static void *map_stdio_virtual(const char *, char *, size_t);
+static void *map_stdio_netaddr(const char *, char *, size_t);
struct map_backend map_backend_stdio = {
@@ -72,7 +72,7 @@ map_stdio_close(void *hdl)
}
static void *
-map_stdio_lookup(void *hdl, char *key, enum map_kind kind)
+map_stdio_lookup(void *hdl, const char *key, enum map_kind kind)
{
char *line;
size_t len;
@@ -110,8 +110,8 @@ map_stdio_lookup(void *hdl, char *key, enum map_kind kind)
}
static int
-map_stdio_compare(void *hdl, char *key, enum map_kind kind,
- int (*func)(char *, char *))
+map_stdio_compare(void *hdl, const char *key, enum map_kind kind,
+ int (*func)(const char *, const char *))
{
char *buf, *lbuf;
size_t flen;
@@ -149,7 +149,7 @@ map_stdio_compare(void *hdl, char *key, enum map_kind kind,
}
static char *
-map_stdio_get_entry(void *hdl, char *key, size_t *len)
+map_stdio_get_entry(void *hdl, const char *key, size_t *len)
{
char *buf, *lbuf;
size_t flen;
@@ -198,7 +198,7 @@ map_stdio_get_entry(void *hdl, char *key, size_t *len)
static void *
-map_stdio_credentials(char *key, char *line, size_t len)
+map_stdio_credentials(const char *key, char *line, size_t len)
{
struct map_credentials *map_credentials = NULL;
char *p;
@@ -241,7 +241,7 @@ err:
}
static void *
-map_stdio_alias(char *key, char *line, size_t len)
+map_stdio_alias(const char *key, char *line, size_t len)
{
char *subrcpt;
char *endp;
@@ -281,7 +281,7 @@ error:
}
static void *
-map_stdio_virtual(char *key, char *line, size_t len)
+map_stdio_virtual(const char *key, char *line, size_t len)
{
char *subrcpt;
char *endp;
@@ -325,7 +325,7 @@ error:
}
static void *
-map_stdio_netaddr(char *key, char *line, size_t len)
+map_stdio_netaddr(const char *key, char *line, size_t len)
{
struct map_netaddr *map_netaddr = NULL;
diff --git a/usr.sbin/smtpd/ruleset.c b/usr.sbin/smtpd/ruleset.c
index 051151a7bea..8bd96dc914f 100644
--- a/usr.sbin/smtpd/ruleset.c
+++ b/usr.sbin/smtpd/ruleset.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ruleset.c,v 1.22 2012/09/15 15:12:11 eric Exp $ */
+/* $OpenBSD: ruleset.c,v 1.23 2012/09/21 10:22:29 eric Exp $ */
/*
* Copyright (c) 2009 Gilles Chehade <gilles@openbsd.org>
@@ -33,22 +33,20 @@
#include "log.h"
-struct rule *ruleset_match(struct envelope *);
-
-static int ruleset_check_source(struct map *, struct sockaddr_storage *);
+static int ruleset_check_source(struct map *, const struct sockaddr_storage *);
static int ruleset_match_mask(struct sockaddr_storage *, struct netaddr *);
static int ruleset_inet4_match(struct sockaddr_in *, struct netaddr *);
static int ruleset_inet6_match(struct sockaddr_in6 *, struct netaddr *);
struct rule *
-ruleset_match(struct envelope *evp)
+ruleset_match(const struct envelope *evp)
{
struct rule *r;
struct map *map;
struct mapel *me;
- struct mailaddr *maddr = &evp->dest;
- struct sockaddr_storage *ss = &evp->ss;
+ const struct mailaddr *maddr = &evp->dest;
+ const struct sockaddr_storage *ss = &evp->ss;
if (evp->flags & DF_INTERNAL)
ss = NULL;
@@ -95,7 +93,7 @@ ruleset_match(struct envelope *evp)
}
static int
-ruleset_cmp_source(char *s1, char *s2)
+ruleset_cmp_source(const char *s1, const char *s2)
{
struct netaddr n1;
struct netaddr n2;
@@ -115,7 +113,7 @@ ruleset_cmp_source(char *s1, char *s2)
}
static int
-ruleset_check_source(struct map *map, struct sockaddr_storage *ss)
+ruleset_check_source(struct map *map, const struct sockaddr_storage *ss)
{
struct mapel *me;
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 81d49d4f550..c2b55f48b81 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.361 2012/09/20 14:28:57 eric Exp $ */
+/* $OpenBSD: smtpd.h,v 1.362 2012/09/21 10:22:29 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -276,8 +276,9 @@ struct map {
struct map_backend {
void *(*open)(struct map *);
void (*close)(void *);
- void *(*lookup)(void *, char *, enum map_kind);
- int (*compare)(void *, char *, enum map_kind, int (*)(char *, char *));
+ void *(*lookup)(void *, const char *, enum map_kind);
+ int (*compare)(void *, const char *, enum map_kind,
+ int (*)(const char *, const char *));
};
@@ -1006,8 +1007,9 @@ void lka_session(struct submit_status *);
void lka_session_forward_reply(struct forward_req *, int);
/* map.c */
-void *map_lookup(objid_t, char *, enum map_kind);
-int map_compare(objid_t, char *, enum map_kind, int (*)(char *, char *));
+void *map_lookup(objid_t, const char *, enum map_kind);
+int map_compare(objid_t, const char *, enum map_kind,
+ int (*)(const char *, const char *));
struct map *map_find(objid_t);
struct map *map_findbyname(const char *);
struct map *map_create(enum map_kind, const char *);
@@ -1072,6 +1074,11 @@ int uncompress_file(FILE *, FILE *);
size_t compress_buffer(char *, size_t, char *, size_t);
size_t uncompress_buffer(char *, size_t, char *, size_t);
+
+/* ruleset.c */
+struct rule *ruleset_match(const struct envelope *);
+
+
/* scheduler.c */
pid_t scheduler(void);
@@ -1169,11 +1176,11 @@ int bsnprintf(char *, size_t, const char *, ...)
__attribute__ ((format (printf, 3, 4)));
int mkdirs(char *, mode_t);
int safe_fclose(FILE *);
-int hostname_match(char *, char *);
+int hostname_match(const char *, const char *);
int email_to_mailaddr(struct mailaddr *, char *);
int valid_localpart(const char *);
int valid_domainpart(const char *);
-char *ss_to_text(struct sockaddr_storage *);
+char *ss_to_text(const struct sockaddr_storage *);
char *time_to_text(time_t);
char *duration_to_text(time_t);
int secure_file(int, char *, char *, uid_t, int);
@@ -1190,8 +1197,8 @@ int rmtree(char *, int);
int mvpurge(char *, char *);
int mktmpfile(void);
const char *parse_smtp_response(char *, size_t, char **, int *);
-int text_to_netaddr(struct netaddr *, char *);
-int text_to_relayhost(struct relayhost *, char *);
+int text_to_netaddr(struct netaddr *, const char *);
+int text_to_relayhost(struct relayhost *, const char *);
void *xmalloc(size_t, const char *);
void *xcalloc(size_t, size_t, const char *);
char *xstrdup(const char *, const char *);
diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c
index 3bf79d433eb..5e7d818bcc3 100644
--- a/usr.sbin/smtpd/util.c
+++ b/usr.sbin/smtpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.79 2012/09/20 14:28:57 eric Exp $ */
+/* $OpenBSD: util.c,v 1.80 2012/09/21 10:22:29 eric Exp $ */
/*
* Copyright (c) 2000,2001 Markus Friedl. All rights reserved.
@@ -359,7 +359,7 @@ safe_fclose(FILE *fp)
}
int
-hostname_match(char *hostname, char *pattern)
+hostname_match(const char *hostname, const char *pattern)
{
while (*pattern != '\0' && *hostname != '\0') {
if (*pattern == '*') {
@@ -483,7 +483,7 @@ email_to_mailaddr(struct mailaddr *maddr, char *email)
}
char *
-ss_to_text(struct sockaddr_storage *ss)
+ss_to_text(const struct sockaddr_storage *ss)
{
static char buf[NI_MAXHOST + 5];
char *p;
@@ -497,7 +497,7 @@ ss_to_text(struct sockaddr_storage *ss)
else if (ss->ss_family == AF_INET) {
in_addr_t addr;
- addr = ((struct sockaddr_in *)ss)->sin_addr.s_addr;
+ addr = ((const struct sockaddr_in *)ss)->sin_addr.s_addr;
addr = ntohl(addr);
bsnprintf(p, NI_MAXHOST,
"%d.%d.%d.%d",
@@ -507,8 +507,8 @@ ss_to_text(struct sockaddr_storage *ss)
addr & 0xff);
}
else if (ss->ss_family == AF_INET6) {
- struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)ss;
- struct in6_addr *in6_addr;
+ const struct sockaddr_in6 *in6 = (const struct sockaddr_in6 *)ss;
+ const struct in6_addr *in6_addr;
strlcpy(buf, "IPv6:", sizeof(buf));
p = buf + 5;
@@ -592,7 +592,7 @@ duration_to_text(time_t t)
}
int
-text_to_netaddr(struct netaddr *netaddr, char *s)
+text_to_netaddr(struct netaddr *netaddr, const char *s)
{
struct sockaddr_storage ss;
struct sockaddr_in ssin;
@@ -661,11 +661,10 @@ text_to_netaddr(struct netaddr *netaddr, char *s)
}
int
-text_to_relayhost(struct relayhost *relay, char *s)
+text_to_relayhost(struct relayhost *relay, const char *s)
{
- uint32_t i;
- struct schema {
- char *name;
+ static const struct schema {
+ const char *name;
uint8_t flags;
} schemas [] = {
{ "smtp://", 0 },
@@ -677,9 +676,10 @@ text_to_relayhost(struct relayhost *relay, char *s)
{ "ssl+auth://", F_SMTPS|F_STARTTLS|F_AUTH }
};
const char *errstr = NULL;
- char *p;
- char *sep;
- int len;
+ const char *p;
+ char *sep;
+ size_t i;
+ int len;
for (i = 0; i < nitems(schemas); ++i)
if (strncasecmp(schemas[i].name, s, strlen(schemas[i].name)) == 0)