osx - Restarting the video assistant with a simple command -


original problem: on macbook pro, video camera keeps freezing. found the solution type

sudo killall vdcassistant 

in terminal, , provide password (i have admin privileges).

now make single command (that doesn't need password). found possible use visudo edit file tells sudo commands might run without requiring password. dangerous make killall "password free", hoping wrap specific command inside script; make script "password free"; , on life. here did:

create file called video, contains

!#/bin/bash sudo killall vdcassistant 

put in /usr/local/bin, give permissions chmod 700 video, , rehash. when type video, prompted password. far good.

next, ran visudo , added lines

user_alias users = myusername cmnd_alias cmds = /usr/local/bin/video users = (all) nopasswd: cmds 

but doesn't have desired effect. still prompted password. if make root owner of script, doesn't change things. if leave out sudo part of command, tells me "no matching processes belonging found".

does have trick missed - how achieve goal (using single-word command perform killall process not own, without having type password)?

i have read answers how run script user without password not find applied here; read answers sudo password in 1 command line - inspiration use visudo came - again didn't give me answer looking for. can't save password in plain text, , don't want remove "normal" protections killall.

is there way this?

if have actual binary executable, can set setuid bit on using chmod 4755, , binary execute whichever user owns (most useful if root, obviously). however, doesn't work on shell scripts, security reasons. i'm not 100% sure case, possible visudo may ignoring shell scripts same reasons.

if you've got xcode installed, though, can build actual binary program run killall command, , can set setuid bit on it. swift program should trick:

import foundation  guard setuid(0) == 0 else {     print("couldn't set uid 0: error \(errno)")     exit(-1) }  let killall = process()  killall.launchpath = "/usr/bin/killall" killall.arguments = ["vdcassistant"]  killall.launch() killall.waituntilexit() 

save above in text file called video.swift. run following command:

swiftc video.swift -framework foundation 

this create file called video in directory. move file /usr/local/bin, change owner root , setuid sucker:

mv video /usr/local/bin sudo chown root:wheel video sudo chmod 4755 video 

now should work.

if want fancier, possible rig plist in /library/launchdaemons , launchd automatically kill process every often.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -