packaging: Add missing quotes in smbprint
[Samba.git] / lib / util / util_id.c
blob19486f942d4f5bac7d3a902b1248f34a806fdc01
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 "replace.h"
23 #include "lib/util/samba_util.h"
25 /****************************************************************************
26 Add a gid to an array of gids if it's not already there.
27 ****************************************************************************/
29 bool add_gid_to_array_unique(TALLOC_CTX *mem_ctx, gid_t gid,
30 gid_t **gids, uint32_t *num_gids)
32 uint32_t i;
34 if ((*num_gids != 0) && (*gids == NULL)) {
36 * A former call to this routine has failed to allocate memory
38 return false;
41 for (i=0; i<*num_gids; i++) {
42 if ((*gids)[i] == gid) {
43 return true;
47 *gids = talloc_realloc(mem_ctx, *gids, gid_t, *num_gids+1);
48 if (*gids == NULL) {
49 *num_gids = 0;
50 return false;
53 (*gids)[*num_gids] = gid;
54 *num_gids += 1;
55 return true;
58 /****************************************************************************
59 Add a uid to an array of uids if it's not already there.
60 ****************************************************************************/
62 bool add_uid_to_array_unique(TALLOC_CTX *mem_ctx, uid_t uid,
63 uid_t **uids, uint32_t *num_uids)
65 uint32_t i;
67 if ((*num_uids != 0) && (*uids == NULL)) {
69 * A former call to this routine has failed to allocate memory
71 return false;
74 for (i=0; i<*num_uids; i++) {
75 if ((*uids)[i] == uid) {
76 return true;
80 *uids = talloc_realloc(mem_ctx, *uids, uid_t, *num_uids+1);
81 if (*uids == NULL) {
82 *num_uids = 0;
83 return false;
86 (*uids)[*num_uids] = uid;
87 *num_uids += 1;
88 return true;