~ubuntu-branches/ubuntu/karmic/pdnsd/karmic

« back to all changes in this revision

Viewing changes to src/helpers.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Ablassmeier
  • Date: 2006-10-12 08:18:52 UTC
  • mfrom: (3.1.3 edgy)
  • Revision ID: james.westby@ubuntu.com-20061012081852-k70ha1vynt2vu7mg
Tags: 1.2.4par-0.2
* Non-maintainer upload.
* Check for bind named pidfile in initscript and do not
  try to startup, otherwise pdnsd installation bails
  out if named is running on the same host (Closes: #389609)
* add --no-create-home to adduser call.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* helpers.h - Various helper functions
 
2
 
2
3
   Copyright (C) 2000, 2001 Thomas Moestl
3
 
 
4
 
   With modifications by Paul Rombouts, 2002, 2003, 2004.
 
4
   Copyright (C) 2002, 2003, 2004 Paul A. Rombouts
5
5
 
6
6
This file is part of the pdnsd package.
7
7
 
35
35
 
36
36
#define SOFTLOCK_MAXTRIES 1000
37
37
 
38
 
int run_as(char *user);
 
38
int run_as(const char *user);
39
39
void pdnsd_exit(void);
40
40
int softlock_mutex(pthread_mutex_t *mutex);
41
41
 
 
42
#if 0
42
43
inline static int isdchar (unsigned char c)
43
44
{
44
45
  return ((c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='-'
47
48
#endif
48
49
          );
49
50
}
 
51
#endif
50
52
 
51
 
void rhn2str(const unsigned char *rhn, unsigned char *str);
 
53
const unsigned char *rhn2str(const unsigned char *rhn, unsigned char *str, int size);
52
54
int  str2rhn(const unsigned char *str, unsigned char *rhn);
53
55
const char *parsestr2rhn(const unsigned char *str, int len, unsigned char *rhn);
54
56
 
58
60
*/
59
61
inline static unsigned int rhnlen(const unsigned char *rhn)
60
62
{
61
 
        unsigned int i=0;
62
 
        unsigned char lb;
 
63
        unsigned int i=0,lb;
63
64
 
64
65
        while((lb=rhn[i]))
65
66
                i+=lb+1;
66
67
        return i+1;
67
68
}
68
69
 
69
 
/* count the number of name segments. */
 
70
/* Skip k segments in a name in length-byte string notation. */
 
71
inline static unsigned char *skipsegs(unsigned char *nm, unsigned k)
 
72
{
 
73
        unsigned lb;
 
74
        for(;k;--k) {
 
75
                lb= *nm;
 
76
                if(!lb) return nm;
 
77
                nm += lb+1;
 
78
        }
 
79
        return nm;
 
80
}
 
81
 
 
82
/* Skip a name in length-byte string notation and return a pointer to the
 
83
   position right after the terminating null byte.
 
84
*/
 
85
inline static unsigned char *skiprhn(unsigned char *rhn)
 
86
{
 
87
        unsigned lb;
 
88
 
 
89
        while((lb= *rhn))
 
90
                rhn += lb+1;
 
91
        return rhn+1;
 
92
}
 
93
 
 
94
/* count the number of name segments of a name in length-byte string notation. */
70
95
inline static unsigned int rhnsegcnt(const unsigned char *rhn)
71
96
{
72
 
        unsigned int res=0;
73
 
        unsigned char lb;
 
97
        unsigned int res=0,lb;
74
98
 
75
99
        while((lb= *rhn)) {
76
100
                ++res;
81
105
 
82
106
unsigned int rhncpy(unsigned char *dst, const unsigned char *src);
83
107
 
84
 
int follow_cname_chain(dns_cent_t *c, unsigned char *name, unsigned char *rrn);
85
 
 
86
108
inline static int is_inaddr_any(pdnsd_a *a)
87
109
{
88
110
  return
130
152
unsigned short get_rand16(void);
131
153
 
132
154
int fsprintf(int fd, const char *format, ...) printfunc(2, 3);
133
 
#if defined(__GNUC__) && (__GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 95))
 
155
#if !defined(CPP_C99_VARIADIC_MACROS)
 
156
/* GNU C Macro Varargs style. */
134
157
# define fsprintf_or_return(args...) {int _retval; if((_retval=fsprintf(args))<0) return _retval;}
135
158
#else
136
 
/* ANSI style variadic macro. */
 
159
/* ANSI C99 style variadic macro. */
137
160
# define fsprintf_or_return(...) {int _retval; if((_retval=fsprintf(__VA_ARGS__))<0) return _retval;}
138
161
#endif
139
162
 
154
177
  return written;
155
178
}
156
179
 
 
180
void hexdump(const void *data, int dlen, char *buf, int buflen);
 
181
int escapestr(const char *in, int ilen, char *str, int size);
157
182
 
 
183
#if 0
158
184
inline static int stricomp(const char *a, const char *b)
159
185
{
160
186
  return !strcasecmp(a,b);
161
187
}
 
188
#endif
162
189
 
163
190
/* compare two names in length byte - string format */
164
191
inline static int rhnicmp(const unsigned char *a, const unsigned char *b)
170
197
                if(lb!=b[i]) return 0;
171
198
                if(!lb) break;
172
199
                ++i;
173
 
                for(;lb;--lb) {
 
200
                do {
174
201
                        if(tolower(a[i])!=tolower(b[i])) return 0;
175
202
                        ++i;
176
 
                }
 
203
                } while(--lb);
177
204
        }
178
205
        return 1;
179
206
}
180
207
 
181
208
/* Bah. I want strlcpy. */
182
 
inline static int strncp(char *dst, const char *src, int dstsz)
 
209
inline static int strncp(char *dst, const char *src, size_t dstsz)
183
210
{
 
211
#ifdef HAVE_STRLCPY
 
212
        return (strlcpy(dst,src,dstsz)<dstsz);
 
213
#else
184
214
#ifdef HAVE_STPNCPY
185
215
        char *p=stpncpy(dst,src,dstsz);
186
216
        if(p<dst+dstsz) return 1;
192
222
        dst[dstsz-1]='\0';
193
223
        return 0;
194
224
#endif
 
225
#endif
195
226
}
196
227
 
197
228
#ifndef HAVE_STRDUP
233
264
}
234
265
#endif
235
266
 
 
267
#ifndef HAVE_MEMPCPY
 
268
inline static void *mempcpy(void *dest, const void *src, size_t len)
 
269
{
 
270
  memcpy(dest,src,len);
 
271
  return ((char *)dest)+len;
 
272
}
 
273
#endif
 
274
 
236
275
#ifndef HAVE_GETLINE
237
276
int getline(char **lineptr, size_t *n, FILE *stream);
238
277
#endif
241
280
int asprintf (char **lineptr, const char *format, ...);
242
281
#endif
243
282
 
 
283
#ifndef HAVE_VASPRINTF
 
284
#include <stdarg.h>
 
285
int vasprintf (char **lineptr, const char *format, va_list va);
 
286
#endif
 
287
 
 
288
#ifndef HAVE_INET_NTOP
 
289
const char *inet_ntop(int af, const void *src, char *dst, size_t size);
 
290
#endif
 
291
 
244
292
#define strlitlen(strlit) (sizeof(strlit)-1)
245
293
 
246
294
#endif /* HELPERS_H */