forked from mheily/rooms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
roomManager.h
109 lines (94 loc) · 3.14 KB
/
roomManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* Copyright (c) 2016 Mark Heily <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include <map>
#include "namespaceImport.h"
#include "passwdEntry.h"
#include "roomOptions.h"
#include "setuidHelper.h"
#include "zfsPool.h"
extern FILE *logfile;
#include "logger.h"
#include "roomManagerUserOptions.h"
class RoomManager {
public:
RoomManager() {
useZfs = ZfsPool::detectZfs();
ownerUid = SetuidHelper::getActualUid();
ownerGid = ownerUid; // FIXME: bad assumption
ownerLogin = PasswdEntry(ownerUid).getLogin();
if (ownerLogin.length() == 0 || ownerLogin[0] == '.') {
throw std::runtime_error("invalid user name");
}
userOptionsPath = string(PasswdEntry(ownerUid).getHome()) + "/.room/config.json";
}
void bootstrap();
bool isBootstrapComplete();
void initUserRoomSpace();
bool doesBaseTemplateExist();
void createBaseTemplate();
void installRoom(const string& name, const string& archive, const RoomOptions& options);
void importRoom(const string& name);
void createRoom(const string& name);
void cloneRoom(const string& dest, const RoomOptions& roomOpt);
//void cloneRoomFromRemote(const string& name, const string& uri);
void receiveRoom(const string& name);
void destroyRoom(const string& name);
Room& getRoomByName(const string& name);
bool checkRoomExists(const string&);
void listRooms();
void parseConfig();
bool isVerbose() const {
return verbose;
}
void setVerbose(bool verbose = false) {
this->verbose = verbose;
fclose(logfile);
if (verbose) {
logfile = stderr;
} else {
logfile = fopen("/dev/null", "w");
}
}
const string& getTempdir() const {
static const string tempdir = "/room/.tmp";
return tempdir;
}
private:
std::map<std::string, Room*> rooms;
bool verbose = false;
bool useZfs;
uid_t ownerUid;
gid_t ownerGid;
RoomOptions roomOptions;
RoomManagerUserOptions userOptions;
string userOptionsPath;
string ownerLogin;
string baseTarball = "/var/cache/room-base.txz";
//string baseUri = "http://ftp.freebsd.org/pub/FreeBSD/releases/amd64/11.0-BETA1/base.txz";
string baseUri = "http://ftp.freebsd.org/pub/FreeBSD/releases/amd64/10.2-RELEASE/base.txz";
string roomDir = "/room";
void enumerateRooms();
void createRoomDir();
string getUserRoomDir();
string getUserRoomDataset();
string getRoomPathByName(const string& name);
// templates
string getBaseTemplateName();
int config_home_fd = -1; // descriptor opened to $HOME/.room
void openConfigHome();
void generateUserConfig();
};