github.com/avfs/avfs@v0.33.1-0.20240303173310-c6ba67c33eb7/idm/osidm/osidm.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 implements an identity manager using os functions.
    18  //
    19  // For testing only, should not be used in a production environment.
    20  package osidm
    21  
    22  import "github.com/avfs/avfs"
    23  
    24  // AdminGroup returns the administrator (root) group.
    25  func (idm *OsIdm) AdminGroup() avfs.GroupReader {
    26  	return idm.adminGroup
    27  }
    28  
    29  // AdminUser returns the administrator (root) user.
    30  func (idm *OsIdm) AdminUser() avfs.UserReader {
    31  	return idm.adminUser
    32  }
    33  
    34  // OsGroup
    35  
    36  // Gid returns the group ID.
    37  func (g *OsGroup) Gid() int {
    38  	return g.gid
    39  }
    40  
    41  // Name returns the group name.
    42  func (g *OsGroup) Name() string {
    43  	return g.name
    44  }
    45  
    46  // OsUser
    47  
    48  // Gid returns the primary group ID of the user.
    49  func (u *OsUser) Gid() int {
    50  	return u.gid
    51  }
    52  
    53  // IsAdmin returns true if the user has administrator (root) privileges.
    54  func (u *OsUser) IsAdmin() bool {
    55  	return u.uid == 0 || u.gid == 0
    56  }
    57  
    58  // Name returns the user name.
    59  func (u *OsUser) Name() string {
    60  	return u.name
    61  }
    62  
    63  // Uid returns the user ID.
    64  func (u *OsUser) Uid() int {
    65  	return u.uid
    66  }