本文整理汇总了Golang中os.Geteuid函数的典型用法代码示例。如果您正苦于以下问题:Golang Geteuid函数的具体用法?Golang Geteuid怎么用?Golang Geteuid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Geteuid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: serve9p
func serve9p() {
var cl *Clone
var err error
var sf *StatsFile
root, err = mkroot()
if err != nil {
goto error
}
cl = new(Clone)
err = cl.Add(root, "clone", p.OsUsers.Uid2User(os.Geteuid()), nil, 0444, cl)
if err != nil {
goto error
}
sf = new(StatsFile)
err = sf.Add(root, "stats", p.OsUsers.Uid2User(os.Geteuid()), nil, 0444, sf)
if err != nil {
goto error
}
fs = srv.NewFileSrv(root)
fs.Dotu = true
fs.Start(fs)
err = fs.StartNetListener("tcp", *laddr)
if err != nil {
goto error
}
return
error:
log.Fatalf("Error serving 9p: %s\n", err)
}
示例2: NewNFQueue
func NewNFQueue(qid uint16) (nfq *nfQueue) {
if os.Geteuid() != 0 {
}
if os.Geteuid() != 0 {
panic("Must be ran by root.")
}
nfq = &nfQueue{DefaultVerdict: ACCEPT, Timeout: time.Microsecond * 5, qid: qid}
return nfq
}
示例3: lookupUid
// lookupUid resolves a username to a numeric id. Current euid is returned on failure.
func lookupUid(username string) uint32 {
u, err := user.Lookup(username)
if err != nil {
log.Printf("Error resolving uid for %v: %v\n", username, err)
return uint32(os.Geteuid())
}
uid, err := strconv.ParseUint(u.Uid, 10 /* base */, 32 /* bits */)
if err != nil {
log.Printf("Error resolving uid for %v: %v\n", username, err)
return uint32(os.Geteuid())
}
return uint32(uid)
}
示例4: FetchImage
// FetchImage will take an image as either a path, a URL or a name
// string and import it into the store if found. If ascPath is not "",
// it must exist as a local file and will be used as the signature
// file for verification, unless verification is disabled. If
// f.WithDeps is true also image dependencies are fetched.
func (f *Fetcher) FetchImage(d dist.Distribution, image, ascPath string) (*types.Hash, error) {
ensureLogger(f.Debug)
db := &distBundle{
dist: d,
image: image,
}
a := f.getAsc(ascPath)
hash, err := f.fetchSingleImage(db, a)
if err != nil {
return nil, err
}
if f.WithDeps {
err = f.fetchImageDeps(hash)
if err != nil {
return nil, err
}
}
// we need to be able to do a chroot and access to the tree store
// directories, we need to
// 1) check if the system supports OverlayFS
// 2) check if we're root
if common.SupportsOverlay() == nil && os.Geteuid() == 0 {
if _, _, err := f.Ts.Render(hash, false); err != nil {
return nil, errwrap.Wrap(errors.New("error rendering tree store"), err)
}
}
h, err := types.NewHash(hash)
if err != nil {
// should never happen
log.PanicE("invalid hash", err)
}
return h, nil
}
示例5: installCommand
func installCommand(cmd *cobra.Command, args []string) {
requireGitVersion()
if localInstall {
requireInRepo()
}
if systemInstall && os.Geteuid() != 0 {
Print("WARNING: current user is not root/admin, system install is likely to fail.")
}
if localInstall && systemInstall {
Exit("Only one of --local and --system options can be specified.")
}
opt := lfs.InstallOptions{Force: forceInstall, Local: localInstall, System: systemInstall}
if skipSmudgeInstall {
// assume the user is changing their smudge mode, so enable force implicitly
opt.Force = true
}
if err := lfs.InstallFilters(opt, skipSmudgeInstall); err != nil {
Error(err.Error())
Exit("Run `git lfs install --force` to reset git config.")
}
if localInstall || lfs.InRepo() {
installHooksCommand(cmd, args)
}
Print("Git LFS initialized.")
}
示例6: main
func main() {
if os.Geteuid() != 0 {
log.Error("Must be run as root")
os.Exit(1)
}
setupIPTables()
ds, err := newDbusServer()
if err != nil {
log.Error(err.Error())
os.Exit(1)
}
fw := &Firewall{
dbus: ds,
dns: NewDnsCache(),
policyMap: make(map[string]*Policy),
}
fw.loadRules()
/*
go func() {
http.ListenAndServe("localhost:6060", nil)
}()
*/
fw.runFilter()
}
示例7: newFuseFS
func newFuseFS(tmpDir string, rpcFS *RpcFs, writableRoot string) (*fuseFS, error) {
tmpDir, err := ioutil.TempDir(tmpDir, "termite-task")
if err != nil {
return nil, err
}
fs := &fuseFS{
writableRoot: strings.TrimLeft(writableRoot, "/"),
workers: map[string]*workerFS{},
rpcFS: rpcFS,
rpcNodeFS: pathfs.NewPathNodeFs(&multiRPCFS{rpcFS},
&pathfs.PathNodeFsOptions{ClientInodes: true}),
tmpDir: tmpDir,
mount: filepath.Join(tmpDir, "mnt"),
}
if err := os.Mkdir(fs.mount, 0755); err != nil {
return nil, err
}
fs.fsConnector = nodefs.NewFileSystemConnector(fs.rpcNodeFS.Root(),
nodeFSOptions())
fuseOpts := fuse.MountOptions{}
if os.Geteuid() == 0 {
fuseOpts.AllowOther = true
}
fs.server, err = fuse.NewServer(fs.fsConnector.RawFS(), fs.mount, &fuseOpts)
if err != nil {
return nil, err
}
go fs.server.Serve()
return fs, nil
}
示例8: setBaseDir
func (m *Manager) setBaseDir() {
m.baseDir = os.Getenv("GOVISORDIR")
switch runtime.GOOS {
case "nacl", "plan9":
m.baseDir = ""
case "windows":
if len(m.baseDir) == 0 {
m.baseDir = os.Getenv("HOME")
}
if len(m.baseDir) == 0 {
m.baseDir = "C:\\"
}
default:
if len(m.baseDir) == 0 {
if os.Geteuid() == 0 {
m.baseDir = "/var"
} else {
m.baseDir = os.Getenv("HOME")
}
}
if len(m.baseDir) == 0 {
m.baseDir = "."
}
}
}
示例9: TestEndToEndStdout
func TestEndToEndStdout(t *testing.T) {
if os.Geteuid() == 0 {
log.Println("This test should not run as root")
return
}
tc := NewTestCase(t)
defer tc.Clean()
err := os.Symlink("oldlink", tc.tmp+"/wd/symlink")
if err != nil {
t.Fatal("oldlink symlink", err)
}
shcmd := make([]byte, 1500)
for i := 0; i < len(shcmd); i++ {
shcmd[i] = 'a'
}
err = ioutil.WriteFile(tc.tmp+"/wd/file.txt", shcmd, 0644)
if err != nil {
t.Fatalf("WriteFile %#v", err)
}
rep := tc.Run(WorkRequest{
Binary: tc.FindBin("cat"),
Argv: []string{"cat", "file.txt"},
Env: testEnv(),
Dir: tc.tmp + "/wd",
})
if string(rep.Stdout) != string(shcmd) {
t.Errorf("Reply mismatch %s expect %s", string(rep.Stdout), string(shcmd))
}
}
示例10: ExtractImage
// ExtractImage will extract the contents of the image at path to the directory
// at dst. If fileMap is set, only files in it will be extracted.
func ExtractImage(path, dst string, fileMap map[string]struct{}) error {
dst, err := filepath.Abs(dst)
if err != nil {
return err
}
file, err := os.Open(path)
if err != nil {
return err
}
defer file.Close()
dr, err := aci.NewCompressedReader(file)
if err != nil {
return fmt.Errorf("error decompressing image: %v", err)
}
defer dr.Close()
uidRange := user.NewBlankUidRange()
if os.Geteuid() == 0 {
return rkttar.ExtractTar(dr, dst, true, uidRange, fileMap)
}
editor, err := rkttar.NewUidShiftingFilePermEditor(uidRange)
if err != nil {
return fmt.Errorf("error determining current user: %v", err)
}
return rkttar.ExtractTarInsecure(tar.NewReader(dr), dst, true, fileMap, editor)
}
示例11: Chown
func (me *UnionFs) Chown(name string, uid uint32, gid uint32, context *fuse.Context) (code fuse.Status) {
name = stripSlash(name)
r := me.getBranch(name)
if r.attr == nil || r.code != fuse.OK {
return r.code
}
if os.Geteuid() != 0 {
return fuse.EPERM
}
if r.attr.Uid != int(uid) || r.attr.Gid != int(gid) {
if r.branch > 0 {
code := me.Promote(name, r, context)
if code != fuse.OK {
return code
}
r.branch = 0
}
me.fileSystems[0].Chown(name, uid, gid, context)
}
r.attr.Uid = int(uid)
r.attr.Gid = int(gid)
r.attr.Ctime_ns = time.Nanoseconds()
me.branchCache.Set(name, r)
return fuse.OK
}
示例12: TestHubSocksOption
func TestHubSocksOption(t *testing.T) {
assert := assert.On(t)
if os.Geteuid() != 0 {
// This test case requires root permission.
return
}
hub, err := ListenUDP(v2net.LocalHostIP, v2net.Port(0), ListenOption{
Callback: func(*buf.Buffer, *proxy.SessionInfo) {},
ReceiveOriginalDest: true,
})
assert.Error(err).IsNil()
conn := hub.Connection()
fd, err := internal.GetSysFd(conn)
assert.Error(err).IsNil()
val, err := syscall.GetsockoptInt(fd, syscall.SOL_IP, syscall.IP_TRANSPARENT)
assert.Error(err).IsNil()
assert.Int(val).Equals(1)
val, err = syscall.GetsockoptInt(fd, syscall.SOL_IP, syscall.IP_RECVORIGDSTADDR)
assert.Error(err).IsNil()
assert.Int(val).Equals(1)
}
示例13: main
func main() {
cachedir := flag.String("cachedir", "/var/cache/termite/worker-cache", "content cache")
tmpdir := flag.String("tmpdir", "/var/tmp",
"where to create FUSE mounts; should be on same partition as cachedir.")
secretFile := flag.String("secret", "secret.txt", "file containing password.")
port := flag.Int("port", 1235, "Where to listen for work requests.")
coordinator := flag.String("coordinator", "", "Where to register the worker.")
jobs := flag.Int("jobs", 1, "Max number of jobs to run.")
user := flag.String("user", "nobody", "Run as this user.")
flag.Parse()
if os.Geteuid() != 0 {
log.Fatal("This program must run as root")
}
secret, err := ioutil.ReadFile(*secretFile)
if err != nil {
log.Fatal("ReadFile", err)
}
opts := termite.WorkerOptions{
Secret: secret,
TempDir: *tmpdir,
CacheDir: *cachedir,
Jobs: *jobs,
User: user,
}
daemon := termite.NewWorkerDaemon(&opts)
go handleStop(daemon)
daemon.RunWorkerServer(*port, *coordinator)
}
示例14: main
func main() {
log.SetPrefix("")
log.SetFlags(0)
if os.Geteuid() != 0 {
log.Fatal(errors.New("please run as root"))
}
fd, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_RAW, syscall.IPPROTO_RAW)
check(err)
if len(os.Args) < 3 {
log.Fatal("usage: synflood <victimIP> <spoofedIP>")
}
raddr := net.ParseIP(os.Args[1])
addr := syscall.SockaddrInet4{
Port: 0,
Addr: to4Array(raddr),
}
p := packet(raddr)
switch runtime.GOOS {
case "darwin", "dragonfly", "freebsd", "netbsd":
// need to set explicitly
check(syscall.SetsockoptInt(fd, syscall.IPPROTO_IP, syscall.IP_HDRINCL, 1))
// no need to receive anything
check(syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_RCVBUF, 1))
case "linux":
// no need to receive anything
check(syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_RCVBUF, 0))
}
for {
check(syscall.Sendto(fd, p, 0, &addr))
}
}
示例15: statusHandler
func statusHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
fmt.Fprintf(w, "pid=%d\n", os.Getpid())
cwd, _ := os.Getwd()
fmt.Fprintf(w, "cwd=%s\n", cwd)
fmt.Fprintf(w, "uid=%d\n", os.Getuid())
fmt.Fprintf(w, "euid=%d\n", os.Geteuid())
fmt.Fprintf(w, "gid=%d\n", os.Getgid())
groups, gerr := exec.Command("groups").CombinedOutput()
if gerr != nil {
fmt.Fprintf(w, "groups_err=%q\n", gerr)
} else {
fmt.Fprintf(w, "groups=%s\n", strings.TrimSpace(string(groups)))
}
ulimitN, _ := exec.Command("ulimit", "-n").Output()
fmt.Fprintf(w, "ulimit_nofiles=%s\n", strings.TrimSpace(string(ulimitN)))
env := os.Environ()
sort.Strings(env)
for _, env := range env {
fmt.Fprintf(w, "%s\n", env)
}
}