2 Unix SMB/CIFS implementation.
4 Helper routines for uid and gid arrays
6 Copyright (C) Guenther Deschner 2009
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.
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.
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/>.
24 /****************************************************************************
25 Add a gid to an array of gids if it's not already there.
26 ****************************************************************************/
28 bool add_gid_to_array_unique(TALLOC_CTX
*mem_ctx
, gid_t gid
,
29 gid_t
**gids
, size_t *num_gids
)
33 if ((*num_gids
!= 0) && (*gids
== NULL
)) {
35 * A former call to this routine has failed to allocate memory
40 for (i
=0; i
<*num_gids
; i
++) {
41 if ((*gids
)[i
] == gid
) {
46 *gids
= talloc_realloc(mem_ctx
, *gids
, gid_t
, *num_gids
+1);
52 (*gids
)[*num_gids
] = gid
;
57 /****************************************************************************
58 Add a uid to an array of uids if it's not already there.
59 ****************************************************************************/
61 bool add_uid_to_array_unique(TALLOC_CTX
*mem_ctx
, uid_t uid
,
62 uid_t
**uids
, size_t *num_uids
)
66 if ((*num_uids
!= 0) && (*uids
== NULL
)) {
68 * A former call to this routine has failed to allocate memory
73 for (i
=0; i
<*num_uids
; i
++) {
74 if ((*uids
)[i
] == uid
) {
79 *uids
= talloc_realloc(mem_ctx
, *uids
, uid_t
, *num_uids
+1);
85 (*uids
)[*num_uids
] = uid
;