feat: add ssh server (sshd)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user