Ejemplo n.º 1
0
// Add user onto the system using useradd exec
func (l *awsUser) addUser() error {
	if l.localUser == nil {
		CMD_ARGS := []string{"-p", "123", "-U", "-m", l.iamUser, "-G", l.SudoGroup}
		_, err := exec.Command("useradd", CMD_ARGS...).Output()
		if err != nil {
			return err
		}
		log.Info(fmt.Sprintf("Creating user %v", l.iamUser))
		lusr, _ := user.Lookup(l.iamUser)
		l.localUser = lusr
	}
	return nil
}
Ejemplo n.º 2
0
// Remove users from system that are not in the group list
func RemoveUser(usr string) error {
	u, err := user.Lookup(usr)
	if err != nil {
		return err
	}
	CMD := "userdel"
	CMD_ARGS := []string{"-r", u.Username}
	if _, err := exec.Command(CMD, CMD_ARGS...).Output(); err != nil {
		log.Error(fmt.Sprintf("Error deleting user %v", usr))
		return err
	}
	log.Info(fmt.Sprintf("Deleted user %v", usr))
	return nil
}
Ejemplo n.º 3
0
// Loop through the keys and call add key to add key to the box
func Keys(l *user.User, kp string, ks []string) error {
	f, err := os.Create(kp)
	defer f.Close()
	if err != nil {
		return err
		log.Error(fmt.Sprintf("Error creating %v", kp))
	}
	log.Debug(fmt.Sprintf("Created file %v writing keys %v", kp, ks))
	w := bufio.NewWriter(f)
	for _, k := range ks {
		fmt.Fprintln(w, k)
		log.Info(fmt.Sprintf("adding key %v", k[0:20]))
	}
	w.Flush()
	if err := setPerms(l, kp); err != nil {
		return err
	}
	return nil
}
Ejemplo n.º 4
0
// function main call out into validate code
func main() {
	// Make and initaize the map for structure
	umap := make(userMap)

	// Check the flag options
	flagOptions()

	// Get a list of the groups
	grpList = splitString(*groups)

	if *onetime {
		if err := umap.userSync(grpList); err != nil {
			os.Exit(1)
		}
		os.Exit(0)
	}

	// Set the channels
	stopChan := make(chan bool)
	doneChan := make(chan bool)
	errChan := make(chan error, 10)

	go umap.process(grpList, doneChan, stopChan, *interval)
	signalChan := make(chan os.Signal, 1)
	signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
	for {
		select {
		case err := <-errChan:
			log.Error(fmt.Sprintf("Error captured: %v", err.Error()))
		case s := <-signalChan:
			log.Info(fmt.Sprintf("Captured %v. Exiting...", s))
			close(doneChan)
		case <-doneChan:
			os.Exit(0)
		}
	}

}