Skip to content
API Documentation
BastionGuard™
SystemUser Class Reference
Inheritance diagram for SystemUser:

Public Member Functions

 SystemUser (string name)
void check_encrypted_dirs ()

Static Public Member Functions

static void query_users ()
static Gee.HashMap< string, SystemUser > read_users_from_file (string passwd_file)

Public Attributes

string name = ""
string password = ""
int uid = -1
int gid = -1
string user_info = ""
string home_path = ""
string shell_path = ""
string full_name = ""
string room_num = ""
string phone_work = ""
string phone_home = ""
string other_info = ""
bool has_encrypted_home = false
bool has_encrypted_private_dirs = false
Gee.ArrayList< string > encrypted_dirs = new Gee.ArrayList<string>()
Gee.ArrayList< string > encrypted_private_dirs = new Gee.ArrayList<string>()
bool is_selected = false

Static Public Attributes

static Gee.HashMap< string, SystemUser > all_users

Properties

static Gee.ArrayList< SystemUser > all_users_sorted [get]
bool is_system [get]
string group_names [get]

Static Private Member Functions

static ? SystemUser parse_line_passwd (string line)

Detailed Description

Definition at line 29 of file SystemUser.vala.

Constructor & Destructor Documentation

◆ SystemUser()

SystemUser.SystemUser ( string name)
inline

Definition at line 54 of file SystemUser.vala.

54 {
55 this.name = name;
56 }
string name

References name.

Referenced by parse_line_passwd(), and read_users_from_file().

Member Function Documentation

◆ check_encrypted_dirs()

void SystemUser.check_encrypted_dirs ( )
inline

Definition at line 146 of file SystemUser.vala.

146 {
147
148 // check encrypted home ------------------------------
149
150 string ecryptfs_mount_file = "/home/.ecryptfs/%s/.ecryptfs/Private.mnt".printf(name);
151
152 if (file_exists(ecryptfs_mount_file)){
153
154 string txt = file_read(ecryptfs_mount_file);
155
156 foreach(string line in txt.split("\n")){
157
158 string path = line.strip();
159
160 if (path.length == 0){ continue; }
161
162 if (path == home_path){
163 has_encrypted_home = true;
164 }
165
166 encrypted_dirs.add(path);
167 }
168 }
169
170 // check encrypted Private dirs --------------------------
171
172 ecryptfs_mount_file = "%s/.ecryptfs/Private.mnt".printf(home_path);
173
174 if (file_exists(ecryptfs_mount_file)){
175
176 string txt = file_read(ecryptfs_mount_file);
177
178 foreach(string line in txt.split("\n")){
179
180 string path = line.strip();
181
182 if (path.length == 0){ continue; }
183
184 if (path != home_path){
186 encrypted_private_dirs.add(path);
187 }
188
189 encrypted_dirs.add(path);
190 }
191 }
192 }
bool has_encrypted_private_dirs
bool has_encrypted_home
Gee.ArrayList< string > encrypted_dirs
Gee.ArrayList< string > encrypted_private_dirs
string home_path
bool file_exists(string file_path)
string? file_read(string file_path)

References encrypted_dirs, encrypted_private_dirs, TeeJee.FileSystem.file_exists(), TeeJee.FileSystem.file_read(), has_encrypted_home, has_encrypted_private_dirs, home_path, and name.

Referenced by parse_line_passwd().

◆ parse_line_passwd()

? SystemUser SystemUser.parse_line_passwd ( string line)
inlinestaticprivate

Definition at line 99 of file SystemUser.vala.

99 {
100
101 if ((line == null) || (line.length == 0)){
102 return null;
103 }
104
105 SystemUser user = null;
106
107 //teejee:x:504:504:Tony George:/home/teejee:/bin/bash
108 string[] fields = line.split(":");
109
110 if (fields.length == 7){
111 user = new SystemUser(fields[0].strip());
112 user.password = fields[1].strip();
113 user.uid = int.parse(fields[2].strip());
114 user.gid = int.parse(fields[3].strip());
115 user.user_info = fields[4].strip();
116 user.home_path = fields[5].strip();
117 user.shell_path = fields[6].strip();
118
119 string[] arr = user.user_info.split(",");
120 if (arr.length >= 1){
121 user.full_name = arr[0];
122 }
123 if (arr.length >= 2){
124 user.room_num = arr[1];
125 }
126 if (arr.length >= 3){
127 user.phone_work = arr[2];
128 }
129 if (arr.length >= 4){
130 user.phone_home = arr[3];
131 }
132 if (arr.length >= 5){
133 user.other_info = arr[4];
134 }
135
137 }
138 else{
139 log_error("'passwd' file contains a record with non-standard fields" + ": %d".printf(fields.length));
140 return null;
141 }
142
143 return user;
144 }
string user_info
SystemUser(string name)
void check_encrypted_dirs()
void log_error(string message, bool highlight=false, bool is_warning=false)

References check_encrypted_dirs(), TeeJee.Logging.log_error(), SystemUser(), and user_info.

Referenced by read_users_from_file().

◆ query_users()

void SystemUser.query_users ( )
inlinestatic

Definition at line 58 of file SystemUser.vala.

58 {
59
60 all_users = read_users_from_file("/etc/passwd");
61 }
static Gee.HashMap< string, SystemUser > all_users
static Gee.HashMap< string, SystemUser > read_users_from_file(string passwd_file)

References all_users, and read_users_from_file().

◆ read_users_from_file()

Gee.HashMap< string, SystemUser > SystemUser.read_users_from_file ( string passwd_file)
inlinestatic

Definition at line 74 of file SystemUser.vala.

74 {
75
76 var list = new Gee.HashMap<string,SystemUser>();
77
78 // read 'passwd' file ---------------------------------
79
80 string txt = file_read(passwd_file);
81
82 if (txt.length == 0){
83 return list;
84 }
85
86 foreach(string line in txt.split("\n")){
87 if ((line == null) || (line.length == 0)){
88 continue;
89 }
90 var user = parse_line_passwd(line);
91 if (user != null){
92 list[user.name] = user;
93 }
94 }
95
96 return list;
97 }
static ? SystemUser parse_line_passwd(string line)

References TeeJee.FileSystem.file_read(), parse_line_passwd(), and SystemUser().

Referenced by Main.detect_encrypted_dirs(), and query_users().

Member Data Documentation

◆ all_users

Gee.HashMap<string,SystemUser> SystemUser.all_users
static

Definition at line 52 of file SystemUser.vala.

Referenced by query_users().

◆ encrypted_dirs

Gee.ArrayList<string> SystemUser.encrypted_dirs = new Gee.ArrayList<string>()

Definition at line 47 of file SystemUser.vala.

Referenced by check_encrypted_dirs().

◆ encrypted_private_dirs

Gee.ArrayList<string> SystemUser.encrypted_private_dirs = new Gee.ArrayList<string>()

Definition at line 48 of file SystemUser.vala.

Referenced by check_encrypted_dirs().

◆ full_name

string SystemUser.full_name = ""

Definition at line 39 of file SystemUser.vala.

◆ gid

int SystemUser.gid = -1

Definition at line 34 of file SystemUser.vala.

◆ has_encrypted_home

bool SystemUser.has_encrypted_home = false

◆ has_encrypted_private_dirs

bool SystemUser.has_encrypted_private_dirs = false

Definition at line 46 of file SystemUser.vala.

Referenced by check_encrypted_dirs().

◆ home_path

string SystemUser.home_path = ""

◆ is_selected

bool SystemUser.is_selected = false

Definition at line 50 of file SystemUser.vala.

◆ name

string SystemUser.name = ""

◆ other_info

string SystemUser.other_info = ""

Definition at line 43 of file SystemUser.vala.

◆ password

string SystemUser.password = ""

Definition at line 32 of file SystemUser.vala.

◆ phone_home

string SystemUser.phone_home = ""

Definition at line 42 of file SystemUser.vala.

◆ phone_work

string SystemUser.phone_work = ""

Definition at line 41 of file SystemUser.vala.

◆ room_num

string SystemUser.room_num = ""

Definition at line 40 of file SystemUser.vala.

◆ shell_path

string SystemUser.shell_path = ""

Definition at line 37 of file SystemUser.vala.

◆ uid

int SystemUser.uid = -1

Definition at line 33 of file SystemUser.vala.

◆ user_info

string SystemUser.user_info = ""

Definition at line 35 of file SystemUser.vala.

Referenced by parse_line_passwd().

Property Documentation

◆ all_users_sorted

Gee.ArrayList<SystemUser> SystemUser.all_users_sorted
staticget

Definition at line 63 of file SystemUser.vala.

63 {
64 owned get {
65 var list = new Gee.ArrayList<SystemUser>();
66 foreach(var user in all_users.values) {
67 list.add(user);
68 }
69 list.sort((a,b) => { return strcmp(a.name, b.name); });
70 return list;
71 }
72 }

◆ group_names

string SystemUser.group_names
get

Definition at line 200 of file SystemUser.vala.

200 {
201 owned get {
202 return "";
203 }
204 }

◆ is_system

bool SystemUser.is_system
get

Definition at line 194 of file SystemUser.vala.

194 {
195 get {
196 return ((uid != 0) && (uid < 1000)) || (uid == 65534) || (name == "PinguyBuilder"); // 65534 - nobody
197 }
198 }

The documentation for this class was generated from the following file: