Line data Source code
1 : /*
2 : SSSD
3 :
4 : NSS Responder
5 :
6 : Copyright (C) Petr Čech <pcech@redhat.com> 2016
7 :
8 : This program is free software; you can redistribute it and/or modify
9 : it under the terms of the GNU General Public License as published by
10 : the Free Software Foundation; either version 3 of the License, or
11 : (at your option) any later version.
12 :
13 : This program is distributed in the hope that it will be useful,
14 : but WITHOUT ANY WARRANTY; without even the implied warranty of
15 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 : GNU General Public License for more details.
17 :
18 : You should have received a copy of the GNU General Public License
19 : along with this program. If not, see <http://www.gnu.org/licenses/>.
20 : */
21 :
22 : #include <sys/types.h>
23 : #include <pwd.h>
24 : #include <grp.h>
25 : #include "util/util.h"
26 : #include "responder/common/negcache_files.h"
27 :
28 : #define BUFFER_SIZE 16384
29 :
30 69 : bool is_user_local_by_name(const char *name)
31 : {
32 69 : struct passwd pwd = { 0 };
33 : struct passwd *pwd_result;
34 : char buffer[BUFFER_SIZE];
35 69 : bool is_local = false;
36 : int ret;
37 :
38 69 : ret = getpwnam_r(name, &pwd, buffer, BUFFER_SIZE, &pwd_result);
39 69 : if (ret == EOK && pwd_result != NULL) {
40 32 : DEBUG(SSSDBG_TRACE_FUNC, "User %s is a local user\n", name);
41 32 : is_local = true;
42 : }
43 :
44 69 : return is_local;
45 : }
46 :
47 8 : bool is_user_local_by_uid(uid_t uid)
48 : {
49 8 : struct passwd pwd = { 0 };
50 : struct passwd *pwd_result;
51 : char buffer[BUFFER_SIZE];
52 8 : bool is_local = false;
53 : int ret;
54 :
55 8 : ret = getpwuid_r(uid, &pwd, buffer, BUFFER_SIZE, &pwd_result);
56 8 : if (ret == EOK && pwd_result != NULL) {
57 7 : DEBUG(SSSDBG_TRACE_FUNC,
58 : "User with UID %"SPRIuid" is a local user\n", uid);
59 7 : is_local = true;
60 : }
61 :
62 8 : return is_local;
63 : }
64 :
65 56 : bool is_group_local_by_name(const char *name)
66 : {
67 56 : struct group grp = { 0 };
68 : struct group *grp_result;
69 : char buffer[BUFFER_SIZE];
70 56 : bool is_local = false;
71 : int ret;
72 :
73 56 : ret = getgrnam_r(name, &grp, buffer, BUFFER_SIZE, &grp_result);
74 56 : if (ret == EOK && grp_result != NULL) {
75 32 : DEBUG(SSSDBG_TRACE_FUNC, "Group %s is a local group\n", name);
76 32 : is_local = true;
77 : }
78 :
79 56 : return is_local;
80 : }
81 :
82 4 : bool is_group_local_by_gid(uid_t gid)
83 : {
84 4 : struct group grp = { 0 };
85 : struct group *grp_result;
86 : char buffer[BUFFER_SIZE];
87 4 : bool is_local = false;
88 : int ret;
89 :
90 4 : ret = getgrgid_r(gid, &grp, buffer, BUFFER_SIZE, &grp_result);
91 4 : if (ret == EOK && grp_result != NULL) {
92 2 : DEBUG(SSSDBG_TRACE_FUNC,
93 : "Group with GID %"SPRIgid" is a local group\n", gid);
94 2 : is_local = true;
95 : }
96 :
97 4 : return is_local;
98 : }
|