コード例 #1
0
ファイル: server.go プロジェクト: nforgerit/docker
func lookupGidByName(nameOrGid string) (int, error) {
	groups, err := user.ParseGroupFilter(func(g *user.Group) bool {
		return g.Name == nameOrGid || strconv.Itoa(g.Gid) == nameOrGid
	})
	if err != nil {
		return -1, err
	}
	if groups != nil && len(groups) > 0 {
		return groups[0].Gid, nil
	}
	return -1, fmt.Errorf("Group %s not found", nameOrGid)
}
コード例 #2
0
ファイル: server.go プロジェクト: kraman/docker
// ListenAndServe sets up the required http.Server and gets it listening for
// each addr passed in and does protocol specific checking.
func ListenAndServe(proto, addr string, eng *engine.Engine, logging, enableCors bool, dockerVersion string) error {
	r, err := createRouter(eng, logging, enableCors, dockerVersion)
	if err != nil {
		return err
	}

	if proto == "fd" {
		return ServeFd(addr, r)
	}

	if proto == "unix" {
		if err := syscall.Unlink(addr); err != nil && !os.IsNotExist(err) {
			return err
		}
	}

	l, err := listenbuffer.NewListenBuffer(proto, addr, activationLock, 15*time.Minute)
	if err != nil {
		return err
	}

	// Basic error and sanity checking
	switch proto {
	case "tcp":
		if !strings.HasPrefix(addr, "127.0.0.1") {
			log.Println("/!\\ DON'T BIND ON ANOTHER IP ADDRESS THAN 127.0.0.1 IF YOU DON'T KNOW WHAT YOU'RE DOING /!\\")
		}
	case "unix":
		if err := os.Chmod(addr, 0660); err != nil {
			return err
		}

		groups, err := user.ParseGroupFilter(func(g *user.Group) bool {
			return g.Name == "docker"
		})
		if err != nil {
			return err
		}
		if len(groups) > 0 {
			utils.Debugf("docker group found. gid: %d", groups[0].Gid)
			if err := os.Chown(addr, 0, groups[0].Gid); err != nil {
				return err
			}
		}
	default:
		return fmt.Errorf("Invalid protocol format.")
	}

	httpSrv := http.Server{Addr: addr, Handler: r}
	return httpSrv.Serve(l)
}