s/qmail 4.3.20
Next generation secure email transport
Loading...
Searching...
No Matches
srs2.h
Go to the documentation of this file.
1#ifndef SRS2_H
2#define SRS2_H
3#include <stdint.h>
4#include <time.h>
5
6/* Adjusted to s/qmail (feh) */
7
8/* Copyright (c) 2004 Shevek (srs@anarres.org)
9 * All rights reserved.
10 *
11 * This file is a part of libsrs2 from http://www.libsrs2.org/
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, under the terms of either the GNU General Public
15 * License version 2 or the BSD license, at the discretion of the
16 * user. Copies of these licenses have been included in the libsrs2
17 * distribution. See the the file called LICENSE for more
18 * information.
19 */
20
21/* This is ugly, but reasonably safe. */
22#undef TRUE
23#define TRUE 1
24#undef FALSE
25#define FALSE 0
26
27#define SRSSEP '='
28#define SRS0TAG "SRS0"
29#define SRS1TAG "SRS1"
30
31/* Error codes */
32
33#define SRS_ERRTYPE_MASK 0xf000
34#define SRS_ERRTYPE_NONE 0x0000
35#define SRS_ERRTYPE_CONFIG 0x1000
36#define SRS_ERRTYPE_INPUT 0x2000
37#define SRS_ERRTYPE_SYNTAX 0x4000
38#define SRS_ERRTYPE_SRS 0x8000
39
40#define SRS_SUCCESS (0)
41#define SRS_ENOTSRSADDRESS (1)
42#define SRS_ENOTREWRITTEN (2)
43
44#define SRS_ENOSECRETS (SRS_ERRTYPE_CONFIG | 1)
45#define SRS_ESEPARATORINVALID (SRS_ERRTYPE_CONFIG | 2)
46
47#define SRS_ENOSENDERATSIGN (SRS_ERRTYPE_INPUT | 1)
48#define SRS_EBUFTOOSMALL (SRS_ERRTYPE_INPUT | 2)
49
50#define SRS_ENOSRS0HOST (SRS_ERRTYPE_SYNTAX | 1)
51#define SRS_ENOSRS0USER (SRS_ERRTYPE_SYNTAX | 2)
52#define SRS_ENOSRS0HASH (SRS_ERRTYPE_SYNTAX | 3)
53#define SRS_ENOSRS0STAMP (SRS_ERRTYPE_SYNTAX | 4)
54#define SRS_ENOSRS1HOST (SRS_ERRTYPE_SYNTAX | 5)
55#define SRS_ENOSRS1USER (SRS_ERRTYPE_SYNTAX | 6)
56#define SRS_ENOSRS1HASH (SRS_ERRTYPE_SYNTAX | 7)
57#define SRS_EBADTIMESTAMPCHAR (SRS_ERRTYPE_SYNTAX | 8)
58#define SRS_EHASHTOOSHORT (SRS_ERRTYPE_SYNTAX | 9)
59
60#define SRS_ETIMESTAMPOUTOFDATE (SRS_ERRTYPE_SRS | 1)
61#define SRS_EHASHINVALID (SRS_ERRTYPE_SRS | 2)
62
63#define SRS_ERROR_TYPE(x) ((x) & SRS_ERRTYPE_MASK)
64
65/* SRS implementation */
66
67#define SRS_IS_SRS_ADDRESS(x) ( \
68 (strncasecmp((x),"SRS",3) == 0) && \
69 (strchr("01", (x)[3]) != NULL) && \
70 (strchr("-+=", (x)[4]) != NULL) \
71)
72
73typedef void *(*srs_malloc_t)(size_t);
74typedef void *(*srs_realloc_t)(void *,size_t);
75typedef void (*srs_free_t)(void *);
76
77typedef int srs_bool;
78
79typedef struct _srs_t {
80 /* Rewriting parameters */
81// stralloc cookies;
82 char **secrets;
85
86 /* Security parameters */
87 int maxage; /* Maximum allowed age in seconds */
90
91 /* Behaviour parameters */
92 srs_bool alwaysrewrite; /* Rewrite even into same domain? */
93 srs_bool noforward; /* Never perform forwards rewriting */
94 srs_bool noreverse; /* Never perform reverse rewriting */
95 char **neverrewrite; /* A list of non-rewritten domains */
97
98/* Interface */
100srs_t *srs_new();
101void srs_init(srs_t *);
102void srs_free(srs_t *);
103int srs_forward(srs_t *,char *,int,const char *,const char *);
104int srs_forward_alloc(srs_t *,char **,const char *,const char *);
105int srs_reverse(srs_t *,char *,int, const char *);
106int srs_reverse_alloc(srs_t *,char **,const char *);
107const char *srs_strerror(int);
108int srs_add_secret(srs_t *,const char *);
109const char * srs_get_secret(srs_t *,int);
110 /* You probably shouldn't call these. */
111int srs_timestamp_create(srs_t *,char *,time_t);
112int srs_timestamp_check(srs_t *,const char *);
113
114#define SRS_PARAM_DECLARE(n, t) \
115 int srs_set_ ## n (srs_t *srs, t value); \
116 t srs_get_ ## n (srs_t *srs);
117
118SRS_PARAM_DECLARE(alwaysrewrite,srs_bool)
119SRS_PARAM_DECLARE(separator,char)
120SRS_PARAM_DECLARE(maxage,int)
121SRS_PARAM_DECLARE(hashlen,int)
122SRS_PARAM_DECLARE(hashmin,int)
125
126#endif /* SRS2_H */
struct message * m
int srs_reverse_alloc(srs_t *, char **, const char *)
Definition: srs2.c:624
void *(* srs_malloc_t)(size_t)
Definition: srs2.h:73
int srs_add_secret(srs_t *, const char *)
Definition: srs2.c:137
void(* srs_free_t)(void *)
Definition: srs2.h:75
void srs_free(srs_t *)
Definition: srs2.c:126
void *(* srs_realloc_t)(void *, size_t)
Definition: srs2.h:74
void srs_init(srs_t *)
Definition: srs2.c:114
int srs_bool
Definition: srs2.h:77
int srs_reverse(srs_t *, char *, int, const char *)
Definition: srs2.c:599
srs_t * srs_new()
Definition: srs2.c:107
int srs_forward(srs_t *, char *, int, const char *, const char *)
Definition: srs2.c:528
#define SRS_PARAM_DECLARE(n, t)
Definition: srs2.h:114
int srs_forward_alloc(srs_t *, char **, const char *, const char *)
Definition: srs2.c:570
const char * srs_strerror(int)
Definition: srs2.c:74
const char * srs_get_secret(srs_t *, int)
Definition: srs2.c:145
struct _srs_t srs_t
int srs_timestamp_create(srs_t *, char *, time_t)
Definition: srs2.c:194
int srs_timestamp_check(srs_t *, const char *)
Definition: srs2.c:204
int srs_set_malloc(srs_malloc_t m, srs_realloc_t r, srs_free_t f)
Definition: srs2.c:64
Definition: srs2.h:79
char ** secrets
Definition: srs2.h:82
int hashlen
Definition: srs2.h:88
int hashmin
Definition: srs2.h:89
char separator
Definition: srs2.h:84
srs_bool noreverse
Definition: srs2.h:94
srs_bool alwaysrewrite
Definition: srs2.h:92
int maxage
Definition: srs2.h:87
srs_bool noforward
Definition: srs2.h:93
int numsecrets
Definition: srs2.h:83
char ** neverrewrite
Definition: srs2.h:95