Introduce polkit policies

This commit is contained in:
Lakindu Akash 2021-02-20 20:36:58 +05:30
parent 43a1a228b8
commit c6cdc4c84a
No known key found for this signature in database
GPG Key ID: 87D9889F7A634A38
6 changed files with 54 additions and 4 deletions

View File

@ -48,6 +48,8 @@ install: $(ODIR)/wihotspot-gui
install -Dm644 desktop/icons/hotspot@512.png $(DESTDIR)$(PREFIX)/share/icons/hicolor/512x512/apps/wihotspot.png
install -Dm644 desktop/icons/hotspot.svg $(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/apps/wihotspot.svg
install -Dm644 desktop/wifihotspot.desktop $(DESTDIR)$(PREFIX)/share/applications/$(APP_NAME).desktop
install -Dm644 scripts/policies/polkit.rules $(DESTDIR)$(PREFIX)/share/polkit-1/rules.d/90-org.opensuse.policykit.wihotspot.rules
install -Dm644 scripts/policies/polkit.policy $(DESTDIR)$(PREFIX)/share/polkit-1/actions/org.opensuse.policykit.wihotspot.policy
install -Dm755 $(ODIR)/wihotspot-gui $(DESTDIR)$(BINDIR)/$(APP_GUI_BINARY)
cd scripts && $(MAKE) install
@ -59,6 +61,8 @@ uninstall:
rm -f $(DESTDIR)$(PREFIX)/share/icons/hicolor/512x512/apps/wihotspot.png
rm -f $(DESTDIR)$(PREFIX)/share/icons/hicolor/scalable/apps/wihotspot.svg
rm -f $(DESTDIR)$(PREFIX)/share/applications/$(APP_NAME).desktop
rm -f $(DESTDIR)$(PREFIX)/share/polkit-1/rules.d/90-org.opensuse.policykit.wihotspot.rules
rm -f $(DESTDIR)$(PREFIX)/share/polkit-1/actions/org.opensuse.policykit.wihotspot.policy
rm -f $(DESTDIR)$(BINDIR)/$(APP_GUI_BINARY)
cd scripts && $(MAKE) uninstall

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
<policyconfig>
<action id="org.opensuse.policykit.wihotspot-gui">
<message>Authentication is required to run the Wihotspot</message>
<icon_name>wihotspot</icon_name>
<defaults>
<allow_any>auth_admin</allow_any>
<allow_inactive>auth_admin</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
<annotate
key="org.freedesktop.policykit.exec.path">/usr/bin/wihotspot-gui</annotate>
<annotate
key="org.freedesktop.policykit.exec.allow_gui">true</annotate>
</action>
<action id="org.opensuse.policykit.create-ap">
<message>Authentication is required to run the Wihotspot</message>
<icon_name>wihotspot</icon_name>
<defaults>
<allow_any>auth_admin</allow_any>
<allow_inactive>auth_admin</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
<annotate
key="org.freedesktop.policykit.exec.path">/usr/bin/create_ap</annotate>
<annotate
key="org.freedesktop.policykit.exec.allow_gui">true</annotate>
</action>
</policyconfig>

View File

@ -0,0 +1,11 @@
/* Allow users in admin group to run GParted without authentication */
polkit.addRule(function(action, subject) {
if ( action.id == "org.opensuse.policykit.create-ap" ) {
if (subject.isInGroup("sudo")) {
return polkit.Result.YES;
} else {
return polkit.Result.AUTH_ADMIN;
}
}
});

View File

@ -1,4 +1,4 @@
#!/bin/sh
# Start wihotspot-gui as root user
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY /usr/bin/wihotspot-gui
# Start wihotspot-gui
/usr/bin/wihotspot-gui

View File

@ -9,7 +9,7 @@
<property name="type_hint">dialog</property>
<property name="gravity">center</property>
<property name="program_name">Linux Wifi Hotspot</property>
<property name="version">3.7.0</property>
<property name="version">4.0.0</property>
<property name="copyright" translatable="yes">(c) lakinduakash 2021</property>
<property name="comments" translatable="yes">For more info visit
https://github.com/lakinduakash/linux-wifi-hotspot</property>

View File

@ -167,7 +167,7 @@ void write_accepted_macs(char* filename, char* accepted_macs){
printf("mac filter file %s \n",filename);
snprintf(cmd_write_mac,BUFSIZE,"%s '%s' %s %s","echo", accepted_macs, "| sudo tee", filename);
snprintf(cmd_write_mac,BUFSIZE,"%s '%s' %s %s","echo", accepted_macs, "| pkexec -u root tee", filename);
int r=system(cmd_write_mac);
}