github.com/avfs/avfs@v0.33.1-0.20240303173310-c6ba67c33eb7/idm/osidm/osidm_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 osidm
    18  
    19  import (
    20  	"math"
    21  
    22  	"github.com/avfs/avfs"
    23  )
    24  
    25  // New creates a new OsIdm identity manager.
    26  func New() *OsIdm {
    27  	osType := avfs.CurrentOSType()
    28  	uid, gid := 0, 0
    29  	GroupName, UserName := avfs.AdminGroupName(osType), avfs.AdminUserName(osType)
    30  	features := avfs.FeatIdentityMgr
    31  
    32  	if !isUserAdmin() {
    33  		features |= avfs.FeatReadOnlyIdm
    34  	}
    35  
    36  	if osType == avfs.OsWindows {
    37  		features = 0
    38  		uid, gid = math.MaxInt, math.MaxInt
    39  		GroupName, UserName = avfs.DefaultName, avfs.DefaultName
    40  	}
    41  
    42  	adminGroup := &OsGroup{name: GroupName, gid: gid}
    43  	adminUser := &OsUser{name: UserName, uid: uid, gid: gid}
    44  
    45  	idm := &OsIdm{
    46  		adminGroup: adminGroup,
    47  		adminUser:  adminUser,
    48  	}
    49  
    50  	_ = idm.SetFeatures(features)
    51  
    52  	return idm
    53  }
    54  
    55  // OSType returns the operating system type of the identity manager.
    56  func (idm *OsIdm) OSType() avfs.OSType {
    57  	return avfs.CurrentOSType()
    58  }
    59  
    60  // Type returns the type of the fileSystem or Identity manager.
    61  func (idm *OsIdm) Type() string {
    62  	return "OsIdm"
    63  }