github.com/avfs/avfs@v0.33.1-0.20240303173310-c6ba67c33eb7/idm/memidm/memidm_cfg.go (about) 1 // 2 // Copyright 2020 The AVFS authors 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 package memidm 18 19 import "github.com/avfs/avfs" 20 21 // New creates a new identity manager. 22 func New() *MemIdm { 23 return NewWithOptions(nil) 24 } 25 26 // NewWithOptions creates a new identity manager using Options. 27 func NewWithOptions(opts *Options) *MemIdm { 28 if opts == nil { 29 opts = &Options{OSType: avfs.CurrentOSType()} 30 } 31 32 idm := &MemIdm{ 33 groupsByName: make(groupsByName), 34 groupsById: make(groupsById), 35 usersByName: make(usersByName), 36 usersById: make(usersById), 37 maxGid: minGid, 38 maxUid: minUid, 39 } 40 41 _ = idm.SetFeatures(avfs.FeatIdentityMgr) 42 _ = idm.SetOSType(opts.OSType) 43 44 adminGroupName := avfs.AdminGroupName(idm.OSType()) 45 adminUserName := avfs.AdminUserName(idm.OSType()) 46 47 idm.adminGroup = &MemGroup{ 48 name: adminGroupName, 49 gid: 0, 50 } 51 52 idm.adminUser = &MemUser{ 53 name: adminUserName, 54 uid: 0, 55 gid: 0, 56 } 57 58 idm.groupsById[0] = idm.adminGroup 59 idm.groupsByName[adminGroupName] = idm.adminGroup 60 idm.usersById[0] = idm.adminUser 61 idm.usersByName[adminUserName] = idm.adminUser 62 63 return idm 64 } 65 66 // Type returns the type of the Identity manager. 67 func (*MemIdm) Type() string { 68 return "MemIdm" 69 }