2 Unix SMB/CIFS implementation.
7 Copyright (C) Simo Sorce 2006
8 Copyright (C) Rafal Szczesniak 2002
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.*/
26 bool idmap_cache_find_sid2uid(const struct dom_sid
*sid
, uid_t
*puid
,
37 key
= talloc_asprintf(talloc_tos(), "IDMAP/SID2UID/%s",
38 sid_to_fstring(sidstr
, sid
));
42 ret
= gencache_get(key
, &value
, &timeout
);
47 uid
= strtol(value
, &endptr
, 10);
48 ret
= (*endptr
== '\0');
52 *expired
= (timeout
<= time(NULL
));
57 bool idmap_cache_find_uid2sid(uid_t uid
, struct dom_sid
*sid
, bool *expired
)
64 key
= talloc_asprintf(talloc_tos(), "IDMAP/UID2SID/%d", (int)uid
);
68 ret
= gencache_get(key
, &value
, &timeout
);
74 if (value
[0] != '-') {
75 ret
= string_to_sid(sid
, value
);
79 *expired
= (timeout
<= time(NULL
));
84 void idmap_cache_set_sid2uid(const struct dom_sid
*sid
, uid_t uid
)
86 time_t now
= time(NULL
);
88 fstring sidstr
, key
, value
;
90 if (!is_null_sid(sid
)) {
91 fstr_sprintf(key
, "IDMAP/SID2UID/%s",
92 sid_to_fstring(sidstr
, sid
));
93 fstr_sprintf(value
, "%d", (int)uid
);
95 ? lp_idmap_negative_cache_time()
96 : lp_idmap_cache_time();
97 gencache_set(key
, value
, now
+ timeout
);
100 fstr_sprintf(key
, "IDMAP/UID2SID/%d", (int)uid
);
101 if (is_null_sid(sid
)) {
102 /* negative uid mapping */
104 timeout
= lp_idmap_negative_cache_time();
107 sid_to_fstring(value
, sid
);
108 timeout
= lp_idmap_cache_time();
110 gencache_set(key
, value
, now
+ timeout
);
114 bool idmap_cache_find_sid2gid(const struct dom_sid
*sid
, gid_t
*pgid
,
125 key
= talloc_asprintf(talloc_tos(), "IDMAP/SID2GID/%s",
126 sid_to_fstring(sidstr
, sid
));
130 ret
= gencache_get(key
, &value
, &timeout
);
135 gid
= strtol(value
, &endptr
, 10);
136 ret
= (*endptr
== '\0');
140 *expired
= (timeout
<= time(NULL
));
145 bool idmap_cache_find_gid2sid(gid_t gid
, struct dom_sid
*sid
, bool *expired
)
152 key
= talloc_asprintf(talloc_tos(), "IDMAP/GID2SID/%d", (int)gid
);
156 ret
= gencache_get(key
, &value
, &timeout
);
162 if (value
[0] != '-') {
163 ret
= string_to_sid(sid
, value
);
167 *expired
= (timeout
<= time(NULL
));
172 void idmap_cache_set_sid2gid(const struct dom_sid
*sid
, gid_t gid
)
174 time_t now
= time(NULL
);
176 fstring sidstr
, key
, value
;
178 if (!is_null_sid(sid
)) {
179 fstr_sprintf(key
, "IDMAP/SID2GID/%s",
180 sid_to_fstring(sidstr
, sid
));
181 fstr_sprintf(value
, "%d", (int)gid
);
182 timeout
= (gid
== -1)
183 ? lp_idmap_negative_cache_time()
184 : lp_idmap_cache_time();
185 gencache_set(key
, value
, now
+ timeout
);
188 fstr_sprintf(key
, "IDMAP/GID2SID/%d", (int)gid
);
189 if (is_null_sid(sid
)) {
190 /* negative gid mapping */
192 timeout
= lp_idmap_negative_cache_time();
195 sid_to_fstring(value
, sid
);
196 timeout
= lp_idmap_cache_time();
198 gencache_set(key
, value
, now
+ timeout
);