selftest/knownfail: ignore samba3.smb2.oplock.exclusive5 failures in v4-1-*
[Samba.git] / lib / util / util_id.c
blobd5a8c66f5ecd9afa013af95e4a0181e5d0ac9539
1 /*
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/>.
22 #include "includes.h"
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, uint32_t *num_gids)
31 int i;
33 if ((*num_gids != 0) && (*gids == NULL)) {
35 * A former call to this routine has failed to allocate memory
37 return false;
40 for (i=0; i<*num_gids; i++) {
41 if ((*gids)[i] == gid) {
42 return true;
46 *gids = talloc_realloc(mem_ctx, *gids, gid_t, *num_gids+1);
47 if (*gids == NULL) {
48 *num_gids = 0;
49 return false;
52 (*gids)[*num_gids] = gid;
53 *num_gids += 1;
54 return true;
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, uint32_t *num_uids)
64 int i;
66 if ((*num_uids != 0) && (*uids == NULL)) {
68 * A former call to this routine has failed to allocate memory
70 return false;
73 for (i=0; i<*num_uids; i++) {
74 if ((*uids)[i] == uid) {
75 return true;
79 *uids = talloc_realloc(mem_ctx, *uids, uid_t, *num_uids+1);
80 if (*uids == NULL) {
81 *num_uids = 0;
82 return false;
85 (*uids)[*num_uids] = uid;
86 *num_uids += 1;
87 return true;