Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
/etc/init.d/net.wlp2s0 restart for user[solved]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
skorefish
Apprentice
Apprentice


Joined: 21 Jun 2015
Posts: 285

PostPosted: Sat Dec 30, 2017 9:57 am    Post subject: /etc/init.d/net.wlp2s0 restart for user[solved] Reply with quote

hi,

how can i grand access for a normal user to /etc/init.d/net.wlp2s0 restart
without using sudo and without typing the passwd??

i was thinking

/usr/share/polkit-1/actions/restartWifi.policy
Code:
<?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>
  <vendor>void</vendor>
  <vendor_url></vendor_url>
  <icon_name>computer</icon_name>

  <action id="restartWifi">
    <description>Restart wifi</description>
    <message>...</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>no</allow_active>
    </defaults>
    <annotate key="org.freedesktop.policykit.exec.path">/etc/init.d/net.wlp2s0</annotate>
  </action>
</policyconfig>


/etc/polkit-1/rules.d/10-restartWifi.rules

Code:
polkit.addRule(function(action, subject) {
       if (action.id == "restartWifi" )
       {
           return polkit.Result.YES;
           }
   });



but it doesn't work


Last edited by skorefish on Thu Jan 11, 2018 11:03 pm; edited 2 times in total
Back to top
View user's profile Send private message
charles17
Advocate
Advocate


Joined: 02 Mar 2008
Posts: 3664

PostPosted: Sat Dec 30, 2017 10:09 am    Post subject: Re: /etc/init.d/net.wlp2s0 restart for user??? Reply with quote

The question is: Why would you want to do that?
Back to top
View user's profile Send private message
skorefish
Apprentice
Apprentice


Joined: 21 Jun 2015
Posts: 285

PostPosted: Sat Dec 30, 2017 10:16 am    Post subject: Reply with quote

Quote:
charles17:The question is: Why would you want to do that?

for my .bash_profile to execute
Code:
status=$(/etc/init.d/net.wlp2s0 status|grep -o started);
if [ "$status" != "started" ];
  then
        /etc/init.d/net.wlp2s0 restart
        startxfce4 --with-ck-launch
fi

        cpupower --cpu all frequency-set --freq 800MHz


i don't start net.wlp2s0 with rc because this is so much slower
i don't want to use a window manager
Back to top
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 7470

PostPosted: Sat Dec 30, 2017 12:19 pm    Post subject: Reply with quote

you could start a script that loop for a file when you boot, and if the file is there it just start the service, this way your user can create the file, but the script that will start the service has rights to do so.
Code:
#!/bin/bash
while [ ! -f /tmp/whatevername ]
 do
 sleep 1
 done
/etc/init.d/net.wlp2s0 restart


and your .bash_profile adapt to
Code:
  then
        touch /tmp/whatevername
        startxfce4 --with-ck-launch
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6747

PostPosted: Sat Dec 30, 2017 12:29 pm    Post subject: Re: /etc/init.d/net.wlp2s0 restart for user??? Reply with quote

skorefish wrote:
without using sudo and without typing the passwd?

Why that restriction? A particular sudo rule for that particular command and your user with NOPASSWD sounds to me to be the correct solution.
Back to top
View user's profile Send private message
skorefish
Apprentice
Apprentice


Joined: 21 Jun 2015
Posts: 285

PostPosted: Sat Dec 30, 2017 2:00 pm    Post subject: Reply with quote

Quote:
you could start a script that loop for a file when you boot,

very interesting method !!

and
Code:
david asus=(ALL) NOPASSWD:/etc/init.d/net.wlp2s0,/etc/sudoers,/sbin/shutdown,/usr/bin/cpupower


works,but what about just typing
Code:
/etc/init.d/net.wlp2s0 restart
without restrictions! Is this possible for a user?

What's the danger in restarting the wifi as a user?
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21607

PostPosted: Sat Dec 30, 2017 6:24 pm    Post subject: Reply with quote

It is not a question of whether it is dangerous to let the user restart wireless. There is no restriction on running that command as a user. However, if you want it to succeed, it needs permission to do things that users normally cannot do. If you have this in a startup script anyway, why do you need the user to be able to run this without sudo? Would it not be easier to define a wrapper that will sudo the script for you?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum