-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
352 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,5 @@ results | |
.vm-is-created | ||
.vm-is-running | ||
.DS_Store | ||
su_cmd_osx.go | ||
*.pyc | ||
*.pyo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package common | ||
|
||
import ( | ||
"os/exec" | ||
) | ||
|
||
func su_cmd(user string, cmdStr string, shell string) *exec.Cmd { | ||
var cmd *exec.Cmd = exec.Command( | ||
"su", | ||
"-l", // login shell | ||
user, | ||
"-c", cmdStr, | ||
) | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package main | ||
|
||
import ( | ||
"os/user" | ||
"path/filepath" | ||
|
||
"github.com/dshearer/jobber/common" | ||
) | ||
|
||
func userHasHome(usr *user.User) bool { | ||
// check if user has home dir | ||
if len(usr.HomeDir) == 0 || usr.HomeDir == "/dev/null" { | ||
common.Logger.Printf("Excluding %v: has no home directory", | ||
usr.Username) | ||
return false | ||
|
||
} | ||
|
||
// check if home dir path is absolute | ||
if !filepath.IsAbs(usr.HomeDir) { | ||
common.Logger.Printf("Excluding %v: home directory path is "+ | ||
"not absolute: %v", usr.Username, usr.HomeDir) | ||
return false | ||
} | ||
|
||
// check if user owns home dir | ||
ownsHomeDir, err := common.UserOwnsFile(usr, usr.HomeDir) | ||
if err != nil { | ||
common.Logger.Printf("Excluding %v: %v", usr.Username, err) | ||
return false | ||
} | ||
if !ownsHomeDir { | ||
common.Logger.Printf("Excluding %v: doesn't own home dir", | ||
usr.Username) | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
func shouldRunForUser(usr *user.User, prefs *Prefs) bool { | ||
// check prefs | ||
if !prefs.ShouldIncludeUser(usr) { | ||
common.Logger.Printf("Excluding %v according to prefs", | ||
usr.Username) | ||
return false | ||
} | ||
|
||
if !userHasHome(usr) { | ||
return false | ||
} | ||
|
||
if !shouldRunForUser_platform(usr) { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
/* | ||
Get all users for which we should run jobberrunner. | ||
*/ | ||
func getAcceptableUsers(prefs *Prefs) ([]*user.User, error) { | ||
acceptableUsers := make([]*user.User, 0) | ||
allUsers, err := getAllUsers() | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, usr := range allUsers { | ||
// check for reasons to exclude | ||
if !shouldRunForUser(usr, prefs) { | ||
continue | ||
} | ||
|
||
acceptableUsers = append(acceptableUsers, usr) | ||
} | ||
|
||
return acceptableUsers, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"os/exec" | ||
"os/user" | ||
"strings" | ||
|
||
"github.com/dshearer/jobber/common" | ||
) | ||
|
||
/* | ||
Get all users. | ||
*/ | ||
func getAllUsers() ([]*user.User, error) { | ||
users := make([]*user.User, 0) | ||
out, err := exec.Command("dscl", ".", "list", "/Users").Output() | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, s := range strings.Split(string(out), "\n") { | ||
// look up user | ||
usr, err := user.Lookup(s) | ||
if err != nil { | ||
continue | ||
} | ||
users = append(users, usr) | ||
} | ||
return users, nil | ||
} | ||
|
||
func shouldRunForUser_platform(usr *user.User) bool { | ||
res := !strings.HasPrefix(usr.Username, "_") | ||
if !res { | ||
common.Logger.Printf("Excluding %v: username starts with \"_\"", | ||
usr.Username) | ||
} | ||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// +build !darwin | ||
|
||
package main | ||
|
||
import ( | ||
"bufio" | ||
"os" | ||
"os/user" | ||
"strings" | ||
|
||
"github.com/dshearer/jobber/common" | ||
) | ||
|
||
/* | ||
Get all users. | ||
*/ | ||
func getAllUsers() ([]*user.User, error) { | ||
users := make([]*user.User, 0) | ||
|
||
// open passwd | ||
f, err := os.Open("/etc/passwd") | ||
if err != nil { | ||
common.ErrLogger.Printf("Failed to open /etc/passwd: %v\n", err) | ||
return users, err | ||
} | ||
defer f.Close() | ||
|
||
scanner := bufio.NewScanner(f) | ||
for scanner.Scan() { | ||
// look up user | ||
parts := strings.Split(scanner.Text(), ":") | ||
if len(parts) == 0 { | ||
continue | ||
} | ||
usr, err := user.Lookup(parts[0]) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
users = append(users, usr) | ||
} | ||
return users, nil | ||
} | ||
|
||
func shouldRunForUser_platform(usr *user.User) bool { | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
MASTER_SOURCES := \ | ||
jobbermaster/get_users_darwin.go \ | ||
jobbermaster/get_users_nondarwin.go \ | ||
jobbermaster/get_users.go \ | ||
jobbermaster/main.go \ | ||
jobbermaster/prefs_file.go \ | ||
jobbermaster/runner_proc.go \ | ||
jobbermaster/sources.mk | ||
|
||
MASTER_TEST_SOURCES := \ | ||
jobbermaster/prefs_file_test.go | ||
jobbermaster/prefs_file_test.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
include ../head.mk | ||
|
||
# required by tail.mk: | ||
PKGFILE = nop | ||
PKGFILE_DEPS = nop | ||
PKGFILE_VM_PATH = nop | ||
PACKAGING_SUBDIR = darwin | ||
SRC_TARBALL_DIR = jobber | ||
INSTALL_PKG_CMD = nop | ||
UNINSTALL_PKG_CMD = nop | ||
|
||
.PHONY : test-local | ||
test-local : ${WORK_DIR}/${SRC_TARBALL} | ||
./make-and-install.sh ${WORK_DIR}/${SRC_TARBALL} $${PWD} | ||
|
||
include ../tail.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>Label</key> | ||
<string>info.nekonya.jobber</string> | ||
<key>Program</key> | ||
<string>/usr/local/libexec/jobbermaster</string> | ||
<key>RunAtLoad</key> | ||
<true/> | ||
<key>KeepAlive</key> | ||
<true/> | ||
</dict> | ||
</plist> |
Oops, something went wrong.