/*
 * user.h
 *
 * Copyright (C) 2017 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __MONOLITHIUM_USER_H__
#define __MONOLITHIUM_USER_H__

#include "defs.h"

#define ALL_USERS (uid_t)-1

#define MAX_USERNAME_LENGTH 32

#define PRIVILEGE_LOGON_USER       (1ULL << 0)
#define PRIVILEGE_NETWORK_ACCESS   (1ULL << 1)
#define PRIVILEGE_MOUNT_UNMOUNT    (1ULL << 2)
#define PRIVILEGE_UNNAMED3         (1ULL << 3)
#define PRIVILEGE_UNNAMED4         (1ULL << 4)
#define PRIVILEGE_UNNAMED5         (1ULL << 5)
#define PRIVILEGE_UNNAMED6         (1ULL << 6)
#define PRIVILEGE_UNNAMED7         (1ULL << 7)
#define PRIVILEGE_UNNAMED8         (1ULL << 8)
#define PRIVILEGE_UNNAMED9         (1ULL << 9)
#define PRIVILEGE_UNNAMED10        (1ULL << 10)
#define PRIVILEGE_UNNAMED11        (1ULL << 11)
#define PRIVILEGE_UNNAMED12        (1ULL << 12)
#define PRIVILEGE_UNNAMED13        (1ULL << 13)
#define PRIVILEGE_UNNAMED14        (1ULL << 14)
#define PRIVILEGE_UNNAMED15        (1ULL << 15)
#define PRIVILEGE_UNNAMED16        (1ULL << 16)
#define PRIVILEGE_UNNAMED17        (1ULL << 17)
#define PRIVILEGE_UNNAMED18        (1ULL << 18)
#define PRIVILEGE_UNNAMED19        (1ULL << 19)
#define PRIVILEGE_UNNAMED20        (1ULL << 20)
#define PRIVILEGE_UNNAMED21        (1ULL << 21)
#define PRIVILEGE_UNNAMED22        (1ULL << 22)
#define PRIVILEGE_UNNAMED23        (1ULL << 23)
#define PRIVILEGE_UNNAMED24        (1ULL << 24)
#define PRIVILEGE_UNNAMED25        (1ULL << 25)
#define PRIVILEGE_UNNAMED26        (1ULL << 26)
#define PRIVILEGE_UNNAMED27        (1ULL << 27)
#define PRIVILEGE_UNNAMED28        (1ULL << 28)
#define PRIVILEGE_UNNAMED29        (1ULL << 29)
#define PRIVILEGE_UNNAMED30        (1ULL << 30)
#define PRIVILEGE_SET_TIME         (1ULL << 31)
#define PRIVILEGE_ACCESS_ALL       (1ULL << 32)
#define PRIVILEGE_CHARACTER_DEVICE (1ULL << 33)
#define PRIVILEGE_BLOCK_DEVICE     (1ULL << 34)
#define PRIVILEGE_UNNAMED35        (1ULL << 35)
#define PRIVILEGE_UNNAMED36        (1ULL << 36)
#define PRIVILEGE_UNNAMED37        (1ULL << 37)
#define PRIVILEGE_UNNAMED38        (1ULL << 38)
#define PRIVILEGE_UNNAMED39        (1ULL << 39)
#define PRIVILEGE_UNNAMED40        (1ULL << 40)
#define PRIVILEGE_UNNAMED41        (1ULL << 41)
#define PRIVILEGE_UNNAMED42        (1ULL << 42)
#define PRIVILEGE_UNNAMED43        (1ULL << 43)
#define PRIVILEGE_UNNAMED44        (1ULL << 44)
#define PRIVILEGE_UNNAMED45        (1ULL << 45)
#define PRIVILEGE_UNNAMED46        (1ULL << 46)
#define PRIVILEGE_UNNAMED47        (1ULL << 47)
#define PRIVILEGE_UNNAMED48        (1ULL << 48)
#define PRIVILEGE_UNNAMED49        (1ULL << 49)
#define PRIVILEGE_UNNAMED50        (1ULL << 50)
#define PRIVILEGE_UNNAMED51        (1ULL << 51)
#define PRIVILEGE_UNNAMED52        (1ULL << 52)
#define PRIVILEGE_UNNAMED53        (1ULL << 53)
#define PRIVILEGE_UNNAMED54        (1ULL << 54)
#define PRIVILEGE_UNNAMED55        (1ULL << 55)
#define PRIVILEGE_UNNAMED56        (1ULL << 56)
#define PRIVILEGE_UNNAMED57        (1ULL << 57)
#define PRIVILEGE_UNNAMED58        (1ULL << 58)
#define PRIVILEGE_MANAGE_USERS     (1ULL << 59)
#define PRIVILEGE_PROCESS_CONTROL  (1ULL << 60)
#define PRIVILEGE_SET_PAGE_FILE    (1ULL << 61)
#define PRIVILEGE_POWER_CONTROL    (1ULL << 62)
#define PRIVILEGE_CHANGE_UID       (1ULL << 63)

#define ALL_PRIVILEGES 0xFFFFFFFFFFFFFFFFULL

typedef dword_t uid_t;

typedef enum
{
    USER_NAME_INFO,
    USER_PRIVILEGE_INFO,
} user_info_t;

sysret_t syscall_create_user(uid_t uid, const char *name, dword_t *password_hash, qword_t privileges);
sysret_t syscall_delete_user(uid_t uid);
sysret_t syscall_set_user_id(uid_t uid);
sysret_t syscall_revert_user(void);
sysret_t syscall_logon_user(uid_t uid, const char *password);
sysret_t syscall_query_user(uid_t uid, user_info_t info_type, void *buffer, dword_t size);

#endif
