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 ret
= string_to_sid(sid
, value
);
77 *expired
= (timeout
<= time(NULL
));
82 void idmap_cache_set_sid2uid(const struct dom_sid
*sid
, uid_t uid
)
84 time_t now
= time(NULL
);
86 fstring sidstr
, key
, value
;
88 if (!is_null_sid(sid
)) {
89 fstr_sprintf(key
, "IDMAP/SID2UID/%s",
90 sid_to_fstring(sidstr
, sid
));
91 fstr_sprintf(value
, "%d", (int)uid
);
93 ? lp_idmap_negative_cache_time()
94 : lp_idmap_cache_time();
95 gencache_set(key
, value
, now
+ timeout
);
98 fstr_sprintf(key
, "IDMAP/UID2SID/%d", (int)uid
);
99 sid_to_fstring(value
, sid
);
100 timeout
= is_null_sid(sid
)
101 ? lp_idmap_negative_cache_time()
102 : lp_idmap_cache_time();
103 gencache_set(key
, value
, now
+ timeout
);
107 bool idmap_cache_find_sid2gid(const struct dom_sid
*sid
, gid_t
*pgid
,
118 key
= talloc_asprintf(talloc_tos(), "IDMAP/SID2GID/%s",
119 sid_to_fstring(sidstr
, sid
));
123 ret
= gencache_get(key
, &value
, &timeout
);
128 gid
= strtol(value
, &endptr
, 10);
129 ret
= (*endptr
== '\0');
133 *expired
= (timeout
<= time(NULL
));
138 bool idmap_cache_find_gid2sid(gid_t gid
, struct dom_sid
*sid
, bool *expired
)
145 key
= talloc_asprintf(talloc_tos(), "IDMAP/GID2SID/%d", (int)gid
);
149 ret
= gencache_get(key
, &value
, &timeout
);
155 ret
= string_to_sid(sid
, value
);
158 *expired
= (timeout
<= time(NULL
));
163 void idmap_cache_set_sid2gid(const struct dom_sid
*sid
, gid_t gid
)
165 time_t now
= time(NULL
);
167 fstring sidstr
, key
, value
;
169 if (!is_null_sid(sid
)) {
170 fstr_sprintf(key
, "IDMAP/SID2GID/%s",
171 sid_to_fstring(sidstr
, sid
));
172 fstr_sprintf(value
, "%d", (int)gid
);
173 timeout
= (gid
== -1)
174 ? lp_idmap_negative_cache_time()
175 : lp_idmap_cache_time();
176 gencache_set(key
, value
, now
+ timeout
);
179 fstr_sprintf(key
, "IDMAP/GID2SID/%d", (int)gid
);
180 sid_to_fstring(value
, sid
);
181 timeout
= is_null_sid(sid
)
182 ? lp_idmap_negative_cache_time()
183 : lp_idmap_cache_time();
184 gencache_set(key
, value
, now
+ timeout
);