28 lines
865 B
C++
28 lines
865 B
C++
/* Shared SSH server policy helpers. */
|
|
#pragma once
|
|
#include <montauk/config.h>
|
|
#include <montauk/string.h>
|
|
#include <montauk/user.h>
|
|
#include <libc/stdio.h>
|
|
|
|
namespace montauk::ssh {
|
|
inline void allow_key(char* out, int cap, const char* username) {
|
|
snprintf(out, cap, "allow.%s", username);
|
|
}
|
|
|
|
inline bool user_allowed(const montauk::toml::Doc& doc, const char* username) {
|
|
char key[64];
|
|
allow_key(key, sizeof(key), username);
|
|
return doc.get_bool(key, false);
|
|
}
|
|
|
|
inline bool is_admin(const char* username) {
|
|
user::UserInfo users[user::MAX_USERS];
|
|
int count = user::load_users(users, user::MAX_USERS);
|
|
for (int i = 0; i < count; i++)
|
|
if (montauk::streq(users[i].username, username))
|
|
return montauk::streq(users[i].role, "admin");
|
|
return false;
|
|
}
|
|
}
|