summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2007-08-30 19:48:31 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:30:24 -0500
commit929e1d99209e20a9c2c95c8bdfc8eaa37b2c2291 (patch)
tree169c06d247826eac8c3d3054ce8de78fce7d454d /source3/utils
parenta646210b2b8ead5690b3c6baf058c2de6e0c1a26 (diff)
downloadsamba-929e1d99209e20a9c2c95c8bdfc8eaa37b2c2291.tar.gz
samba-929e1d99209e20a9c2c95c8bdfc8eaa37b2c2291.tar.bz2
samba-929e1d99209e20a9c2c95c8bdfc8eaa37b2c2291.zip
r24809: Consolidate the use of temporary talloc contexts.
This adds the two functions talloc_stackframe() and talloc_tos(). * When a new talloc stackframe is allocated with talloc_stackframe(), then * the TALLOC_CTX returned with talloc_tos() is reset to that new * frame. Whenever that stack frame is TALLOC_FREE()'ed, then the reverse * happens: The previous talloc_tos() is restored. * * This API is designed to be robust in the sense that if someone forgets to * TALLOC_FREE() a stackframe, then the next outer one correctly cleans up and * resets the talloc_tos(). The original motivation for this patch was to get rid of the sid_string_static & friends buffers. Explicitly passing talloc context everywhere clutters code too much for my taste, so an implicit talloc_tos() is introduced here. Many of these static buffers are replaced by a single static pointer. The intended use would thus be that low-level functions can rather freely push stuff to talloc_tos, the upper layers clean up by freeing the stackframe. The more of these stackframes are used and correctly freed the more exact the memory cleanup happens. This patch removes the main_loop_talloc_ctx, tmp_talloc_ctx and lp_talloc_ctx (did I forget any?) So, never do a tmp_ctx = talloc_init("foo"); anymore, instead, use tmp_ctx = talloc_stackframe() :-) Volker (This used to be commit 6585ea2cb7f417e14540495b9c7380fe9c8c717b)
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/net_lookup.c4
-rw-r--r--source3/utils/net_sam.c38
2 files changed, 21 insertions, 21 deletions
diff --git a/source3/utils/net_lookup.c b/source3/utils/net_lookup.c
index a775afcdc1..29fea32c9b 100644
--- a/source3/utils/net_lookup.c
+++ b/source3/utils/net_lookup.c
@@ -299,7 +299,7 @@ static int net_lookup_name(int argc, const char **argv)
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ALL,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ALL,
&dom, &name, &sid, &type)) {
d_printf("Could not lookup name %s\n", argv[0]);
return -1;
@@ -326,7 +326,7 @@ static int net_lookup_sid(int argc, const char **argv)
return -1;
}
- if (!lookup_sid(tmp_talloc_ctx(), &sid,
+ if (!lookup_sid(talloc_tos(), &sid,
&dom, &name, &type)) {
d_printf("Could not lookup name %s\n", argv[0]);
return -1;
diff --git a/source3/utils/net_sam.c b/source3/utils/net_sam.c
index 09eb57f95f..3cc838e71b 100644
--- a/source3/utils/net_sam.c
+++ b/source3/utils/net_sam.c
@@ -41,7 +41,7 @@ static int net_sam_userset(int argc, const char **argv, const char *field,
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&dom, &name, &sid, &type)) {
d_fprintf(stderr, "Could not find name %s\n", argv[0]);
return -1;
@@ -138,7 +138,7 @@ static int net_sam_set_userflag(int argc, const char **argv, const char *field,
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&dom, &name, &sid, &type)) {
d_fprintf(stderr, "Could not find name %s\n", argv[0]);
return -1;
@@ -222,7 +222,7 @@ static int net_sam_set_pwdmustchangenow(int argc, const char **argv)
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&dom, &name, &sid, &type)) {
d_fprintf(stderr, "Could not find name %s\n", argv[0]);
return -1;
@@ -283,7 +283,7 @@ static int net_sam_set_comment(int argc, const char **argv)
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&dom, &name, &sid, &type)) {
d_fprintf(stderr, "Could not find name %s\n", argv[0]);
return -1;
@@ -520,18 +520,18 @@ static NTSTATUS map_unix_group(const struct group *grp, GROUP_MAP *pmap)
map.gid = grp->gr_gid;
grpname = grp->gr_name;
- if (lookup_name(tmp_talloc_ctx(), grpname, LOOKUP_NAME_ISOLATED,
+ if (lookup_name(talloc_tos(), grpname, LOOKUP_NAME_ISOLATED,
&dom, &name, NULL, NULL)) {
const char *tmp = talloc_asprintf(
- tmp_talloc_ctx(), "Unix Group %s", grp->gr_name);
+ talloc_tos(), "Unix Group %s", grp->gr_name);
DEBUG(5, ("%s exists as %s\\%s, retrying as \"%s\"\n",
grpname, dom, name, tmp));
grpname = tmp;
}
- if (lookup_name(tmp_talloc_ctx(), grpname, LOOKUP_NAME_ISOLATED,
+ if (lookup_name(talloc_tos(), grpname, LOOKUP_NAME_ISOLATED,
NULL, NULL, NULL, NULL)) {
DEBUG(3, ("\"%s\" exists, can't map it\n", grp->gr_name));
return NT_STATUS_GROUP_EXISTS;
@@ -551,7 +551,7 @@ static NTSTATUS map_unix_group(const struct group *grp, GROUP_MAP *pmap)
sid_compose(&map.sid, get_global_sam_sid(), rid);
map.sid_name_use = SID_NAME_DOM_GRP;
- fstrcpy(map.comment, talloc_asprintf(tmp_talloc_ctx(), "Unix Group %s",
+ fstrcpy(map.comment, talloc_asprintf(talloc_tos(), "Unix Group %s",
grp->gr_name));
status = pdb_add_group_mapping_entry(&map);
@@ -606,7 +606,7 @@ static NTSTATUS unmap_unix_group(const struct group *grp, GROUP_MAP *pmap)
map.gid = grp->gr_gid;
grpname = grp->gr_name;
- if (!lookup_name(tmp_talloc_ctx(), grpname, LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), grpname, LOOKUP_NAME_ISOLATED,
NULL, NULL, NULL, NULL)) {
DEBUG(3, ("\"%s\" does not exist, can't unmap it\n", grp->gr_name));
return NT_STATUS_NO_SUCH_GROUP;
@@ -702,7 +702,7 @@ static int net_sam_deletelocalgroup(int argc, const char **argv)
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&dom, &name, &sid, &type)) {
d_fprintf(stderr, "Could not find %s.\n", argv[0]);
return -1;
@@ -755,7 +755,7 @@ static int net_sam_createbuiltingroup(int argc, const char **argv)
fstrcpy( groupname, "BUILTIN\\" );
fstrcat( groupname, argv[0] );
- if ( !lookup_name(tmp_talloc_ctx(), groupname, LOOKUP_NAME_ALL, NULL,
+ if ( !lookup_name(talloc_tos(), groupname, LOOKUP_NAME_ALL, NULL,
NULL, &sid, &type)) {
d_fprintf(stderr, "%s is not a BUILTIN group\n", argv[0]);
return -1;
@@ -795,7 +795,7 @@ static int net_sam_addmem(int argc, const char **argv)
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&groupdomain, &groupname, &group, &grouptype)) {
d_fprintf(stderr, "Could not find group %s\n", argv[0]);
return -1;
@@ -803,7 +803,7 @@ static int net_sam_addmem(int argc, const char **argv)
/* check to see if the member to be added is a name or a SID */
- if (!lookup_name(tmp_talloc_ctx(), argv[1], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[1], LOOKUP_NAME_ISOLATED,
&memberdomain, &membername, &member, &membertype))
{
/* try it as a SID */
@@ -813,7 +813,7 @@ static int net_sam_addmem(int argc, const char **argv)
return -1;
}
- if ( !lookup_sid(tmp_talloc_ctx(), &member, &memberdomain,
+ if ( !lookup_sid(talloc_tos(), &member, &memberdomain,
&membername, &membertype) )
{
d_fprintf(stderr, "Could not resolve SID %s\n", argv[1]);
@@ -868,13 +868,13 @@ static int net_sam_delmem(int argc, const char **argv)
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&groupdomain, &groupname, &group, &grouptype)) {
d_fprintf(stderr, "Could not find group %s\n", argv[0]);
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[1], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[1], LOOKUP_NAME_ISOLATED,
&memberdomain, &membername, &member, NULL)) {
if (!string_to_sid(&member, argv[1])) {
d_fprintf(stderr, "Could not find member %s\n",
@@ -926,7 +926,7 @@ static int net_sam_listmem(int argc, const char **argv)
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&groupdomain, &groupname, &group, &grouptype)) {
d_fprintf(stderr, "Could not find group %s\n", argv[0]);
return -1;
@@ -949,7 +949,7 @@ static int net_sam_listmem(int argc, const char **argv)
(unsigned int)num_members);
for (i=0; i<num_members; i++) {
const char *dom, *name;
- if (lookup_sid(tmp_talloc_ctx(), &members[i],
+ if (lookup_sid(talloc_tos(), &members[i],
&dom, &name, NULL)) {
d_printf(" %s\\%s\n", dom, name);
} else {
@@ -1076,7 +1076,7 @@ static int net_sam_show(int argc, const char **argv)
return -1;
}
- if (!lookup_name(tmp_talloc_ctx(), argv[0], LOOKUP_NAME_ISOLATED,
+ if (!lookup_name(talloc_tos(), argv[0], LOOKUP_NAME_ISOLATED,
&dom, &name, &sid, &type)) {
d_fprintf(stderr, "Could not find name %s\n", argv[0]);
return -1;