This source file includes following definitions.
- is_privileged
- crm_clear_bit
- crm_set_bit
- realloc_safe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #ifndef CRM_INTERNAL__H
23 # define CRM_INTERNAL__H
24
25 # include <config.h>
26 # include <portability.h>
27
28 # include <glib.h>
29 # include <stdbool.h>
30 # include <libxml/tree.h>
31
32 # include <crm/lrmd.h>
33 # include <crm/common/logging.h>
34 # include <crm/common/ipcs.h>
35 # include <crm/common/internal.h>
36
37
38 void *find_library_function(void **handle, const char *lib, const char *fn, int fatal);
39 void *convert_const_pointer(const void *ptr);
40
41
42 char *uid2username(uid_t uid);
43 void determine_request_user(const char *user, xmlNode * request, const char *field);
44 const char *crm_acl_get_set_user(xmlNode * request, const char *field, const char *peer_user);
45
46 # if ENABLE_ACL
47 # include <string.h>
48 static inline gboolean
49 is_privileged(const char *user)
50 {
51 if (user == NULL) {
52 return FALSE;
53 } else if (strcmp(user, CRM_DAEMON_USER) == 0) {
54 return TRUE;
55 } else if (strcmp(user, "root") == 0) {
56 return TRUE;
57 }
58 return FALSE;
59 }
60 # endif
61
62
63 # ifdef HAVE_GETOPT_H
64 # include <getopt.h>
65 # else
66 # define no_argument 0
67 # define required_argument 1
68 # endif
69
70 # define pcmk_option_default 0x00000
71 # define pcmk_option_hidden 0x00001
72 # define pcmk_option_paragraph 0x00002
73 # define pcmk_option_example 0x00004
74
75 struct crm_option {
76
77
78 const char *name;
79
80
81
82
83 int has_arg;
84
85 int *flag;
86
87 int val;
88
89
90 const char *desc;
91 long flags;
92 };
93
94 void crm_set_options(const char *short_options, const char *usage, struct crm_option *long_options,
95 const char *app_desc);
96 int crm_get_option(int argc, char **argv, int *index);
97 int crm_get_option_long(int argc, char **argv, int *index, const char **longname);
98 int crm_help(char cmd, int exit_code);
99
100
101 typedef struct pe_cluster_option_s {
102 const char *name;
103 const char *alt_name;
104 const char *type;
105 const char *values;
106 const char *default_value;
107
108 gboolean(*is_valid) (const char *);
109
110 const char *description_short;
111 const char *description_long;
112
113 } pe_cluster_option;
114
115 const char *cluster_option(GHashTable * options, gboolean(*validate) (const char *),
116 const char *name, const char *old_name, const char *def_value);
117
118 const char *get_cluster_pref(GHashTable * options, pe_cluster_option * option_list, int len,
119 const char *name);
120
121 void config_metadata(const char *name, const char *version, const char *desc_short,
122 const char *desc_long, pe_cluster_option * option_list, int len);
123
124 void verify_all_options(GHashTable * options, pe_cluster_option * option_list, int len);
125 gboolean check_time(const char *value);
126 gboolean check_timer(const char *value);
127 gboolean check_boolean(const char *value);
128 gboolean check_number(const char *value);
129 gboolean check_positive_number(const char *value);
130 gboolean check_quorum(const char *value);
131 gboolean check_script(const char *value);
132 gboolean check_utilization(const char *value);
133 long crm_get_sbd_timeout(void);
134 gboolean check_sbd_timeout(const char *value);
135
136
137 extern int node_score_red;
138 extern int node_score_green;
139 extern int node_score_yellow;
140 extern int node_score_infinity;
141
142
143 int crm_pid_active(long pid, const char *daemon);
144 void crm_make_daemon(const char *name, gboolean daemonize, const char *pidfile);
145
146
147 char *generate_op_key(const char *rsc_id, const char *op_type, int interval);
148 char *generate_notify_key(const char *rsc_id, const char *notify_type, const char *op_type);
149 char *generate_transition_magic_v202(const char *transition_key, int op_status);
150 char *generate_transition_magic(const char *transition_key, int op_status, int op_rc);
151 char *generate_transition_key(int action, int transition_id, int target_rc, const char *node);
152 void filter_action_parameters(xmlNode *param_set, const char *version);
153 xmlNode *create_operation_update(xmlNode *parent, lrmd_event_data_t *event,
154 const char *caller_version, int target_rc,
155 const char *node, const char *origin,
156 int level);
157
158 static inline long long
159 crm_clear_bit(const char *function, int line, const char *target, long long word, long long bit)
160 {
161 long long rc = (word & ~bit);
162
163 if (rc == word) {
164
165 } else if (target) {
166 crm_trace("Bit 0x%.8llx for %s cleared by %s:%d", bit, target, function, line);
167 } else {
168 crm_trace("Bit 0x%.8llx cleared by %s:%d", bit, function, line);
169 }
170
171 return rc;
172 }
173
174 static inline long long
175 crm_set_bit(const char *function, int line, const char *target, long long word, long long bit)
176 {
177 long long rc = (word | bit);
178
179 if (rc == word) {
180
181 } else if (target) {
182 crm_trace("Bit 0x%.8llx for %s set by %s:%d", bit, target, function, line);
183 } else {
184 crm_trace("Bit 0x%.8llx set by %s:%d", bit, function, line);
185 }
186
187 return rc;
188 }
189
190 # define set_bit(word, bit) word = crm_set_bit(__FUNCTION__, __LINE__, NULL, word, bit)
191 # define clear_bit(word, bit) word = crm_clear_bit(__FUNCTION__, __LINE__, NULL, word, bit)
192
193 char *generate_hash_key(const char *crm_msg_reference, const char *sys);
194
195
196 typedef struct crm_remote_s crm_remote_t;
197
198 int crm_remote_send(crm_remote_t * remote, xmlNode * msg);
199 int crm_remote_ready(crm_remote_t * remote, int total_timeout );
200 gboolean crm_remote_recv(crm_remote_t * remote, int total_timeout , int *disconnected);
201 xmlNode *crm_remote_parse_buffer(crm_remote_t * remote);
202 int crm_remote_tcp_connect(const char *host, int port);
203 int crm_remote_tcp_connect_async(const char *host, int port, int timeout,
204 int *timer_id, void *userdata, void (*callback) (void *userdata, int sock));
205 int crm_remote_accept(int ssock);
206 void crm_sockaddr2str(void *sa, char *s);
207
208 # ifdef HAVE_GNUTLS_GNUTLS_H
209
210
211
212
213
214
215
216
217 int crm_initiate_client_tls_handshake(crm_remote_t * remote, int timeout_ms);
218
219
220
221
222
223
224
225
226
227
228
229 void *crm_create_anon_tls_session(int sock, int type, void *credentials);
230
231
232
233
234
235
236
237
238
239
240
241 void *create_psk_tls_session(int csock, int type, void *credentials);
242 # endif
243
244 # define REMOTE_MSG_TERMINATOR "\r\n\r\n"
245
246 const char *daemon_option(const char *option);
247 void set_daemon_option(const char *option, const char *value);
248 gboolean daemon_option_enabled(const char *daemon, const char *option);
249 void strip_text_nodes(xmlNode * xml);
250 void pcmk_panic(const char *origin);
251 void sysrq_init(void);
252 pid_t pcmk_locate_sbd(void);
253 long crm_pidfile_inuse(const char *filename, long mypid, const char *daemon);
254 long crm_read_pidfile(const char *filename);
255
256 # define crm_config_err(fmt...) { crm_config_error = TRUE; crm_err(fmt); }
257 # define crm_config_warn(fmt...) { crm_config_warning = TRUE; crm_warn(fmt); }
258
259 # define attrd_channel T_ATTRD
260 # define F_ATTRD_KEY "attr_key"
261 # define F_ATTRD_ATTRIBUTE "attr_name"
262 # define F_ATTRD_REGEX "attr_regex"
263 # define F_ATTRD_TASK "task"
264 # define F_ATTRD_VALUE "attr_value"
265 # define F_ATTRD_SET "attr_set"
266 # define F_ATTRD_IS_REMOTE "attr_is_remote"
267 # define F_ATTRD_IS_PRIVATE "attr_is_private"
268 # define F_ATTRD_SECTION "attr_section"
269 # define F_ATTRD_DAMPEN "attr_dampening"
270 # define F_ATTRD_IGNORE_LOCALLY "attr_ignore_locally"
271 # define F_ATTRD_HOST "attr_host"
272 # define F_ATTRD_HOST_ID "attr_host_id"
273 # define F_ATTRD_USER "attr_user"
274 # define F_ATTRD_WRITER "attr_writer"
275 # define F_ATTRD_VERSION "attr_version"
276 # define F_ATTRD_RESOURCE "attr_resource"
277 # define F_ATTRD_OPERATION "attr_clear_operation"
278 # define F_ATTRD_INTERVAL "attr_clear_interval"
279
280
281 # define ATTRD_OP_PEER_REMOVE "peer-remove"
282 # define ATTRD_OP_UPDATE "update"
283 # define ATTRD_OP_UPDATE_BOTH "update-both"
284 # define ATTRD_OP_UPDATE_DELAY "update-delay"
285 # define ATTRD_OP_QUERY "query"
286 # define ATTRD_OP_REFRESH "refresh"
287 # define ATTRD_OP_FLUSH "flush"
288 # define ATTRD_OP_SYNC "sync"
289 # define ATTRD_OP_SYNC_RESPONSE "sync-response"
290 # define ATTRD_OP_CLEAR_FAILURE "clear-failure"
291
292 # define PCMK_ENV_PHYSICAL_HOST "physical_host"
293
294
295 # if SUPPORT_COROSYNC
296 # if CS_USES_LIBQB
297 # include <qb/qbipc_common.h>
298 # include <corosync/corotypes.h>
299 typedef struct qb_ipc_request_header cs_ipc_header_request_t;
300 typedef struct qb_ipc_response_header cs_ipc_header_response_t;
301 # else
302 # include <corosync/corodefs.h>
303 # include <corosync/coroipcc.h>
304 # include <corosync/coroipc_types.h>
305 typedef coroipc_request_header_t cs_ipc_header_request_t;
306 typedef coroipc_response_header_t cs_ipc_header_response_t;
307 # endif
308 # else
309 typedef struct {
310 int size __attribute__ ((aligned(8)));
311 int id __attribute__ ((aligned(8)));
312 } __attribute__ ((aligned(8))) cs_ipc_header_request_t;
313
314 typedef struct {
315 int size __attribute__ ((aligned(8)));
316 int id __attribute__ ((aligned(8)));
317 int error __attribute__ ((aligned(8)));
318 } __attribute__ ((aligned(8))) cs_ipc_header_response_t;
319
320 # endif
321
322 void
323 attrd_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb);
324 void
325 stonith_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb);
326
327 qb_ipcs_service_t *
328 crmd_ipc_server_init(struct qb_ipcs_service_handlers *cb);
329
330 void cib_ipc_servers_init(qb_ipcs_service_t **ipcs_ro,
331 qb_ipcs_service_t **ipcs_rw,
332 qb_ipcs_service_t **ipcs_shm,
333 struct qb_ipcs_service_handlers *ro_cb,
334 struct qb_ipcs_service_handlers *rw_cb);
335
336 void cib_ipc_servers_destroy(qb_ipcs_service_t *ipcs_ro,
337 qb_ipcs_service_t *ipcs_rw,
338 qb_ipcs_service_t *ipcs_shm);
339
340 static inline void *realloc_safe(void *ptr, size_t size)
341 {
342 void *ret = realloc(ptr, size);
343
344 if (ret == NULL) {
345 free(ptr);
346 abort();
347 }
348
349 return ret;
350 }
351
352 const char *crm_xml_add_last_written(xmlNode *xml_node);
353 void crm_xml_dump(xmlNode * data, int options, char **buffer, int *offset, int *max, int depth);
354 void crm_buffer_add_char(char **buffer, int *offset, int *max, char c);
355
356 gboolean crm_digest_verify(xmlNode *input, const char *expected);
357
358
359 char *crm_compat_realpath(const char *path);
360
361
362 typedef struct remote_proxy_s {
363 char *node_name;
364 char *session_id;
365
366 gboolean is_local;
367
368 crm_ipc_t *ipc;
369 mainloop_io_t *source;
370 uint32_t last_request_id;
371 lrmd_t *lrm;
372
373 } remote_proxy_t;
374
375 remote_proxy_t *remote_proxy_new(
376 lrmd_t *lrmd, struct ipc_client_callbacks *proxy_callbacks,
377 const char *node_name, const char *session_id, const char *channel);
378
379 int remote_proxy_check(lrmd_t *lrmd, GHashTable *hash);
380 void remote_proxy_cb(lrmd_t *lrmd, const char *node_name, xmlNode *msg);
381 void remote_proxy_ack_shutdown(lrmd_t *lrmd);
382 void remote_proxy_nack_shutdown(lrmd_t *lrmd);
383
384 int remote_proxy_dispatch(const char *buffer, ssize_t length, gpointer userdata);
385 void remote_proxy_disconnected(gpointer data);
386 void remote_proxy_free(gpointer data);
387
388 void remote_proxy_relay_event(remote_proxy_t *proxy, xmlNode *msg);
389 void remote_proxy_relay_response(remote_proxy_t *proxy, xmlNode *msg, int msg_id);
390
391 #endif