]>
git.ipfire.org Git - thirdparty/strongswan.git/blob - programs/pluto/defs.h
1 /* misc. universal things
2 * Copyright (C) 1997 Angelos D. Keromytis.
3 * Copyright (C) 1998-2001 D. Hugh Redelmeier.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * RCSID $Id: defs.h,v 1.10 2006/01/04 21:00:43 as Exp $
21 #include <sys/types.h>
24 # define USED_BY_KLIPS /* ignore */
26 # define USED_BY_KLIPS UNUSED
30 # define USED_BY_DEBUG /* ignore */
32 # define USED_BY_DEBUG UNUSED
35 /* Length of temporary buffers */
39 /* type of serial number of a state object
40 * Needed in connections.h and state.h; here to simplify dependencies.
42 typedef unsigned long so_serial_t
;
43 #define SOS_NOBODY 0 /* null serial number */
44 #define SOS_FIRST 1 /* first normal serial number */
46 /* memory allocation */
48 extern void *alloc_bytes(size_t size
, const char *name
);
49 #define alloc_thing(thing, name) (alloc_bytes(sizeof(thing), (name)))
51 extern void *clone_bytes(const void *orig
, size_t size
, const char *name
);
52 #define clone_thing(orig, name) clone_bytes((const void *)&(orig), sizeof(orig), (name))
53 #define clone_str(str, name) \
54 ((str) == NULL? NULL : clone_bytes((str), strlen((str))+1, (name)))
57 extern void pfree(void *ptr
);
58 extern void report_leaks(void);
60 # define pfree(ptr) free(ptr) /* ordinary stdc free */
62 #define pfreeany(p) { if ((p) != NULL) pfree(p); }
63 #define replace(p, q) { pfreeany(p); (p) = (q); }
66 /* chunk is a simple pointer-and-size abstraction */
72 typedef struct chunk chunk_t
;
74 #define setchunk(ch, addr, size) { (ch).ptr = (addr); (ch).len = (size); }
75 #define strchunk(str) { str, sizeof(str) }
76 /* NOTE: freeanychunk, unlike pfreeany, NULLs .ptr */
77 #define freeanychunk(ch) { pfreeany((ch).ptr); (ch).ptr = NULL; }
78 #define clonetochunk(ch, addr, size, name) \
79 { (ch).ptr = clone_bytes((addr), (ch).len = (size), name); }
80 #define clonereplacechunk(ch, addr, size, name) \
81 { pfreeany((ch).ptr); clonetochunk(ch, addr, size, name); }
82 #define chunkcpy(dst, chunk) \
83 { memcpy(dst, chunk.ptr, chunk.len); dst += chunk.len;}
84 #define same_chunk(a, b) \
85 (a).len == (b).len && memcmp((a).ptr, (b).ptr, (b).len) == 0
87 extern char* temporary_cyclic_buffer(void);
88 extern const char* concatenate_paths(const char *a
, const char *b
);
90 extern const chunk_t empty_chunk
;
92 /* compare two chunks */
93 extern bool cmp_chunk(chunk_t a
, chunk_t b
);
95 /* move a chunk to a memory position and free it after insertion */
96 extern void mv_chunk(u_char
**pos
, chunk_t content
);
98 /* write the binary contents of a chunk_t to a file */
99 extern bool write_chunk(const char *filename
, const char *label
, chunk_t ch
100 ,mode_t mask
, bool force
);
102 /* display a date either in local or UTC time */
103 extern char* timetoa(const time_t *time
, bool utc
);
105 /* warns a predefined interval before expiry */
106 extern const char* check_expiry(time_t expiration_date
,
107 int warning_interval
, bool strict
);
109 #define MAX_PROMPT_PASS_TRIALS 5
110 #define PROMPT_PASS_LEN 64
112 /* struct used to prompt for a secret passphrase
113 * from a console with file descriptor fd
116 char secret
[PROMPT_PASS_LEN
+1];
121 /* no time defined in time_t */
122 #define UNDEFINED_TIME 0
124 /* size of timetoa string buffer */
125 #define TIMETOA_BUF 30
127 /* filter eliminating the directory entries '.' and '..' */
128 typedef struct dirent dirent_t
;
129 extern int file_select(const dirent_t
*entry
);
131 /* cleanly exit Pluto */
133 extern void exit_pluto(int /*status*/) NEVER_RETURNS
;
137 #define zero(x) memset((x), '\0', sizeof(*(x)))
139 /* are all bytes 0? */
140 extern bool all_zero(const unsigned char *m
, size_t len
);
142 /* pad_up(n, m) is the amount to add to n to make it a multiple of m */
143 #define pad_up(n, m) (((m) - 1) - (((n) + (m) - 1) % (m)))