]>
git.proxmox.com Git - ceph.git/blob - ceph/src/client/UserPerm.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2016 Red Hat
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #ifndef CEPH_CLIENT_USERPERM_H
16 #define CEPH_CLIENT_USERPERM_H
26 void deep_copy_from(const UserPerm
& b
) {
33 gid_count
= b
.gid_count
;
35 gids
= new gid_t
[gid_count
];
37 for (int i
= 0; i
< gid_count
; ++i
) {
43 UserPerm() : m_uid(-1), m_gid(-1), gid_count(0),
44 gids(NULL
), alloced_gids(false) {}
45 UserPerm(uid_t uid
, gid_t gid
, int ngids
=0, gid_t
*gidlist
=NULL
) :
46 m_uid(uid
), m_gid(gid
), gid_count(ngids
),
47 gids(gidlist
), alloced_gids(false) {}
48 UserPerm(const UserPerm
& o
) : UserPerm() {
51 UserPerm(UserPerm
&& o
) {
54 gid_count
= o
.gid_count
;
56 alloced_gids
= o
.alloced_gids
;
64 UserPerm
& operator=(const UserPerm o
) {
69 uid_t
uid() const { return m_uid
!= (uid_t
)-1 ? m_uid
: ::geteuid(); }
70 gid_t
gid() const { return m_gid
!= (gid_t
)-1 ? m_gid
: ::getegid(); }
71 bool gid_in_groups(gid_t id
) const {
72 if (id
== gid()) return true;
73 for (int i
= 0; i
< gid_count
; ++i
) {
74 if (id
== gids
[i
]) return true;
78 int get_gids(const gid_t
**_gids
) const { *_gids
= gids
; return gid_count
; }
79 void init_gids(gid_t
* _gids
, int count
) {
84 void shallow_copy(const UserPerm
& o
) {
87 gid_count
= o
.gid_count
;