Skip to content

Commit ae5cda8

Browse files
vlendecslowfranklin
authored andcommitted
nsswitch: Remove next_token() from wbinfo
Signed-off-by: Volker Lendecke <[email protected]> Reviewed-by: Ralph Boehme <[email protected]>
1 parent d83d270 commit ae5cda8

File tree

1 file changed

+61
-47
lines changed

1 file changed

+61
-47
lines changed

nsswitch/wbinfo.c

Lines changed: 61 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,93 +1031,101 @@ static bool wbinfo_sid_to_gid(const char *sid_str)
10311031

10321032
static bool wbinfo_sids_to_unix_ids(const char *arg)
10331033
{
1034-
char sidstr[WBC_SID_STRING_BUFLEN];
1034+
TALLOC_CTX *frame = talloc_stackframe();
1035+
char *sidstr = NULL;
10351036
struct wbcDomainSid *sids;
10361037
struct wbcUnixId *unix_ids;
10371038
int i, num_sids;
10381039
const char *p;
10391040
wbcErr wbc_status;
1040-
1041+
bool ret = false;
10411042

10421043
num_sids = 0;
10431044
sids = NULL;
10441045
p = arg;
10451046

1046-
while (next_token(&p, sidstr, LIST_SEP, sizeof(sidstr))) {
1047-
sids = talloc_realloc(talloc_tos(), sids, struct wbcDomainSid,
1048-
num_sids+1);
1047+
while (next_token_talloc(frame, &p, &sidstr, LIST_SEP)) {
1048+
sids = talloc_realloc(frame,
1049+
sids,
1050+
struct wbcDomainSid,
1051+
num_sids + 1);
10491052
if (sids == NULL) {
10501053
d_fprintf(stderr, "talloc failed\n");
1051-
return false;
1054+
goto fail;
10521055
}
10531056
wbc_status = wbcStringToSid(sidstr, &sids[num_sids]);
10541057
if (!WBC_ERROR_IS_OK(wbc_status)) {
10551058
d_fprintf(stderr, "wbcSidToString(%s) failed: %s\n",
10561059
sidstr, wbcErrorString(wbc_status));
1057-
TALLOC_FREE(sids);
1058-
return false;
1060+
goto fail;
10591061
}
1062+
TALLOC_FREE(sidstr);
10601063
num_sids += 1;
10611064
}
10621065

1063-
unix_ids = talloc_array(talloc_tos(), struct wbcUnixId, num_sids);
1066+
unix_ids = talloc_array(frame, struct wbcUnixId, num_sids);
10641067
if (unix_ids == NULL) {
1065-
TALLOC_FREE(sids);
1066-
return false;
1068+
goto fail;
10671069
}
10681070

10691071
wbc_status = wbcSidsToUnixIds(sids, num_sids, unix_ids);
10701072
if (!WBC_ERROR_IS_OK(wbc_status)) {
10711073
d_fprintf(stderr, "wbcSidsToUnixIds failed: %s\n",
10721074
wbcErrorString(wbc_status));
1073-
TALLOC_FREE(sids);
1074-
return false;
1075+
goto fail;
10751076
}
10761077

10771078
for (i=0; i<num_sids; i++) {
1079+
fstring sidbuf;
10781080

1079-
wbcSidToStringBuf(&sids[i], sidstr, sizeof(sidstr));
1081+
wbcSidToStringBuf(&sids[i], sidbuf, sizeof(sidbuf));
10801082

10811083
switch(unix_ids[i].type) {
10821084
case WBC_ID_TYPE_UID:
1083-
d_printf("%s -> uid %d\n", sidstr, unix_ids[i].id.uid);
1085+
d_printf("%s -> uid %d\n", sidbuf, unix_ids[i].id.uid);
10841086
break;
10851087
case WBC_ID_TYPE_GID:
1086-
d_printf("%s -> gid %d\n", sidstr, unix_ids[i].id.gid);
1088+
d_printf("%s -> gid %d\n", sidbuf, unix_ids[i].id.gid);
10871089
break;
10881090
case WBC_ID_TYPE_BOTH:
1089-
d_printf("%s -> uid/gid %d\n", sidstr, unix_ids[i].id.uid);
1091+
d_printf("%s -> uid/gid %d\n",
1092+
sidbuf,
1093+
unix_ids[i].id.uid);
10901094
break;
10911095
default:
1092-
d_printf("%s -> unmapped\n", sidstr);
1096+
d_printf("%s -> unmapped\n", sidbuf);
10931097
break;
10941098
}
10951099
}
10961100

1097-
TALLOC_FREE(sids);
1098-
TALLOC_FREE(unix_ids);
1099-
1100-
return true;
1101+
ret = true;
1102+
fail:
1103+
TALLOC_FREE(frame);
1104+
return ret;
11011105
}
11021106

11031107
static bool wbinfo_xids_to_sids(const char *arg)
11041108
{
1105-
fstring idstr;
1109+
TALLOC_CTX *frame = talloc_stackframe();
1110+
char *idstr = NULL;
11061111
struct wbcUnixId *xids = NULL;
11071112
struct wbcDomainSid *sids;
11081113
wbcErr wbc_status;
11091114
int num_xids = 0;
11101115
const char *p;
11111116
int i;
1117+
bool ret = false;
11121118

11131119
p = arg;
11141120

1115-
while (next_token(&p, idstr, LIST_SEP, sizeof(idstr))) {
1116-
xids = talloc_realloc(talloc_tos(), xids, struct wbcUnixId,
1117-
num_xids+1);
1121+
while (next_token_talloc(frame, &p, &idstr, LIST_SEP)) {
1122+
xids = talloc_realloc(xids,
1123+
xids,
1124+
struct wbcUnixId,
1125+
num_xids + 1);
11181126
if (xids == NULL) {
11191127
d_fprintf(stderr, "talloc failed\n");
1120-
return false;
1128+
goto fail;
11211129
}
11221130

11231131
switch (idstr[0]) {
@@ -1135,26 +1143,23 @@ static bool wbinfo_xids_to_sids(const char *arg)
11351143
break;
11361144
default:
11371145
d_fprintf(stderr, "%s is an invalid id\n", idstr);
1138-
TALLOC_FREE(xids);
1139-
return false;
1146+
goto fail;
11401147
}
1148+
TALLOC_FREE(idstr);
11411149
num_xids += 1;
11421150
}
11431151

1144-
sids = talloc_array(talloc_tos(), struct wbcDomainSid, num_xids);
1152+
sids = talloc_array(frame, struct wbcDomainSid, num_xids);
11451153
if (sids == NULL) {
11461154
d_fprintf(stderr, "talloc failed\n");
1147-
TALLOC_FREE(xids);
1148-
return false;
1155+
goto fail;
11491156
}
11501157

11511158
wbc_status = wbcUnixIdsToSids(xids, num_xids, sids);
11521159
if (!WBC_ERROR_IS_OK(wbc_status)) {
11531160
d_fprintf(stderr, "wbcUnixIdsToSids failed: %s\n",
11541161
wbcErrorString(wbc_status));
1155-
TALLOC_FREE(sids);
1156-
TALLOC_FREE(xids);
1157-
return false;
1162+
goto fail;
11581163
}
11591164

11601165
for (i=0; i<num_xids; i++) {
@@ -1169,7 +1174,10 @@ static bool wbinfo_xids_to_sids(const char *arg)
11691174
d_printf("%s\n", str);
11701175
}
11711176

1172-
return true;
1177+
ret = true;
1178+
fail:
1179+
TALLOC_FREE(frame);
1180+
return ret;
11731181
}
11741182

11751183
static bool wbinfo_allocate_uid(void)
@@ -1502,34 +1510,37 @@ static bool wbinfo_lookuprids(const char *domain, const char *arg)
15021510

15031511
static bool wbinfo_lookup_sids(const char *arg)
15041512
{
1505-
char sidstr[WBC_SID_STRING_BUFLEN];
1513+
TALLOC_CTX *frame = talloc_stackframe();
1514+
char *sidstr = NULL;
15061515
struct wbcDomainSid *sids;
15071516
struct wbcDomainInfo *domains;
15081517
struct wbcTranslatedName *names;
15091518
int num_domains;
15101519
int i, num_sids;
15111520
const char *p;
15121521
wbcErr wbc_status;
1513-
1522+
bool ret;
15141523

15151524
num_sids = 0;
15161525
sids = NULL;
15171526
p = arg;
15181527

1519-
while (next_token(&p, sidstr, LIST_SEP, sizeof(sidstr))) {
1520-
sids = talloc_realloc(talloc_tos(), sids, struct wbcDomainSid,
1521-
num_sids+1);
1528+
while (next_token_talloc(frame, &p, &sidstr, LIST_SEP)) {
1529+
sids = talloc_realloc(frame,
1530+
sids,
1531+
struct wbcDomainSid,
1532+
num_sids + 1);
15221533
if (sids == NULL) {
15231534
d_fprintf(stderr, "talloc failed\n");
1524-
return false;
1535+
goto fail;
15251536
}
15261537
wbc_status = wbcStringToSid(sidstr, &sids[num_sids]);
15271538
if (!WBC_ERROR_IS_OK(wbc_status)) {
15281539
d_fprintf(stderr, "wbcSidToString(%s) failed: %s\n",
15291540
sidstr, wbcErrorString(wbc_status));
1530-
TALLOC_FREE(sids);
1531-
return false;
1541+
goto fail;
15321542
}
1543+
TALLOC_FREE(sidstr);
15331544
num_sids += 1;
15341545
}
15351546

@@ -1538,8 +1549,7 @@ static bool wbinfo_lookup_sids(const char *arg)
15381549
if (!WBC_ERROR_IS_OK(wbc_status)) {
15391550
d_fprintf(stderr, "wbcLookupSids failed: %s\n",
15401551
wbcErrorString(wbc_status));
1541-
TALLOC_FREE(sids);
1542-
return false;
1552+
goto fail;
15431553
}
15441554

15451555
for (i=0; i<num_sids; i++) {
@@ -1568,7 +1578,11 @@ static bool wbinfo_lookup_sids(const char *arg)
15681578
}
15691579
wbcFreeMemory(names);
15701580
wbcFreeMemory(domains);
1571-
return true;
1581+
1582+
ret = true;
1583+
fail:
1584+
TALLOC_FREE(frame);
1585+
return ret;
15721586
}
15731587

15741588
/* Convert string to sid */

0 commit comments

Comments
 (0)