Return an rc from the passwd and group functions.
[pwmd.git] / src / util-misc.h
blobbb9e909e164af04b3651732d073a5dfa22366d0e
1 /*
2 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
3 Ben Kibbey <bjk@luxsci.net>
5 This file is part of pwmd.
7 Pwmd is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 2 of the License, or
10 (at your option) any later version.
12 Pwmd is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Pwmd. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef UTIL_MISC_H
21 #define UTIL_MISC_H
23 #include <pthread.h>
24 #include <sys/types.h>
25 #include <wchar.h>
26 #include <pwd.h>
27 #include "rcfile.h"
29 #ifdef HAVE_BACKTRACE
30 #include <execinfo.h>
31 #include <syslog.h>
32 #define BACKTRACE_COUNT 20
33 #define BACKTRACE(fn) do { \
34 int n, nptrs; \
35 char **strings; \
36 void *buffer[BACKTRACE_COUNT]; \
37 nptrs = backtrace(buffer, BACKTRACE_COUNT); \
38 strings = backtrace_symbols(buffer, nptrs); \
39 for (n = 0; n < nptrs; n++) \
40 log_write("BACKTRACE: (%s) %i: %s", fn, n, strings[n]); \
41 } while (0)
42 #endif
44 #define log_write0 log_write
46 #define log_write1(...) do { \
47 if (log_level >= 1) \
48 log_write(__VA_ARGS__); \
49 } while (0)
51 #define log_write2(...) do { \
52 if (log_level >= 2) \
53 log_write(__VA_ARGS__); \
54 } while (0)
56 typedef enum
58 OPTION_TYPE_NOARG,
59 OPTION_TYPE_ARG,
60 OPTION_TYPE_OPTARG,
61 } option_type_t;
63 struct argv_s
65 const char *opt;
66 option_type_t type;
67 gpg_error_t (*func) (void *data, void *value);
70 typedef struct
72 size_t len;
73 void *buf;
74 } membuf_t;
76 char *home_directory;
77 int log_level;
79 gpg_error_t parse_options (char **line, struct argv_s *args[], void *data,
80 int more);
81 int valid_filename (const char *filename);
82 char *expand_homedir (char *str);
83 char *bin2hex (const unsigned char *data, size_t len);
84 char *plus_escape (const char *fmt, ...);
85 char *strip_texi_and_wrap (const char *str);
86 void free_key (void *data);
87 gpg_error_t create_thread (void *(*cb) (void *), void *data,
88 pthread_t * tid, int detached);
89 void cleanup_mutex_cb (void *arg);
90 void cleanup_fd_cb (void *arg);
91 void cleanup_unlink_cb (void *arg);
92 void cleanup_cancel_cb (void *arg);
93 void cleanup_cache_mutex (void *arg);
94 int valid_keygrip (const unsigned char *data, size_t len);
95 gpg_error_t get_checksum (const char *filename, unsigned char **r_crc,
96 size_t * r_crclen);
97 char *get_username (uid_t);
98 char *get_home_dir ();
99 struct passwd *get_pwd_struct (const char *user, uid_t uid, struct passwd *,
100 char **buf, gpg_error_t *);
101 wchar_t *str_to_wchar (const char *str);
103 #endif