37 #define _DARWIN_C_SOURCE 1 41 #define __BSD_VISIBLE 1 48 #include "scheduler/task.h" 57 static const char *module_str =
"policy_resalt_task";
58 static const time_t TIME_INF = ((time_t)-1);
67 generate_salt(
char *buf,
int len)
69 #ifdef HAVE_ARC4RANDOM 70 arc4random_buf(buf, len);
75 for (i = 0; i < len; i++)
76 buf[i] = rand() & 0xFF;
87 to_hex(
const char *buf,
int len,
char *out)
89 const char *h =
"0123456789abcdef";
92 for (i = 0; i < len; i++) {
93 out[2*i] = h[(buf[i]>>4) & 0x0F];
94 out[2*i+1] = h[buf[i] & 0x0F];
104 perform_policy_resalt(task_type* task,
char const *policyname,
void *userdata,
109 time_t resalt_time, now = time_now();
110 char salt[255], salthex[511];
116 ods_log_error(
"[%s] could not fetch policy %s from database," 117 " rescheduling", module_str, policyname);
120 return schedule_DEFER;
127 return schedule_SUCCESS;
132 if (now >= resalt_time) {
134 if (saltlength <= 0 || saltlength > 255) {
135 ods_log_error(
"[%s] policy %s has an invalid salt length. " 136 "Must be in range [0..255]", module_str,
policy_name(policy));
138 return schedule_SUCCESS;
141 #ifndef HAVE_ARC4RANDOM 146 generate_salt(salt, saltlength);
147 to_hex(salt, saltlength, salthex);
153 ods_log_error(
"[%s] db error", module_str);
155 return schedule_DEFER;
158 ods_log_debug(
"[%s] policy %s resalted successfully", module_str,
policy_name(policy));
167 policy_resalt_task(
char const *owner,
engine_type *engine)
169 return task_create(strdup(owner), TASK_CLASS_ENFORCER, TASK_TYPE_RESALT,
170 perform_policy_resalt, engine, NULL, time_now());
183 int status = ODS_STATUS_OK;
187 ods_log_error(
"[%s] Unable to get list of policies from database",
190 return ODS_STATUS_ERR;
194 task = policy_resalt_task(
policy_name(policy), engine);
195 status |= schedule_task(engine->
taskq, task, 1, 0);
int policy_list_get(policy_list_t *policy_list)
void policy_list_free(policy_list_t *policy_list)
unsigned int policy_denial_resalt(const policy_t *policy)
policy_t * policy_new_get_by_name(const db_connection_t *connection, const char *name)
const char * policy_name(const policy_t *policy)
unsigned int policy_denial_salt_last_change(const policy_t *policy)
void signconf_task_flush_policy(engine_type *engine, db_connection_t *dbconn, policy_t const *policy)
unsigned int policy_passthrough(const policy_t *policy)
void policy_free(policy_t *policy)
int policy_update(policy_t *policy)
policy_list_t * policy_list_new(const db_connection_t *connection)
int policy_set_denial_salt(policy_t *policy, const char *denial_salt_text)
const policy_t * policy_list_next(policy_list_t *policy_list)
unsigned int policy_denial_salt_length(const policy_t *policy)
int policy_set_denial_salt_last_change(policy_t *policy, unsigned int denial_salt_last_change)
int flush_resalt_task_all(engine_type *engine, db_connection_t *dbconn)