Merge lp:~donadigo/switchboard-plug-parental-controls/fix-home-config into lp:~elementary-pantheon/switchboard-plug-parental-controls/trunk
- fix-home-config
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Felipe Escoto |
Approved revision: | 230 |
Merged at revision: | 243 |
Proposed branch: | lp:~donadigo/switchboard-plug-parental-controls/fix-home-config |
Merge into: | lp:~elementary-pantheon/switchboard-plug-parental-controls/trunk |
Diff against target: |
819 lines (+193/-153) 18 files modified
CMakeLists.txt (+1/-0) data/CMakeLists.txt (+1/-0) data/daemon.conf (+13/-0) src/CMakeLists.txt (+1/-1) src/Widgets/GeneralBox.vala (+3/-3) src/client/CMakeLists.txt (+1/-1) src/daemon/CMakeLists.txt (+1/-1) src/daemon/Daemon.vala (+3/-3) src/daemon/IptablesHelper.vala (+7/-9) src/daemon/ProcessWatcher.vala (+3/-3) src/daemon/Server.vala (+11/-2) src/daemon/SessionHandler.vala (+17/-2) src/daemon/SessionManager.vala (+14/-5) src/daemon/UserConfig.vala (+64/-73) src/shared/Constants.vala.cmake (+2/-2) src/shared/PAM/Reader.vala (+8/-15) src/shared/PAM/Writer.vala (+40/-27) src/shared/Utils.vala (+3/-6) |
To merge this branch: | bzr merge lp:~donadigo/switchboard-plug-parental-controls/fix-home-config |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Felipe Escoto (community) | Approve | ||
Cody Garver (community) | Needs Fixing | ||
Review via email: mp+305406@code.launchpad.net |
Commit message
* Save config file to share/pantheon-
* Rename "Vars" to "Constants"
* Do not block apps when not active
* Restarting configuration is now more unified in the code
Description of the change
This branch fixes an issue where created user that was never logged in (and his home directory wasn't initiated) the config file wouldn't be created and the config wouldn't be applied. We now have a config file in data/ folder which will be installed in cmake_install_
There are also some minor changes like renaming "Vars" to "Constants" and fixing smaller bugs.
This is work for Loki Update.
- 230. By Adam Bieńkowski
-
Merge trunk; resolve conflicts; fix writing time restrictions logic to PAM configuration
Adam Bieńkowski (donadigo) wrote : | # |
Branch updated.
Felipe Escoto (philip.scott) wrote : | # |
Stepping to the right direction with this branch. I'm approving it so we can move on without it getting too large
Preview Diff
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2016-09-21 13:11:51 +0000 | |||
3 | +++ CMakeLists.txt 2016-12-09 17:18:29 +0000 | |||
4 | @@ -32,6 +32,7 @@ | |||
5 | 32 | 32 | ||
6 | 33 | # Configure file | 33 | # Configure file |
7 | 34 | configure_file (${CMAKE_SOURCE_DIR}/config.vala.cmake ${CMAKE_BINARY_DIR}/src/config.vala) | 34 | configure_file (${CMAKE_SOURCE_DIR}/config.vala.cmake ${CMAKE_BINARY_DIR}/src/config.vala) |
8 | 35 | configure_file (${CMAKE_SOURCE_DIR}/src/shared/Constants.vala.cmake ${CMAKE_SOURCE_DIR}/src/shared/Constants.vala) | ||
9 | 35 | add_definitions (-DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\") | 36 | add_definitions (-DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\") |
10 | 36 | 37 | ||
11 | 37 | option (ENABLE_DAEMON_STARTUP "Enable starting daemon on system startup" TRUE) | 38 | option (ENABLE_DAEMON_STARTUP "Enable starting daemon on system startup" TRUE) |
12 | 38 | 39 | ||
13 | === modified file 'data/CMakeLists.txt' | |||
14 | --- data/CMakeLists.txt 2016-09-09 14:51:34 +0000 | |||
15 | +++ data/CMakeLists.txt 2016-12-09 17:18:29 +0000 | |||
16 | @@ -1,6 +1,7 @@ | |||
17 | 1 | configure_file (org.pantheon.switchboard.parental-controls.policy.cmake ${CMAKE_CURRENT_BINARY_DIR}/data/org.pantheon.switchboard.parental-controls.policy) | 1 | configure_file (org.pantheon.switchboard.parental-controls.policy.cmake ${CMAKE_CURRENT_BINARY_DIR}/data/org.pantheon.switchboard.parental-controls.policy) |
18 | 2 | configure_file (org.pantheon.ParentalControls.service.cmake ${CMAKE_CURRENT_BINARY_DIR}/org.pantheon.ParentalControls.service) | 2 | configure_file (org.pantheon.ParentalControls.service.cmake ${CMAKE_CURRENT_BINARY_DIR}/org.pantheon.ParentalControls.service) |
19 | 3 | 3 | ||
20 | 4 | install (FILES daemon.conf DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pantheon-parental-controls) | ||
21 | 4 | install (FILES ${CMAKE_CURRENT_BINARY_DIR}/data/org.pantheon.switchboard.parental-controls.policy DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/polkit-1/actions/) | 5 | install (FILES ${CMAKE_CURRENT_BINARY_DIR}/data/org.pantheon.switchboard.parental-controls.policy DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/polkit-1/actions/) |
22 | 5 | install (FILES ${CMAKE_CURRENT_BINARY_DIR}/org.pantheon.ParentalControls.service DESTINATION share/dbus-1/system-services) | 6 | install (FILES ${CMAKE_CURRENT_BINARY_DIR}/org.pantheon.ParentalControls.service DESTINATION share/dbus-1/system-services) |
23 | 6 | install (FILES org.pantheon.ParentalControls.conf DESTINATION /etc/dbus-1/system.d) | 7 | install (FILES org.pantheon.ParentalControls.conf DESTINATION /etc/dbus-1/system.d) |
24 | 7 | 8 | ||
25 | === added file 'data/daemon.conf' | |||
26 | --- data/daemon.conf 1970-01-01 00:00:00 +0000 | |||
27 | +++ data/daemon.conf 2016-12-09 17:18:29 +0000 | |||
28 | @@ -0,0 +1,13 @@ | |||
29 | 1 | # This is main configuration file for pantheon parental controls daemon. | ||
30 | 2 | # It is used to restrict users and control whethever they can or cannot | ||
31 | 3 | # access a specified service. | ||
32 | 4 | # | ||
33 | 5 | # a simple example of how a configuration for user "username" would look like: | ||
34 | 6 | # [username] | ||
35 | 7 | # Active=false | ||
36 | 8 | # Targets=/path/to/executable1;/path/to/executable2; | ||
37 | 9 | # BlockUrls=website1.com;website2.com | ||
38 | 10 | # Admin=false | ||
39 | 11 | # | ||
40 | 12 | # End of example file. | ||
41 | 13 | # | ||
42 | 0 | \ No newline at end of file | 14 | \ No newline at end of file |
43 | 1 | 15 | ||
44 | === modified file 'src/CMakeLists.txt' | |||
45 | --- src/CMakeLists.txt 2016-10-25 21:35:37 +0000 | |||
46 | +++ src/CMakeLists.txt 2016-12-09 17:18:29 +0000 | |||
47 | @@ -22,7 +22,7 @@ | |||
48 | 22 | Widgets/AppsBox.vala | 22 | Widgets/AppsBox.vala |
49 | 23 | Widgets/AppChooser.vala | 23 | Widgets/AppChooser.vala |
50 | 24 | Widgets/WeekSpinBox.vala | 24 | Widgets/WeekSpinBox.vala |
52 | 25 | shared/Vars.vala | 25 | shared/Constants.vala |
53 | 26 | shared/Utils.vala | 26 | shared/Utils.vala |
54 | 27 | shared/PAM/Token.vala | 27 | shared/PAM/Token.vala |
55 | 28 | shared/PAM/Reader.vala | 28 | shared/PAM/Reader.vala |
56 | 29 | 29 | ||
57 | === modified file 'src/Widgets/GeneralBox.vala' | |||
58 | --- src/Widgets/GeneralBox.vala 2016-09-27 20:32:53 +0000 | |||
59 | +++ src/Widgets/GeneralBox.vala 2016-12-09 17:18:29 +0000 | |||
60 | @@ -38,7 +38,7 @@ | |||
61 | 38 | 38 | ||
62 | 39 | public GeneralBox (Act.User user) { | 39 | public GeneralBox (Act.User user) { |
63 | 40 | this.user = user; | 40 | this.user = user; |
65 | 41 | plank_conf_file_path = Path.build_filename (user.get_home_dir (), Vars.PLANK_CONF_DIR); | 41 | plank_conf_file_path = Path.build_filename (user.get_home_dir (), Constants.PLANK_CONF_DIR); |
66 | 42 | 42 | ||
67 | 43 | dock_btn.notify["active"].connect (on_dock_btn_activate); | 43 | dock_btn.notify["active"].connect (on_dock_btn_activate); |
68 | 44 | print_btn.notify["active"].connect (on_print_conf_activate); | 44 | print_btn.notify["active"].connect (on_print_conf_activate); |
69 | @@ -136,7 +136,7 @@ | |||
70 | 136 | } | 136 | } |
71 | 137 | 137 | ||
72 | 138 | private void load_restrictions () { | 138 | private void load_restrictions () { |
74 | 139 | var token = PAM.Reader.get_token_for_user (Vars.PAM_TIME_CONF_PATH, user.get_user_name ()); | 139 | var token = PAM.Reader.get_token_for_user (Constants.PAM_TIME_CONF_PATH, user.get_user_name ()); |
75 | 140 | if (token == null) { | 140 | if (token == null) { |
76 | 141 | return; | 141 | return; |
77 | 142 | } | 142 | } |
78 | @@ -204,7 +204,7 @@ | |||
79 | 204 | string[] users = { user.get_user_name () }; | 204 | string[] users = { user.get_user_name () }; |
80 | 205 | 205 | ||
81 | 206 | try { | 206 | try { |
83 | 207 | CupsPkHelper? helper = Bus.get_proxy_sync (BusType.SYSTEM, Vars.CUPS_PK_HELPER_IFACE, "/"); | 207 | CupsPkHelper? helper = Bus.get_proxy_sync (BusType.SYSTEM, Constants.CUPS_PK_HELPER_IFACE, "/"); |
84 | 208 | if (helper == null) { | 208 | if (helper == null) { |
85 | 209 | return; | 209 | return; |
86 | 210 | } | 210 | } |
87 | 211 | 211 | ||
88 | === modified file 'src/client/CMakeLists.txt' | |||
89 | --- src/client/CMakeLists.txt 2016-08-30 17:40:51 +0000 | |||
90 | +++ src/client/CMakeLists.txt 2016-12-09 17:18:29 +0000 | |||
91 | @@ -9,7 +9,7 @@ | |||
92 | 9 | vala_precompile (VALA_C ${CLIENT_EXEC_NAME} | 9 | vala_precompile (VALA_C ${CLIENT_EXEC_NAME} |
93 | 10 | Client.vala | 10 | Client.vala |
94 | 11 | AppUnavailableDialog.vala | 11 | AppUnavailableDialog.vala |
96 | 12 | ${CMAKE_SOURCE_DIR}/src/shared/Vars.vala | 12 | ${CMAKE_SOURCE_DIR}/src/shared/Constants.vala |
97 | 13 | ${CMAKE_SOURCE_DIR}/src/shared/Utils.vala | 13 | ${CMAKE_SOURCE_DIR}/src/shared/Utils.vala |
98 | 14 | PACKAGES | 14 | PACKAGES |
99 | 15 | posix | 15 | posix |
100 | 16 | 16 | ||
101 | === modified file 'src/daemon/CMakeLists.txt' | |||
102 | --- src/daemon/CMakeLists.txt 2016-08-30 17:40:51 +0000 | |||
103 | +++ src/daemon/CMakeLists.txt 2016-12-09 17:18:29 +0000 | |||
104 | @@ -18,7 +18,7 @@ | |||
105 | 18 | Interfaces.vala | 18 | Interfaces.vala |
106 | 19 | UserConfig.vala | 19 | UserConfig.vala |
107 | 20 | Server.vala | 20 | Server.vala |
109 | 21 | ${CMAKE_SOURCE_DIR}/src/shared/Vars.vala | 21 | ${CMAKE_SOURCE_DIR}/src/shared/Constants.vala |
110 | 22 | ${CMAKE_SOURCE_DIR}/src/shared/Utils.vala | 22 | ${CMAKE_SOURCE_DIR}/src/shared/Utils.vala |
111 | 23 | ${CMAKE_SOURCE_DIR}/src/shared/PAM/Token.vala | 23 | ${CMAKE_SOURCE_DIR}/src/shared/PAM/Token.vala |
112 | 24 | ${CMAKE_SOURCE_DIR}/src/shared/PAM/Reader.vala | 24 | ${CMAKE_SOURCE_DIR}/src/shared/PAM/Reader.vala |
113 | 25 | 25 | ||
114 | === modified file 'src/daemon/Daemon.vala' | |||
115 | --- src/daemon/Daemon.vala 2016-08-29 22:25:35 +0000 | |||
116 | +++ src/daemon/Daemon.vala 2016-12-09 17:18:29 +0000 | |||
117 | @@ -64,7 +64,7 @@ | |||
118 | 64 | 64 | ||
119 | 65 | private void on_bus_acquired (DBusConnection connection) { | 65 | private void on_bus_acquired (DBusConnection connection) { |
120 | 66 | try { | 66 | try { |
122 | 67 | connection.register_object (Vars.PARENTAL_CONTROLS_OBJECT_PATH, Server.get_default ()); | 67 | connection.register_object (Constants.PARENTAL_CONTROLS_OBJECT_PATH, Server.get_default ()); |
123 | 68 | } catch (IOError e) { | 68 | } catch (IOError e) { |
124 | 69 | warning ("%s\n", e.message); | 69 | warning ("%s\n", e.message); |
125 | 70 | } | 70 | } |
126 | @@ -75,12 +75,12 @@ | |||
127 | 75 | return; | 75 | return; |
128 | 76 | } | 76 | } |
129 | 77 | 77 | ||
131 | 78 | Bus.own_name (BusType.SYSTEM, Vars.PARENTAL_CONTROLS_IFACE, BusNameOwnerFlags.REPLACE, | 78 | Bus.own_name (BusType.SYSTEM, Constants.PARENTAL_CONTROLS_IFACE, BusNameOwnerFlags.REPLACE, |
132 | 79 | on_bus_acquired, | 79 | on_bus_acquired, |
133 | 80 | () => {}, | 80 | () => {}, |
134 | 81 | on_bus_lost); | 81 | on_bus_lost); |
135 | 82 | 82 | ||
137 | 83 | session_manager = new SessionManager (); | 83 | session_manager = SessionManager.get_default (); |
138 | 84 | session_manager.start (); | 84 | session_manager.start (); |
139 | 85 | } | 85 | } |
140 | 86 | 86 | ||
141 | 87 | 87 | ||
142 | === modified file 'src/daemon/IptablesHelper.vala' | |||
143 | --- src/daemon/IptablesHelper.vala 2016-08-30 17:28:55 +0000 | |||
144 | +++ src/daemon/IptablesHelper.vala 2016-12-09 17:18:29 +0000 | |||
145 | @@ -27,7 +27,6 @@ | |||
146 | 27 | 27 | ||
147 | 28 | private UserConfig config; | 28 | private UserConfig config; |
148 | 29 | private string[] current_urls; | 29 | private string[] current_urls; |
149 | 30 | private ulong changed_signal_id; | ||
150 | 31 | 30 | ||
151 | 32 | public static bool get_can_start () { | 31 | public static bool get_can_start () { |
152 | 33 | return Environment.find_program_in_path (IPTABLES_EXEC) != null; | 32 | return Environment.find_program_in_path (IPTABLES_EXEC) != null; |
153 | @@ -40,18 +39,17 @@ | |||
154 | 40 | public void start () { | 39 | public void start () { |
155 | 41 | this.current_urls = config.get_block_urls (); | 40 | this.current_urls = config.get_block_urls (); |
156 | 42 | add_rules (); | 41 | add_rules (); |
164 | 43 | 42 | } | |
165 | 44 | changed_signal_id = config.changed.connect (() => { | 43 | |
166 | 45 | remove_rules (); | 44 | public void restart () { |
167 | 46 | 45 | remove_rules (); | |
168 | 47 | current_urls = config.get_block_urls (); | 46 | |
169 | 48 | add_rules (); | 47 | current_urls = config.get_block_urls (); |
170 | 49 | }); | 48 | add_rules (); |
171 | 50 | } | 49 | } |
172 | 51 | 50 | ||
173 | 52 | public void stop () { | 51 | public void stop () { |
174 | 53 | remove_rules (); | 52 | remove_rules (); |
175 | 54 | disconnect (changed_signal_id); | ||
176 | 55 | } | 53 | } |
177 | 56 | 54 | ||
178 | 57 | private void add_rules () { | 55 | private void add_rules () { |
179 | 58 | 56 | ||
180 | === modified file 'src/daemon/ProcessWatcher.vala' | |||
181 | --- src/daemon/ProcessWatcher.vala 2016-10-25 21:35:37 +0000 | |||
182 | +++ src/daemon/ProcessWatcher.vala 2016-12-09 17:18:29 +0000 | |||
183 | @@ -42,7 +42,7 @@ | |||
184 | 42 | } | 42 | } |
185 | 43 | 43 | ||
186 | 44 | private void handle_pid (int pid) { | 44 | private void handle_pid (int pid) { |
188 | 45 | if (config == null) { | 45 | if (config == null || !config.get_active ()) { |
189 | 46 | return; | 46 | return; |
190 | 47 | } | 47 | } |
191 | 48 | 48 | ||
192 | @@ -86,7 +86,7 @@ | |||
193 | 86 | try { | 86 | try { |
194 | 87 | var unix_user = new Polkit.UnixUser.for_name (config.username); | 87 | var unix_user = new Polkit.UnixUser.for_name (config.username); |
195 | 88 | var result = authority.check_authorization_sync (new Polkit.UnixProcess.for_owner (client_pid, 0, unix_user.get_uid ()), | 88 | var result = authority.check_authorization_sync (new Polkit.UnixProcess.for_owner (client_pid, 0, unix_user.get_uid ()), |
197 | 89 | Vars.PARENTAL_CONTROLS_ACTION_ID, | 89 | Constants.PARENTAL_CONTROLS_ACTION_ID, |
198 | 90 | null, | 90 | null, |
199 | 91 | Polkit.CheckAuthorizationFlags.NONE); | 91 | Polkit.CheckAuthorizationFlags.NONE); |
200 | 92 | if (result.get_is_authorized ()) { | 92 | if (result.get_is_authorized ()) { |
201 | @@ -100,7 +100,7 @@ | |||
202 | 100 | server.disconnect (signal_id); | 100 | server.disconnect (signal_id); |
203 | 101 | }); | 101 | }); |
204 | 102 | 102 | ||
206 | 103 | server.app_authorize (config.username, executable, Vars.PARENTAL_CONTROLS_ACTION_ID); | 103 | server.app_authorize (config.username, executable, Constants.PARENTAL_CONTROLS_ACTION_ID); |
207 | 104 | } else { | 104 | } else { |
208 | 105 | server.show_app_unavailable (executable); | 105 | server.show_app_unavailable (executable); |
209 | 106 | } | 106 | } |
210 | 107 | 107 | ||
211 | === modified file 'src/daemon/Server.vala' | |||
212 | --- src/daemon/Server.vala 2016-10-25 21:35:37 +0000 | |||
213 | +++ src/daemon/Server.vala 2016-12-09 17:18:29 +0000 | |||
214 | @@ -60,6 +60,8 @@ | |||
215 | 60 | } | 60 | } |
216 | 61 | 61 | ||
217 | 62 | UserConfig.init (); | 62 | UserConfig.init (); |
218 | 63 | |||
219 | 64 | config_changed.connect (on_config_changed); | ||
220 | 63 | } | 65 | } |
221 | 64 | 66 | ||
222 | 65 | [DBus (visible = false)] | 67 | [DBus (visible = false)] |
223 | @@ -69,7 +71,7 @@ | |||
224 | 69 | public signal void launch (string[] args); | 71 | public signal void launch (string[] args); |
225 | 70 | public signal void show_app_unavailable (string path); | 72 | public signal void show_app_unavailable (string path); |
226 | 71 | public signal void show_timeout (int hours, int minutes); | 73 | public signal void show_timeout (int hours, int minutes); |
228 | 72 | public signal void user_config_changed (string username); | 74 | public signal void config_changed (); |
229 | 73 | 75 | ||
230 | 74 | public void end_app_authorization (BusName sender) { | 76 | public void end_app_authorization (BusName sender) { |
231 | 75 | uint32 pid = get_pid_from_sender (sender); | 77 | uint32 pid = get_pid_from_sender (sender); |
232 | @@ -188,6 +190,13 @@ | |||
233 | 188 | return config.get_admin (); | 190 | return config.get_admin (); |
234 | 189 | } | 191 | } |
235 | 190 | 192 | ||
236 | 193 | private void on_config_changed () { | ||
237 | 194 | var current_handler = SessionManager.get_default ().current_handler; | ||
238 | 195 | if (current_handler != null) { | ||
239 | 196 | current_handler.update (); | ||
240 | 197 | } | ||
241 | 198 | } | ||
242 | 199 | |||
243 | 191 | private void ensure_pam_lightdm_enabled () { | 200 | private void ensure_pam_lightdm_enabled () { |
244 | 192 | string path = "/etc/pam.d/lightdm"; | 201 | string path = "/etc/pam.d/lightdm"; |
245 | 193 | 202 | ||
246 | @@ -231,7 +240,7 @@ | |||
247 | 231 | 240 | ||
248 | 232 | try { | 241 | try { |
249 | 233 | var authority = Polkit.Authority.get_sync (null); | 242 | var authority = Polkit.Authority.get_sync (null); |
251 | 234 | var auth_result = authority.check_authorization_sync (subject, Vars.PARENTAL_CONTROLS_ACTION_ID, null, Polkit.CheckAuthorizationFlags.NONE); | 243 | var auth_result = authority.check_authorization_sync (subject, Constants.PARENTAL_CONTROLS_ACTION_ID, null, Polkit.CheckAuthorizationFlags.NONE); |
252 | 235 | return auth_result.get_is_authorized (); | 244 | return auth_result.get_is_authorized (); |
253 | 236 | } catch (Error e) { | 245 | } catch (Error e) { |
254 | 237 | warning (e.message); | 246 | warning (e.message); |
255 | 238 | 247 | ||
256 | === modified file 'src/daemon/SessionHandler.vala' | |||
257 | --- src/daemon/SessionHandler.vala 2016-08-30 17:28:55 +0000 | |||
258 | +++ src/daemon/SessionHandler.vala 2016-12-09 17:18:29 +0000 | |||
259 | @@ -43,7 +43,7 @@ | |||
260 | 43 | 43 | ||
261 | 44 | iptables_helper = new IptablesHelper (config); | 44 | iptables_helper = new IptablesHelper (config); |
262 | 45 | 45 | ||
264 | 46 | var token = PAM.Reader.get_token_for_user (Vars.PAM_TIME_CONF_PATH, session.name); | 46 | var token = PAM.Reader.get_token_for_user (Constants.PAM_TIME_CONF_PATH, session.name); |
265 | 47 | if (token != null) { | 47 | if (token != null) { |
266 | 48 | timer = new Timer (token); | 48 | timer = new Timer (token); |
267 | 49 | timer.terminate.connect (() => { | 49 | timer.terminate.connect (() => { |
268 | @@ -53,7 +53,7 @@ | |||
269 | 53 | warning (e.message); | 53 | warning (e.message); |
270 | 54 | } | 54 | } |
271 | 55 | }); | 55 | }); |
273 | 56 | } | 56 | } |
274 | 57 | } | 57 | } |
275 | 58 | 58 | ||
276 | 59 | public string get_id () { | 59 | public string get_id () { |
277 | @@ -78,6 +78,21 @@ | |||
278 | 78 | } | 78 | } |
279 | 79 | } | 79 | } |
280 | 80 | 80 | ||
281 | 81 | public void update () { | ||
282 | 82 | if (!config.get_active ()) { | ||
283 | 83 | iptables_helper.stop (); | ||
284 | 84 | if (timer != null) { | ||
285 | 85 | timer.stop (); | ||
286 | 86 | } | ||
287 | 87 | |||
288 | 88 | return; | ||
289 | 89 | } | ||
290 | 90 | |||
291 | 91 | if (IptablesHelper.get_can_start ()) { | ||
292 | 92 | iptables_helper.restart (); | ||
293 | 93 | } | ||
294 | 94 | } | ||
295 | 95 | |||
296 | 81 | public void stop () { | 96 | public void stop () { |
297 | 82 | iptables_helper.stop (); | 97 | iptables_helper.stop (); |
298 | 83 | if (timer != null) { | 98 | if (timer != null) { |
299 | 84 | 99 | ||
300 | === modified file 'src/daemon/SessionManager.vala' | |||
301 | --- src/daemon/SessionManager.vala 2016-08-30 17:28:55 +0000 | |||
302 | +++ src/daemon/SessionManager.vala 2016-12-09 17:18:29 +0000 | |||
303 | @@ -22,16 +22,25 @@ | |||
304 | 22 | 22 | ||
305 | 23 | namespace PC.Daemon { | 23 | namespace PC.Daemon { |
306 | 24 | public class SessionManager : Object { | 24 | public class SessionManager : Object { |
308 | 25 | private SessionHandler? current_handler = null; | 25 | public SessionHandler? current_handler = null; |
309 | 26 | private IManager? manager = null; | 26 | private IManager? manager = null; |
310 | 27 | private DBusConnection? conn = null; | 27 | private DBusConnection? conn = null; |
311 | 28 | private ProcessWatcher pwatcher; | 28 | private ProcessWatcher pwatcher; |
312 | 29 | 29 | ||
313 | 30 | private uint[] signal_ids; | 30 | private uint[] signal_ids; |
314 | 31 | 31 | ||
315 | 32 | private static SessionManager? instance = null; | ||
316 | 33 | public static SessionManager get_default () { | ||
317 | 34 | if (instance == null) { | ||
318 | 35 | instance = new SessionManager (); | ||
319 | 36 | } | ||
320 | 37 | |||
321 | 38 | return instance; | ||
322 | 39 | } | ||
323 | 40 | |||
324 | 32 | public SessionManager () { | 41 | public SessionManager () { |
325 | 33 | try { | 42 | try { |
327 | 34 | manager = Bus.get_proxy_sync (BusType.SYSTEM, Vars.LOGIN_IFACE, Vars.LOGIN_OBJECT_PATH); | 43 | manager = Bus.get_proxy_sync (BusType.SYSTEM, Constants.LOGIN_IFACE, Constants.LOGIN_OBJECT_PATH); |
328 | 35 | conn = Bus.get_sync (BusType.SYSTEM, null); | 44 | conn = Bus.get_sync (BusType.SYSTEM, null); |
329 | 36 | } catch (IOError e) { | 45 | } catch (IOError e) { |
330 | 37 | warning ("%s\n", e.message); | 46 | warning ("%s\n", e.message); |
331 | @@ -52,7 +61,7 @@ | |||
332 | 52 | try { | 61 | try { |
333 | 53 | foreach (SeatStruct seat_s in manager.list_seats ()) { | 62 | foreach (SeatStruct seat_s in manager.list_seats ()) { |
334 | 54 | signal_ids += conn.signal_subscribe (null, | 63 | signal_ids += conn.signal_subscribe (null, |
336 | 55 | Vars.DBUS_PROPERTIES_IFACE, | 64 | Constants.DBUS_PROPERTIES_IFACE, |
337 | 56 | "PropertiesChanged", | 65 | "PropertiesChanged", |
338 | 57 | seat_s.object_path, | 66 | seat_s.object_path, |
339 | 58 | null, | 67 | null, |
340 | @@ -78,7 +87,7 @@ | |||
341 | 78 | try { | 87 | try { |
342 | 79 | var structs = manager.list_sessions (); | 88 | var structs = manager.list_sessions (); |
343 | 80 | foreach (SessionStruct session_s in structs) { | 89 | foreach (SessionStruct session_s in structs) { |
345 | 81 | ISession? session = Bus.get_proxy_sync (BusType.SYSTEM, Vars.LOGIN_IFACE, session_s.object_path); | 90 | ISession? session = Bus.get_proxy_sync (BusType.SYSTEM, Constants.LOGIN_IFACE, session_s.object_path); |
346 | 82 | if (session != null && session.active) { | 91 | if (session != null && session.active) { |
347 | 83 | return session; | 92 | return session; |
348 | 84 | } | 93 | } |
349 | @@ -100,7 +109,7 @@ | |||
350 | 100 | 109 | ||
351 | 101 | if (session != null && | 110 | if (session != null && |
352 | 102 | session.name != null && | 111 | session.name != null && |
354 | 103 | !(session.name in Vars.DAEMON_IGNORED_USERS)) { | 112 | !(session.name in Constants.DAEMON_IGNORED_USERS)) { |
355 | 104 | current_handler = new SessionHandler (session); | 113 | current_handler = new SessionHandler (session); |
356 | 105 | current_handler.start (); | 114 | current_handler.start (); |
357 | 106 | pwatcher.set_config (current_handler.get_config ()); | 115 | pwatcher.set_config (current_handler.get_config ()); |
358 | 107 | 116 | ||
359 | === modified file 'src/daemon/UserConfig.vala' | |||
360 | --- src/daemon/UserConfig.vala 2016-08-30 17:28:55 +0000 | |||
361 | +++ src/daemon/UserConfig.vala 2016-12-09 17:18:29 +0000 | |||
362 | @@ -23,11 +23,8 @@ | |||
363 | 23 | namespace PC.Daemon { | 23 | namespace PC.Daemon { |
364 | 24 | public class UserConfig : Object { | 24 | public class UserConfig : Object { |
365 | 25 | public string username; | 25 | public string username; |
371 | 26 | public signal void changed (); | 26 | |
372 | 27 | 27 | private static KeyFile key; | |
368 | 28 | private KeyFile key; | ||
369 | 29 | private string config_path; | ||
370 | 30 | |||
373 | 31 | private static List<UserConfig> config_list; | 28 | private static List<UserConfig> config_list; |
374 | 32 | 29 | ||
375 | 33 | public static UserConfig? get_for_username (string username, bool create) { | 30 | public static UserConfig? get_for_username (string username, bool create) { |
376 | @@ -38,9 +35,9 @@ | |||
377 | 38 | } | 35 | } |
378 | 39 | 36 | ||
379 | 40 | if (create) { | 37 | if (create) { |
383 | 41 | return create_for_username (username); | 38 | return create_for_username (username); |
384 | 42 | } | 39 | } |
385 | 43 | 40 | ||
386 | 44 | return null; | 41 | return null; |
387 | 45 | } | 42 | } |
388 | 46 | 43 | ||
389 | @@ -51,84 +48,96 @@ | |||
390 | 51 | public static void init () { | 48 | public static void init () { |
391 | 52 | config_list = new List<UserConfig> (); | 49 | config_list = new List<UserConfig> (); |
392 | 53 | 50 | ||
393 | 51 | key = new KeyFile (); | ||
394 | 52 | key.set_list_separator (';'); | ||
395 | 53 | |||
396 | 54 | if (!init_config_file ()) { | ||
397 | 55 | return; | ||
398 | 56 | } | ||
399 | 57 | |||
400 | 58 | try { | ||
401 | 59 | key.load_from_file (Constants.DAEMON_CONF_FILE, KeyFileFlags.KEEP_COMMENTS | KeyFileFlags.KEEP_TRANSLATIONS); | ||
402 | 60 | } catch (KeyFileError e) { | ||
403 | 61 | warning (e.message); | ||
404 | 62 | } catch (FileError e) { | ||
405 | 63 | warning (e.message); | ||
406 | 64 | } | ||
407 | 65 | |||
408 | 54 | foreach (Act.User user in Utils.get_usermanager ().list_users ()) { | 66 | foreach (Act.User user in Utils.get_usermanager ().list_users ()) { |
411 | 55 | string config_path = Utils.build_daemon_conf_path (user); | 67 | string username = user.get_user_name (); |
412 | 56 | if (!FileUtils.test (config_path, FileTest.IS_REGULAR)) { | 68 | if (!key.has_group (username)) { |
413 | 57 | continue; | 69 | continue; |
414 | 58 | } | 70 | } |
415 | 59 | 71 | ||
431 | 60 | var key = new KeyFile (); | 72 | var user_config = new UserConfig (username); |
417 | 61 | key.set_list_separator (';'); | ||
418 | 62 | try { | ||
419 | 63 | if (!key.load_from_file (config_path, KeyFileFlags.NONE)) { | ||
420 | 64 | continue; | ||
421 | 65 | } | ||
422 | 66 | } catch (KeyFileError e) { | ||
423 | 67 | warning (e.message); | ||
424 | 68 | continue; | ||
425 | 69 | } catch (FileError e) { | ||
426 | 70 | warning (e.message); | ||
427 | 71 | continue; | ||
428 | 72 | } | ||
429 | 73 | |||
430 | 74 | var user_config = new UserConfig (config_path, user.get_user_name (), key); | ||
432 | 75 | config_list.append (user_config); | 73 | config_list.append (user_config); |
433 | 76 | } | 74 | } |
434 | 77 | } | 75 | } |
435 | 78 | 76 | ||
436 | 77 | private static bool init_config_file () { | ||
437 | 78 | var file = File.new_for_path (Constants.DAEMON_CONF_FILE); | ||
438 | 79 | if (!file.query_exists ()) { | ||
439 | 80 | critical ("Could not found daemon config file: %s does not exist".printf (file.get_path ())); | ||
440 | 81 | return false; | ||
441 | 82 | } | ||
442 | 83 | |||
443 | 84 | try { | ||
444 | 85 | var monitor = file.monitor (FileMonitorFlags.NONE, null); | ||
445 | 86 | monitor.changed.connect ((src, dest, event) => { | ||
446 | 87 | if (event == FileMonitorEvent.CHANGES_DONE_HINT) { | ||
447 | 88 | foreach (UserConfig config in config_list) { | ||
448 | 89 | config.update_key (); | ||
449 | 90 | } | ||
450 | 91 | |||
451 | 92 | Server.get_default ().config_changed (); | ||
452 | 93 | } | ||
453 | 94 | }); | ||
454 | 95 | } catch (Error e) { | ||
455 | 96 | warning (e.message); | ||
456 | 97 | } | ||
457 | 98 | |||
458 | 99 | return true; | ||
459 | 100 | } | ||
460 | 101 | |||
461 | 79 | private static UserConfig? create_for_username (string username) { | 102 | private static UserConfig? create_for_username (string username) { |
462 | 80 | var user = Utils.get_usermanager ().get_user (username); | 103 | var user = Utils.get_usermanager ().get_user (username); |
463 | 81 | if (user == null) { | 104 | if (user == null) { |
464 | 82 | return null; | 105 | return null; |
465 | 83 | } | 106 | } |
466 | 84 | 107 | ||
480 | 85 | string config_path = Utils.build_daemon_conf_path (user); | 108 | var config = new UserConfig (username); |
481 | 86 | var file = File.new_for_path (config_path); | 109 | config.set_active (false); |
469 | 87 | try { | ||
470 | 88 | file.create (FileCreateFlags.PRIVATE); | ||
471 | 89 | } catch (FileError e) { | ||
472 | 90 | warning (e.message); | ||
473 | 91 | return null; | ||
474 | 92 | } catch (Error e) { | ||
475 | 93 | warning (e.message); | ||
476 | 94 | return null; | ||
477 | 95 | } | ||
478 | 96 | |||
479 | 97 | var config = new UserConfig (config_path, username, new KeyFile ()); | ||
482 | 98 | config_list.append (config); | 110 | config_list.append (config); |
483 | 99 | return config; | 111 | return config; |
484 | 100 | } | 112 | } |
485 | 101 | 113 | ||
487 | 102 | private UserConfig (string config_path, string username, KeyFile key) { | 114 | private UserConfig (string username) { |
488 | 103 | this.username = username; | 115 | this.username = username; |
489 | 104 | this.key = key; | ||
490 | 105 | this.config_path = config_path; | ||
491 | 106 | monitor_file (); | ||
492 | 107 | } | 116 | } |
493 | 108 | 117 | ||
494 | 109 | public void set_active (bool active) { | 118 | public void set_active (bool active) { |
496 | 110 | key.set_boolean (Vars.DAEMON_GROUP, Vars.DAEMON_KEY_ACTIVE, active); | 119 | key.set_boolean (username, Constants.DAEMON_KEY_ACTIVE, active); |
497 | 111 | save (); | 120 | save (); |
498 | 112 | } | 121 | } |
499 | 113 | 122 | ||
500 | 114 | public void set_targets (string[] targets) { | 123 | public void set_targets (string[] targets) { |
502 | 115 | key.set_string_list (Vars.DAEMON_GROUP, Vars.DAEMON_KEY_TARGETS, targets); | 124 | key.set_string_list (username, Constants.DAEMON_KEY_TARGETS, targets); |
503 | 116 | save (); | 125 | save (); |
504 | 117 | } | 126 | } |
505 | 118 | 127 | ||
506 | 119 | public void set_block_urls (string[] block_urls) { | 128 | public void set_block_urls (string[] block_urls) { |
508 | 120 | key.set_string_list (Vars.DAEMON_GROUP, Vars.DAEMON_KEY_BLOCK_URLS, block_urls); | 129 | key.set_string_list (username, Constants.DAEMON_KEY_BLOCK_URLS, block_urls); |
509 | 121 | save (); | 130 | save (); |
510 | 122 | } | 131 | } |
511 | 123 | 132 | ||
512 | 124 | public void set_admin (bool admin) { | 133 | public void set_admin (bool admin) { |
514 | 125 | key.set_boolean (Vars.DAEMON_GROUP, Vars.DAEMON_KEY_ADMIN, admin); | 134 | key.set_boolean (username, Constants.DAEMON_KEY_ADMIN, admin); |
515 | 126 | save (); | 135 | save (); |
516 | 127 | } | 136 | } |
517 | 128 | 137 | ||
518 | 129 | public bool get_active () { | 138 | public bool get_active () { |
519 | 130 | try { | 139 | try { |
521 | 131 | return key.get_boolean (Vars.DAEMON_GROUP, Vars.DAEMON_KEY_ACTIVE); | 140 | return key.get_boolean (username, Constants.DAEMON_KEY_ACTIVE); |
522 | 132 | } catch (KeyFileError e) { | 141 | } catch (KeyFileError e) { |
523 | 133 | warning (e.message); | 142 | warning (e.message); |
524 | 134 | } | 143 | } |
525 | @@ -138,7 +147,7 @@ | |||
526 | 138 | 147 | ||
527 | 139 | public string[] get_targets () { | 148 | public string[] get_targets () { |
528 | 140 | try { | 149 | try { |
530 | 141 | return key.get_string_list (Vars.DAEMON_GROUP, Vars.DAEMON_KEY_TARGETS); | 150 | return key.get_string_list (username, Constants.DAEMON_KEY_TARGETS); |
531 | 142 | } catch (KeyFileError e) { | 151 | } catch (KeyFileError e) { |
532 | 143 | warning (e.message); | 152 | warning (e.message); |
533 | 144 | } | 153 | } |
534 | @@ -148,7 +157,7 @@ | |||
535 | 148 | 157 | ||
536 | 149 | public string[] get_block_urls () { | 158 | public string[] get_block_urls () { |
537 | 150 | try { | 159 | try { |
539 | 151 | return key.get_string_list (Vars.DAEMON_GROUP, Vars.DAEMON_KEY_BLOCK_URLS); | 160 | return key.get_string_list (username, Constants.DAEMON_KEY_BLOCK_URLS); |
540 | 152 | } catch (KeyFileError e) { | 161 | } catch (KeyFileError e) { |
541 | 153 | warning (e.message); | 162 | warning (e.message); |
542 | 154 | } | 163 | } |
543 | @@ -158,7 +167,7 @@ | |||
544 | 158 | 167 | ||
545 | 159 | public bool get_admin () { | 168 | public bool get_admin () { |
546 | 160 | try { | 169 | try { |
548 | 161 | return key.get_boolean (Vars.DAEMON_GROUP, Vars.DAEMON_KEY_ADMIN); | 170 | return key.get_boolean (username, Constants.DAEMON_KEY_ADMIN); |
549 | 162 | } catch (KeyFileError e) { | 171 | } catch (KeyFileError e) { |
550 | 163 | warning (e.message); | 172 | warning (e.message); |
551 | 164 | } | 173 | } |
552 | @@ -166,26 +175,9 @@ | |||
553 | 166 | return false; | 175 | return false; |
554 | 167 | } | 176 | } |
555 | 168 | 177 | ||
576 | 169 | private void monitor_file () { | 178 | public void update_key () { |
577 | 170 | var file = File.new_for_path (config_path); | 179 | try { |
578 | 171 | try { | 180 | key.load_from_file (Constants.DAEMON_CONF_FILE, KeyFileFlags.KEEP_COMMENTS | KeyFileFlags.KEEP_TRANSLATIONS); |
559 | 172 | var monitor = file.monitor (FileMonitorFlags.NONE, null); | ||
560 | 173 | monitor.changed.connect ((src, dest, event) => { | ||
561 | 174 | if (event == FileMonitorEvent.CHANGES_DONE_HINT) { | ||
562 | 175 | update_key (); | ||
563 | 176 | |||
564 | 177 | Server.get_default ().user_config_changed (username); | ||
565 | 178 | changed (); | ||
566 | 179 | } | ||
567 | 180 | }); | ||
568 | 181 | } catch (Error e) { | ||
569 | 182 | warning (e.message); | ||
570 | 183 | } | ||
571 | 184 | } | ||
572 | 185 | |||
573 | 186 | private void update_key () { | ||
574 | 187 | try { | ||
575 | 188 | key.load_from_file (config_path, KeyFileFlags.NONE); | ||
579 | 189 | } catch (KeyFileError e) { | 181 | } catch (KeyFileError e) { |
580 | 190 | warning (e.message); | 182 | warning (e.message); |
581 | 191 | } catch (FileError e) { | 183 | } catch (FileError e) { |
582 | @@ -195,14 +187,13 @@ | |||
583 | 195 | 187 | ||
584 | 196 | private void save () { | 188 | private void save () { |
585 | 197 | try { | 189 | try { |
587 | 198 | key.save_to_file (config_path); | 190 | key.save_to_file (Constants.DAEMON_CONF_FILE); |
588 | 199 | } catch (FileError e) { | 191 | } catch (FileError e) { |
589 | 200 | warning (e.message); | 192 | warning (e.message); |
590 | 201 | return; | 193 | return; |
591 | 202 | } | 194 | } |
592 | 203 | 195 | ||
595 | 204 | Server.get_default ().user_config_changed (username); | 196 | Server.get_default ().config_changed (); |
594 | 205 | changed (); | ||
596 | 206 | } | 197 | } |
597 | 207 | } | 198 | } |
598 | 208 | } | 199 | } |
599 | 209 | \ No newline at end of file | 200 | \ No newline at end of file |
600 | 210 | 201 | ||
601 | === renamed file 'src/shared/Vars.vala' => 'src/shared/Constants.vala.cmake' | |||
602 | --- src/shared/Vars.vala 2016-08-29 22:25:35 +0000 | |||
603 | +++ src/shared/Constants.vala.cmake 2016-12-09 17:18:29 +0000 | |||
604 | @@ -20,7 +20,7 @@ | |||
605 | 20 | * Authored by: Adam Bieńkowski <donadigos159@gmail.com> | 20 | * Authored by: Adam Bieńkowski <donadigos159@gmail.com> |
606 | 21 | */ | 21 | */ |
607 | 22 | 22 | ||
609 | 23 | namespace PC.Vars { | 23 | namespace PC.Constants { |
610 | 24 | public const string LOGIN_IFACE = "org.freedesktop.login1"; | 24 | public const string LOGIN_IFACE = "org.freedesktop.login1"; |
611 | 25 | public const string LOGIN_OBJECT_PATH = "/org/freedesktop/login1"; | 25 | public const string LOGIN_OBJECT_PATH = "/org/freedesktop/login1"; |
612 | 26 | public const string DBUS_PROPERTIES_IFACE = "org.freedesktop.DBus.Properties"; | 26 | public const string DBUS_PROPERTIES_IFACE = "org.freedesktop.DBus.Properties"; |
613 | @@ -31,7 +31,7 @@ | |||
614 | 31 | public const string PLANK_CONF_DIR = "/.config/plank/dock1/settings"; | 31 | public const string PLANK_CONF_DIR = "/.config/plank/dock1/settings"; |
615 | 32 | public const string PLANK_CONF_GROUP = "PlankDockPreferences"; | 32 | public const string PLANK_CONF_GROUP = "PlankDockPreferences"; |
616 | 33 | public const string PLANK_CONF_LOCK_ITEMS_KEY = "LockItems"; | 33 | public const string PLANK_CONF_LOCK_ITEMS_KEY = "LockItems"; |
618 | 34 | public const string DAEMON_CONF_DIR = "/.config/pantheon-parental-controls-daemon.conf"; | 34 | public const string DAEMON_CONF_FILE = "@CMAKE_INSTALL_PREFIX@/share/pantheon-parental-controls/daemon.conf"; |
619 | 35 | public const string[] DAEMON_IGNORED_USERS = { "lightdm" }; | 35 | public const string[] DAEMON_IGNORED_USERS = { "lightdm" }; |
620 | 36 | public const string DAEMON_GROUP = "PCDaemon"; | 36 | public const string DAEMON_GROUP = "PCDaemon"; |
621 | 37 | public const string DAEMON_KEY_ACTIVE = "Active"; | 37 | public const string DAEMON_KEY_ACTIVE = "Active"; |
622 | 38 | 38 | ||
623 | === modified file 'src/shared/PAM/Reader.vala' | |||
624 | --- src/shared/PAM/Reader.vala 2016-08-30 17:28:55 +0000 | |||
625 | +++ src/shared/PAM/Reader.vala 2016-12-09 17:18:29 +0000 | |||
626 | @@ -22,22 +22,15 @@ | |||
627 | 22 | 22 | ||
628 | 23 | namespace PC.PAM { | 23 | namespace PC.PAM { |
629 | 24 | public class Reader : Object { | 24 | public class Reader : Object { |
632 | 25 | public static string get_config (string contents, bool ignore_comments = true) { | 25 | public static string get_config (string contents, out int start_idx, out int end_idx) { |
633 | 26 | string config = ""; | 26 | start_idx = contents.index_of (Constants.PAM_CONF_START); |
634 | 27 | end_idx = contents.index_of (Constants.PAM_CONF_END) + Constants.PAM_CONF_END.char_count (); | ||
635 | 27 | 28 | ||
636 | 28 | int start_idx = contents.index_of (Vars.PAM_CONF_START); | ||
637 | 29 | int end_idx = contents.index_of (Vars.PAM_CONF_END) + Vars.PAM_CONF_END.char_count (); | ||
638 | 30 | if (start_idx == -1 || end_idx == -1) { | 29 | if (start_idx == -1 || end_idx == -1) { |
649 | 31 | return config; | 30 | return ""; |
650 | 32 | } | 31 | } |
651 | 33 | 32 | ||
652 | 34 | config = contents.slice (start_idx, end_idx); | 33 | return contents.slice (start_idx, end_idx); |
643 | 35 | |||
644 | 36 | if (ignore_comments) { | ||
645 | 37 | return Utils.remove_comments (config); | ||
646 | 38 | } | ||
647 | 39 | |||
648 | 40 | return config; | ||
653 | 41 | } | 34 | } |
654 | 42 | 35 | ||
655 | 43 | public static List<Token> get_tokens (string filename) { | 36 | public static List<Token> get_tokens (string filename) { |
656 | @@ -49,7 +42,7 @@ | |||
657 | 49 | return new List<Token> (); | 42 | return new List<Token> (); |
658 | 50 | } | 43 | } |
659 | 51 | 44 | ||
661 | 52 | string config = get_config (contents); | 45 | string config = get_config (contents, null, null); |
662 | 53 | return Token.parse (config); | 46 | return Token.parse (config); |
663 | 54 | } | 47 | } |
664 | 55 | 48 | ||
665 | 56 | 49 | ||
666 | === modified file 'src/shared/PAM/Writer.vala' | |||
667 | --- src/shared/PAM/Writer.vala 2016-08-30 17:28:55 +0000 | |||
668 | +++ src/shared/PAM/Writer.vala 2016-12-09 17:18:29 +0000 | |||
669 | @@ -25,7 +25,7 @@ | |||
670 | 25 | private string filename; | 25 | private string filename; |
671 | 26 | 26 | ||
672 | 27 | public static Writer new_for_time () { | 27 | public static Writer new_for_time () { |
674 | 28 | return new Writer (Vars.PAM_TIME_CONF_PATH); | 28 | return new Writer (Constants.PAM_TIME_CONF_PATH); |
675 | 29 | } | 29 | } |
676 | 30 | 30 | ||
677 | 31 | public Writer (string filename) { | 31 | public Writer (string filename) { |
678 | @@ -33,13 +33,11 @@ | |||
679 | 33 | } | 33 | } |
680 | 34 | 34 | ||
681 | 35 | public void add_restriction_for_user (string input, bool clean) { | 35 | public void add_restriction_for_user (string input, bool clean) { |
682 | 36 | string? clean_username = null; | ||
683 | 36 | if (clean) { | 37 | if (clean) { |
684 | 37 | var token = Token.parse_line (input); | 38 | var token = Token.parse_line (input); |
685 | 38 | if (token != null) { | 39 | if (token != null) { |
690 | 39 | string username = token.get_user_arg0 (); | 40 | clean_username = token.get_user_arg0 (); |
687 | 40 | if (Reader.get_token_for_user (filename, username) != null) { | ||
688 | 41 | remove_restriction_for_user (username); | ||
689 | 42 | } | ||
691 | 43 | } | 41 | } |
692 | 44 | } | 42 | } |
693 | 45 | 43 | ||
694 | @@ -51,26 +49,32 @@ | |||
695 | 51 | return; | 49 | return; |
696 | 52 | } | 50 | } |
697 | 53 | 51 | ||
705 | 54 | string config = Reader.get_config (contents, false); | 52 | int start_idx; |
706 | 55 | 53 | int end_idx; | |
707 | 56 | var builder = new StringBuilder (Vars.PAM_CONF_START); | 54 | string config = Reader.get_config (contents, out start_idx, out end_idx); |
708 | 57 | if (config != "") { | 55 | |
709 | 58 | builder.append ("\n"); | 56 | if (start_idx != -1 && end_idx != -1) { |
710 | 59 | builder.append (Utils.remove_comments (config)); | 57 | contents = contents.splice (start_idx - 1, end_idx); |
711 | 60 | } else { | 58 | } |
712 | 59 | |||
713 | 60 | var builder = new StringBuilder (Constants.PAM_CONF_START); | ||
714 | 61 | builder.append ("\n"); | ||
715 | 62 | |||
716 | 63 | foreach (var token in Token.parse (config)) { | ||
717 | 64 | if (token.get_user_arg0 () == clean_username) { | ||
718 | 65 | continue; | ||
719 | 66 | } | ||
720 | 67 | |||
721 | 68 | builder.append (token.to_string ()); | ||
722 | 61 | builder.append ("\n"); | 69 | builder.append ("\n"); |
723 | 62 | } | 70 | } |
724 | 63 | 71 | ||
725 | 64 | builder.append (input); | 72 | builder.append (input); |
726 | 65 | builder.append ("\n"); | 73 | builder.append ("\n"); |
728 | 66 | builder.append (Vars.PAM_CONF_END); | 74 | builder.append (Constants.PAM_CONF_END); |
729 | 67 | 75 | ||
730 | 68 | try { | 76 | try { |
736 | 69 | if (config != "") { | 77 | FileUtils.set_contents (filename, "%s\n%s".printf (contents, builder.str)); |
732 | 70 | FileUtils.set_contents (filename, contents.replace (config, builder.str)); | ||
733 | 71 | } else { | ||
734 | 72 | FileUtils.set_contents (filename, "\n%s\n%s\n".printf (contents, builder.str)); | ||
735 | 73 | } | ||
737 | 74 | } catch (FileError e) { | 78 | } catch (FileError e) { |
738 | 75 | warning ("%s\n", e.message); | 79 | warning ("%s\n", e.message); |
739 | 76 | } | 80 | } |
740 | @@ -85,26 +89,35 @@ | |||
741 | 85 | return; | 89 | return; |
742 | 86 | } | 90 | } |
743 | 87 | 91 | ||
745 | 88 | string config = Reader.get_config (contents); | 92 | int start_idx; |
746 | 93 | int end_idx; | ||
747 | 94 | string config = Reader.get_config (contents, out start_idx, out end_idx); | ||
748 | 89 | 95 | ||
750 | 90 | if (config == "") { | 96 | if (start_idx != -1 && end_idx != -1) { |
751 | 97 | contents = contents.splice (start_idx - 1, end_idx); | ||
752 | 98 | } else { | ||
753 | 91 | return; | 99 | return; |
754 | 92 | } | 100 | } |
755 | 93 | 101 | ||
757 | 94 | string buffer = ""; | 102 | var builder = new StringBuilder (Constants.PAM_CONF_START); |
758 | 103 | builder.append ("\n"); | ||
759 | 95 | 104 | ||
764 | 96 | foreach (string line in config.split ("\n")) { | 105 | foreach (var token in Token.parse (config)) { |
765 | 97 | var token = Token.parse_line (line); | 106 | if (token.get_user_arg0 () == username) { |
766 | 98 | if (token != null && token.get_user_arg0 () != username) { | 107 | continue; |
763 | 99 | buffer += line; | ||
767 | 100 | } | 108 | } |
768 | 109 | |||
769 | 110 | builder.append (token.to_string ()); | ||
770 | 111 | builder.append ("\n"); | ||
771 | 101 | } | 112 | } |
772 | 102 | 113 | ||
773 | 114 | builder.append (Constants.PAM_CONF_END); | ||
774 | 115 | |||
775 | 103 | try { | 116 | try { |
777 | 104 | FileUtils.set_contents (filename, contents.replace (config, buffer)); | 117 | FileUtils.set_contents (filename, "%s\n%s".printf (contents, builder.str)); |
778 | 105 | } catch (FileError e) { | 118 | } catch (FileError e) { |
779 | 106 | warning ("%s\n", e.message); | 119 | warning ("%s\n", e.message); |
780 | 107 | } | 120 | } |
782 | 108 | } | 121 | } |
783 | 109 | } | 122 | } |
784 | 110 | } | 123 | } |
785 | 111 | \ No newline at end of file | 124 | \ No newline at end of file |
786 | 112 | 125 | ||
787 | === modified file 'src/shared/Utils.vala' | |||
788 | --- src/shared/Utils.vala 2016-10-25 21:35:37 +0000 | |||
789 | +++ src/shared/Utils.vala 2016-12-09 17:18:29 +0000 | |||
790 | @@ -75,7 +75,7 @@ | |||
791 | 75 | } | 75 | } |
792 | 76 | 76 | ||
793 | 77 | try { | 77 | try { |
795 | 78 | api = Bus.get_proxy_sync (BusType.SYSTEM, Vars.PARENTAL_CONTROLS_IFACE, Vars.PARENTAL_CONTROLS_OBJECT_PATH); | 78 | api = Bus.get_proxy_sync (BusType.SYSTEM, Constants.PARENTAL_CONTROLS_IFACE, Constants.PARENTAL_CONTROLS_OBJECT_PATH); |
796 | 79 | } catch (Error e) { | 79 | } catch (Error e) { |
797 | 80 | critical ("%s, using dummy parental controls backend", e.message); | 80 | critical ("%s, using dummy parental controls backend", e.message); |
798 | 81 | api = new DummyParentalControls (); | 81 | api = new DummyParentalControls (); |
799 | @@ -90,8 +90,9 @@ | |||
800 | 90 | } | 90 | } |
801 | 91 | 91 | ||
802 | 92 | try { | 92 | try { |
803 | 93 | |||
804 | 93 | var user = new Polkit.UnixUser.for_name (Environment.get_user_name ()); | 94 | var user = new Polkit.UnixUser.for_name (Environment.get_user_name ()); |
806 | 94 | permission = new Polkit.Permission.sync (Vars.PARENTAL_CONTROLS_ACTION_ID, | 95 | permission = new Polkit.Permission.sync (Constants.PARENTAL_CONTROLS_ACTION_ID, |
807 | 95 | new Polkit.UnixProcess.for_owner (Posix.getpid (), 0, user.get_uid ())); | 96 | new Polkit.UnixProcess.for_owner (Posix.getpid (), 0, user.get_uid ())); |
808 | 96 | return permission; | 97 | return permission; |
809 | 97 | } catch (Error e) { | 98 | } catch (Error e) { |
810 | @@ -132,9 +133,5 @@ | |||
811 | 132 | 133 | ||
812 | 133 | return buffer; | 134 | return buffer; |
813 | 134 | } | 135 | } |
814 | 135 | |||
815 | 136 | public static string build_daemon_conf_path (Act.User user) { | ||
816 | 137 | return Path.build_filename (user.get_home_dir (), Vars.DAEMON_CONF_DIR); | ||
817 | 138 | } | ||
818 | 139 | } | 136 | } |
819 | 140 | } | 137 | } |
Needs trunk merged in and conflicts resolved.