2024-04-24 02:01:26 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include "notify.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "runtime-config.h"
|
|
|
|
/* If samuel truly doesn't exist,
|
|
|
|
* there's probably a bigger issue than just an LDAP failure.
|
|
|
|
*/
|
|
|
|
#define CHECK_USERS_CANARY_USER "samuel"
|
|
|
|
int check_users_state;
|
|
|
|
void check_users_init() {
|
|
|
|
check_users_state = 0;
|
|
|
|
}
|
|
|
|
void check_users() {
|
|
|
|
if(should_enable_debug()) {
|
|
|
|
printf("[D] Starting check_users\n");
|
|
|
|
}
|
|
|
|
struct passwd *res;
|
|
|
|
errno = 0;
|
|
|
|
res = getpwnam(CHECK_USERS_CANARY_USER);
|
2024-04-24 04:25:06 +00:00
|
|
|
if(res == NULL || getenv("NEST_SANITY_CHECK_USERS_DEBUG")!=NULL) {
|
2024-04-24 02:01:26 +00:00
|
|
|
/* If we've already reported it, let's not report it again */
|
|
|
|
if(check_users_state == 1) return;
|
|
|
|
int res_errno;
|
|
|
|
res_errno = errno;
|
|
|
|
char *res_err_txt;
|
|
|
|
res_err_txt = strerror(res_errno);
|
|
|
|
char *notification_payload;
|
|
|
|
int notification_payload_len;
|
2024-04-24 02:05:20 +00:00
|
|
|
const char *notification_payload_fmt = "samuel doesn't exist, LDAP is probably broken somehow. (getpwnam returned errno %s/%d)";
|
2024-04-24 02:01:26 +00:00
|
|
|
/* TODO: set a realistic payload length */
|
|
|
|
notification_payload_len = strlen(notification_payload_fmt) + strlen(res_err_txt) + 1;
|
|
|
|
notification_payload = malloc(notification_payload_len+1);
|
2024-04-24 02:05:20 +00:00
|
|
|
snprintf(notification_payload, notification_payload_len, notification_payload_fmt, res_err_txt, res_errno);
|
2024-04-24 02:01:26 +00:00
|
|
|
int send_alarm_result;
|
|
|
|
send_alarm_result = send_alarm(notification_payload);
|
2024-04-24 04:25:06 +00:00
|
|
|
free(notification_payload);
|
2024-04-24 02:01:26 +00:00
|
|
|
/* We only set this to 1 if we successfully reported the issue. */
|
|
|
|
if(send_alarm_result == 0) check_users_state = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(check_users_state > 0) {
|
|
|
|
int send_alarm_result;
|
|
|
|
send_alarm_result = send_alarm("samuel exists again, everything is probably okay now");
|
|
|
|
/* Keep notifying until it sends successfully. */
|
|
|
|
if(send_alarm_result == 0) check_users_state = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|