Added a reserved list of UID's to not allow a user to be created with
This commit is contained in:
parent
5d127225e7
commit
30c045c753
@ -1,6 +1,7 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
@ -8,6 +9,8 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
ldap "gopkg.in/ldap.v2"
|
||||
|
||||
"git.metaunix.net/metaunix.net/muldap/lib/util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -32,6 +35,18 @@ var userAddCmd = &cobra.Command{
|
||||
Short: "Add an LDAP user to the directory",
|
||||
Long: `Create and add an LDAP user resource to your directory.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// chck if a user id was provided
|
||||
if flagUserUsername == "" {
|
||||
uidErr := errors.New("You must supply a user ID")
|
||||
log.Fatal(uidErr)
|
||||
}
|
||||
|
||||
// check if the provided user id is valid
|
||||
if util.ContainsString(viper.GetStringSlice("user.uid_reserved"), flagUserUsername) {
|
||||
uidErr := errors.New("The user ID name that you provided is in the reserved list")
|
||||
log.Fatal(uidErr)
|
||||
}
|
||||
|
||||
// create new LDAP connection
|
||||
l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", viper.GetString("host"), viper.GetInt("port")))
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user