1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

r23770: Some minor cleanups in libgpo

(including some valgrind errors, uninitialized vars, etc.)

Guenther
(This used to be commit 1a2878db2d)
This commit is contained in:
Günther Deschner 2007-07-09 15:48:17 +00:00 committed by Gerald (Jerry) Carter
parent 5e4962d9e7
commit 5512dacbca
4 changed files with 184 additions and 131 deletions

View File

@ -24,8 +24,7 @@
explode the GPO CIFS URI into their components
****************************************************************/
NTSTATUS ads_gpo_explode_filesyspath(ADS_STRUCT *ads,
TALLOC_CTX *mem_ctx,
NTSTATUS gpo_explode_filesyspath(TALLOC_CTX *mem_ctx,
const char *file_sys_path,
char **server,
char **service,
@ -40,6 +39,10 @@ NTSTATUS ads_gpo_explode_filesyspath(ADS_STRUCT *ads,
*nt_path = NULL;
*unix_path = NULL;
if (!file_sys_path) {
return NT_STATUS_OK;
}
if (!next_token(&file_sys_path, tok, "\\", sizeof(tok))) {
return NT_STATUS_INVALID_PARAMETER;
}
@ -76,8 +79,7 @@ NTSTATUS ads_gpo_explode_filesyspath(ADS_STRUCT *ads,
prepare the local disc storage for "unix_path"
****************************************************************/
NTSTATUS ads_gpo_prepare_local_store(ADS_STRUCT *ads,
TALLOC_CTX *mem_ctx,
static NTSTATUS gpo_prepare_local_store(TALLOC_CTX *mem_ctx,
const char *unix_path)
{
const char *top_dir = lock_path(GPO_CACHE_DIR);
@ -115,21 +117,20 @@ NTSTATUS ads_gpo_prepare_local_store(ADS_STRUCT *ads,
download a full GPO via CIFS
****************************************************************/
NTSTATUS ads_fetch_gpo_files(ADS_STRUCT *ads,
TALLOC_CTX *mem_ctx,
NTSTATUS gpo_fetch_files(TALLOC_CTX *mem_ctx,
struct cli_state *cli,
struct GROUP_POLICY_OBJECT *gpo)
{
NTSTATUS result;
char *server, *service, *nt_path, *unix_path, *nt_ini_path, *unix_ini_path;
result = ads_gpo_explode_filesyspath(ads, mem_ctx, gpo->file_sys_path,
result = gpo_explode_filesyspath(mem_ctx, gpo->file_sys_path,
&server, &service, &nt_path, &unix_path);
if (!NT_STATUS_IS_OK(result)) {
goto out;
}
result = ads_gpo_prepare_local_store(ads, mem_ctx, unix_path);
result = gpo_prepare_local_store(mem_ctx, unix_path);
if (!NT_STATUS_IS_OK(result)) {
goto out;
}
@ -161,23 +162,26 @@ NTSTATUS ads_fetch_gpo_files(ADS_STRUCT *ads,
get the locally stored gpt.ini version number
****************************************************************/
NTSTATUS ads_gpo_get_sysvol_gpt_version(ADS_STRUCT *ads,
TALLOC_CTX *mem_ctx,
NTSTATUS gpo_get_sysvol_gpt_version(TALLOC_CTX *mem_ctx,
const char *unix_path,
uint32 *sysvol_version,
char **display_name)
{
NTSTATUS status;
uint32 version;
uint32 version = 0;
char *local_path = NULL;
char *name = NULL;
if (!unix_path) {
return NT_STATUS_OK;
}
local_path = talloc_asprintf(mem_ctx, "%s/%s", unix_path, GPT_INI);
NT_STATUS_HAVE_NO_MEMORY(local_path);
status = parse_gpt_ini(mem_ctx, local_path, &version, &name);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(10,("ads_gpo_get_sysvol_gpt_version: failed to parse ini [%s]: %s\n",
DEBUG(10,("gpo_get_sysvol_gpt_version: failed to parse ini [%s]: %s\n",
unix_path, nt_errstr(status)));
return status;
}

View File

@ -28,14 +28,24 @@
ADS_STATUS ads_parse_gp_ext(TALLOC_CTX *mem_ctx,
const char *extension_raw,
struct GP_EXT *gp_ext)
struct GP_EXT **gp_ext)
{
struct GP_EXT *ext = NULL;
char **ext_list;
char **ext_strings = NULL;
int i;
if (!extension_raw) {
goto parse_error;
}
DEBUG(20,("ads_parse_gp_ext: %s\n", extension_raw));
ext = TALLOC_ZERO_P(mem_ctx, struct GP_EXT);
if (!ext) {
goto parse_error;
}
ext_list = str_list_make_talloc(mem_ctx, extension_raw, "]");
if (ext_list == NULL) {
goto parse_error;
@ -45,28 +55,28 @@ ADS_STATUS ads_parse_gp_ext(TALLOC_CTX *mem_ctx,
/* no op */
}
gp_ext->num_exts = i;
ext->num_exts = i;
if (gp_ext->num_exts) {
gp_ext->extensions = TALLOC_ZERO_ARRAY(mem_ctx, char *, gp_ext->num_exts);
gp_ext->extensions_guid = TALLOC_ZERO_ARRAY(mem_ctx, char *, gp_ext->num_exts);
gp_ext->snapins = TALLOC_ZERO_ARRAY(mem_ctx, char *, gp_ext->num_exts);
gp_ext->snapins_guid = TALLOC_ZERO_ARRAY(mem_ctx, char *, gp_ext->num_exts);
if (ext->num_exts) {
ext->extensions = TALLOC_ZERO_ARRAY(mem_ctx, char *, ext->num_exts);
ext->extensions_guid = TALLOC_ZERO_ARRAY(mem_ctx, char *, ext->num_exts);
ext->snapins = TALLOC_ZERO_ARRAY(mem_ctx, char *, ext->num_exts);
ext->snapins_guid = TALLOC_ZERO_ARRAY(mem_ctx, char *, ext->num_exts);
} else {
gp_ext->extensions = NULL;
gp_ext->extensions_guid = NULL;
gp_ext->snapins = NULL;
gp_ext->snapins_guid = NULL;
ext->extensions = NULL;
ext->extensions_guid = NULL;
ext->snapins = NULL;
ext->snapins_guid = NULL;
}
if (gp_ext->extensions == NULL || gp_ext->extensions_guid == NULL ||
gp_ext->snapins == NULL || gp_ext->snapins_guid == NULL ||
gp_ext->gp_extension == NULL) {
ext->gp_extension = talloc_strdup(mem_ctx, extension_raw);
if (ext->extensions == NULL || ext->extensions_guid == NULL ||
ext->snapins == NULL || ext->snapins_guid == NULL ||
ext->gp_extension == NULL) {
goto parse_error;
}
gp_ext->gp_extension = talloc_strdup(mem_ctx, extension_raw);
for (i = 0; ext_list[i] != NULL; i++) {
int k;
@ -95,11 +105,11 @@ ADS_STATUS ads_parse_gp_ext(TALLOC_CTX *mem_ctx,
q++;
}
gp_ext->extensions[i] = talloc_strdup(mem_ctx, cse_gpo_guid_string_to_name(q));
gp_ext->extensions_guid[i] = talloc_strdup(mem_ctx, q);
ext->extensions[i] = talloc_strdup(mem_ctx, cse_gpo_guid_string_to_name(q));
ext->extensions_guid[i] = talloc_strdup(mem_ctx, q);
/* we might have no name for the guid */
if (gp_ext->extensions_guid[i] == NULL) {
if (ext->extensions_guid[i] == NULL) {
goto parse_error;
}
@ -112,11 +122,11 @@ ADS_STATUS ads_parse_gp_ext(TALLOC_CTX *mem_ctx,
}
/* FIXME: theoretically there could be more than one snapin per extension */
gp_ext->snapins[i] = talloc_strdup(mem_ctx, cse_snapin_gpo_guid_string_to_name(m));
gp_ext->snapins_guid[i] = talloc_strdup(mem_ctx, m);
ext->snapins[i] = talloc_strdup(mem_ctx, cse_snapin_gpo_guid_string_to_name(m));
ext->snapins_guid[i] = talloc_strdup(mem_ctx, m);
/* we might have no name for the guid */
if (gp_ext->snapins_guid[i] == NULL) {
if (ext->snapins_guid[i] == NULL) {
goto parse_error;
}
}
@ -129,6 +139,8 @@ ADS_STATUS ads_parse_gp_ext(TALLOC_CTX *mem_ctx,
str_list_free_talloc(mem_ctx, &ext_strings);
}
*gp_ext = ext;
return ADS_ERROR(LDAP_SUCCESS);
parse_error:
@ -146,7 +158,7 @@ parse_error:
parse the raw link string into a GP_LINK structure
****************************************************************/
ADS_STATUS ads_parse_gplink(TALLOC_CTX *mem_ctx,
static ADS_STATUS gpo_parse_gplink(TALLOC_CTX *mem_ctx,
const char *gp_link_raw,
uint32 options,
struct GP_LINK *gp_link)
@ -154,7 +166,7 @@ ADS_STATUS ads_parse_gplink(TALLOC_CTX *mem_ctx,
char **link_list;
int i;
DEBUG(10,("ads_parse_gplink: gPLink: %s\n", gp_link_raw));
DEBUG(10,("gpo_parse_gplink: gPLink: %s\n", gp_link_raw));
link_list = str_list_make_talloc(mem_ctx, gp_link_raw, "]");
if (link_list == NULL) {
@ -186,7 +198,7 @@ ADS_STATUS ads_parse_gplink(TALLOC_CTX *mem_ctx,
char *p, *q;
DEBUGADD(10,("ads_parse_gplink: processing link #%d\n", i));
DEBUGADD(10,("gpo_parse_gplink: processing link #%d\n", i));
q = link_list[i];
if (q[0] == '[') {
@ -207,8 +219,8 @@ ADS_STATUS ads_parse_gplink(TALLOC_CTX *mem_ctx,
gp_link->link_opts[i] = atoi(p + 1);
DEBUGADD(10,("ads_parse_gplink: link: %s\n", gp_link->link_names[i]));
DEBUGADD(10,("ads_parse_gplink: opt: %d\n", gp_link->link_opts[i]));
DEBUGADD(10,("gpo_parse_gplink: link: %s\n", gp_link->link_names[i]));
DEBUGADD(10,("gpo_parse_gplink: opt: %d\n", gp_link->link_opts[i]));
}
@ -262,7 +274,7 @@ ADS_STATUS ads_get_gpo_link(ADS_STRUCT *ads,
return ADS_ERROR(LDAP_NO_SUCH_ATTRIBUTE);
}
/* perfectly leggal to have no options */
/* perfectly legal to have no options */
if (!ads_pull_uint32(ads, res, "gPOptions", &gp_options)) {
DEBUG(10,("ads_get_gpo_link: no 'gPOptions' attribute found\n"));
gp_options = 0;
@ -270,7 +282,7 @@ ADS_STATUS ads_get_gpo_link(ADS_STRUCT *ads,
ads_msgfree(ads, res);
return ads_parse_gplink(mem_ctx, gp_link, gp_options, gp_link_struct);
return gpo_parse_gplink(mem_ctx, gp_link, gp_options, gp_link_struct);
}
/****************************************************************
@ -518,7 +530,7 @@ ADS_STATUS ads_get_gpo(ADS_STRUCT *ads,
add a gplink to the GROUP_POLICY_OBJECT linked list
****************************************************************/
ADS_STATUS add_gplink_to_gpo_list(ADS_STRUCT *ads,
static ADS_STATUS add_gplink_to_gpo_list(ADS_STRUCT *ads,
TALLOC_CTX *mem_ctx,
struct GROUP_POLICY_OBJECT **gpo_list,
const char *link_dn,
@ -581,7 +593,7 @@ ADS_STATUS add_gplink_to_gpo_list(ADS_STRUCT *ads,
/****************************************************************
****************************************************************/
ADS_STATUS ads_get_gpo_sid_token(ADS_STRUCT *ads,
static ADS_STATUS ads_get_gpo_sid_token(ADS_STRUCT *ads,
TALLOC_CTX *mem_ctx,
const char *dn,
struct GPO_SID_TOKEN **token)

View File

@ -240,35 +240,52 @@ void dump_gpo(TALLOC_CTX *mem_ctx, struct GROUP_POLICY_OBJECT *gpo, int debuglev
break;
}
DEBUGADD(lvl,("machine_extensions:\t%s\n", gpo->machine_extensions));
if (gpo->machine_extensions) {
struct GP_EXT gp_ext;
struct GP_EXT *gp_ext = NULL;
ADS_STATUS status;
DEBUGADD(lvl,("machine_extensions:\t%s\n", gpo->machine_extensions));
status = ads_parse_gp_ext(mem_ctx, gpo->machine_extensions, &gp_ext);
if (!ADS_ERR_OK(status)) {
return;
}
dump_gp_ext(&gp_ext, lvl);
dump_gp_ext(gp_ext, lvl);
}
DEBUGADD(lvl,("user_extensions:\t%s\n", gpo->user_extensions));
if (gpo->user_extensions) {
struct GP_EXT gp_ext;
struct GP_EXT *gp_ext = NULL;
ADS_STATUS status;
DEBUGADD(lvl,("user_extensions:\t%s\n", gpo->user_extensions));
status = ads_parse_gp_ext(mem_ctx, gpo->user_extensions, &gp_ext);
if (!ADS_ERR_OK(status)) {
return;
}
dump_gp_ext(&gp_ext, lvl);
dump_gp_ext(gp_ext, lvl);
}
}
/****************************************************************
****************************************************************/
void dump_gpo_list(TALLOC_CTX *mem_ctx,
struct GROUP_POLICY_OBJECT *gpo_list,
int debuglevel)
{
struct GROUP_POLICY_OBJECT *gpo = NULL;
for (gpo = gpo_list; gpo; gpo = gpo->next) {
dump_gpo(mem_ctx, gpo, debuglevel);
}
}
/****************************************************************
****************************************************************/
void dump_gplink(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, struct GP_LINK *gp_link)
{
ADS_STATUS status;
@ -326,6 +343,9 @@ void dump_gplink(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, struct GP_LINK *gp_link)
}
}
/****************************************************************
****************************************************************/
ADS_STATUS process_extension_with_snapin(ADS_STRUCT *ads,
TALLOC_CTX *mem_ctx,
const char *extension_guid,
@ -348,14 +368,17 @@ ADS_STATUS process_extension_with_snapin(ADS_STRUCT *ads,
return ADS_SUCCESS;
}
/****************************************************************
****************************************************************/
ADS_STATUS gpo_process_a_gpo(ADS_STRUCT *ads,
TALLOC_CTX *mem_ctx,
struct GROUP_POLICY_OBJECT *gpo,
const char *extension_guid,
const char *extension_guid_filter,
uint32 flags)
{
ADS_STATUS status;
struct GP_EXT gp_ext;
struct GP_EXT *gp_ext = NULL;
int i;
if (flags & GPO_LIST_FLAG_MACHINE) {
@ -388,14 +411,15 @@ ADS_STATUS gpo_process_a_gpo(ADS_STRUCT *ads,
}
}
for (i=0; i<gp_ext.num_exts; i++) {
for (i=0; i<gp_ext->num_exts; i++) {
if (extension_guid && !strequal(extension_guid, gp_ext.extensions_guid[i])) {
if (extension_guid_filter && !strequal(extension_guid_filter, gp_ext->extensions_guid[i])) {
continue;
}
status = process_extension_with_snapin(ads, mem_ctx, gp_ext.extensions_guid[i],
gp_ext.snapins_guid[i]);
status = process_extension_with_snapin(ads, mem_ctx,
gp_ext->extensions_guid[i],
gp_ext->snapins_guid[i]);
if (!ADS_ERR_OK(status)) {
return status;
}
@ -404,16 +428,19 @@ ADS_STATUS gpo_process_a_gpo(ADS_STRUCT *ads,
return ADS_SUCCESS;
}
/****************************************************************
****************************************************************/
ADS_STATUS gpo_process_gpo_list(ADS_STRUCT *ads,
TALLOC_CTX *mem_ctx,
struct GROUP_POLICY_OBJECT **gpo_list,
struct GROUP_POLICY_OBJECT *gpo_list,
const char *extensions_guid,
uint32 flags)
{
ADS_STATUS status;
struct GROUP_POLICY_OBJECT *gpo = *gpo_list;
struct GROUP_POLICY_OBJECT *gpo;
for (gpo = *gpo_list; gpo; gpo = gpo->next) {
for (gpo = gpo_list; gpo; gpo = gpo->next) {
status = gpo_process_a_gpo(ads, mem_ctx, gpo,
extensions_guid, flags);
@ -455,6 +482,9 @@ ADS_STATUS gpo_lockout_policy(ADS_STRUCT *ads,
return ADS_ERROR_NT(NT_STATUS_NOT_IMPLEMENTED);
}
/****************************************************************
****************************************************************/
ADS_STATUS gpo_password_policy(ADS_STRUCT *ads,
TALLOC_CTX *mem_ctx,
const char *hostname,
@ -512,7 +542,7 @@ ADS_STATUS gpo_password_policy(ADS_STRUCT *ads,
ads_memfree(ads, dn);
status = gpo_process_gpo_list(ads, mem_ctx, &gpo_list,
status = gpo_process_gpo_list(ads, mem_ctx, gpo_list,
cse_gpo_name_to_guid_string("Security"),
GPO_LIST_FLAG_MACHINE);
if (!ADS_ERR_OK(status)) {
@ -533,19 +563,22 @@ NTSTATUS check_refresh_gpo(ADS_STRUCT *ads,
struct cli_state **cli_out)
{
NTSTATUS result;
char *server, *share, *nt_path, *unix_path;
char *server = NULL;
char *share = NULL;
char *nt_path = NULL;
char *unix_path = NULL;
uint32 sysvol_gpt_version = 0;
char *display_name;
char *display_name = NULL;
struct cli_state *cli = NULL;
result = ads_gpo_explode_filesyspath(ads, mem_ctx, gpo->file_sys_path,
result = gpo_explode_filesyspath(mem_ctx, gpo->file_sys_path,
&server, &share, &nt_path, &unix_path);
if (!NT_STATUS_IS_OK(result)) {
goto out;
}
result = ads_gpo_get_sysvol_gpt_version(ads, mem_ctx,
result = gpo_get_sysvol_gpt_version(mem_ctx,
unix_path,
&sysvol_gpt_version,
&display_name);
@ -577,12 +610,12 @@ NTSTATUS check_refresh_gpo(ADS_STRUCT *ads,
*cli_out = cli;
}
result = ads_fetch_gpo_files(ads, mem_ctx, *cli_out, gpo);
result = gpo_fetch_files(mem_ctx, *cli_out, gpo);
if (!NT_STATUS_IS_OK(result)) {
goto out;
}
result = ads_gpo_get_sysvol_gpt_version(ads, mem_ctx,
result = gpo_get_sysvol_gpt_version(mem_ctx,
unix_path,
&sysvol_gpt_version,
&display_name);
@ -627,6 +660,10 @@ NTSTATUS check_refresh_gpo_list(ADS_STRUCT *ads,
struct cli_state *cli = NULL;
struct GROUP_POLICY_OBJECT *gpo;
if (!gpo_list) {
return NT_STATUS_INVALID_PARAMETER;
}
for (gpo = gpo_list; gpo; gpo = gpo->next) {
result = check_refresh_gpo(ads, mem_ctx, gpo, &cli);

View File

@ -50,7 +50,7 @@ static int net_ads_gpo_refresh(int argc, const char **argv)
LDAPMessage *res = NULL;
const char *filter;
char *dn = NULL;
struct GROUP_POLICY_OBJECT *gpo_list;
struct GROUP_POLICY_OBJECT *gpo_list = NULL;
uint32 uac = 0;
uint32 flags = 0;
struct GROUP_POLICY_OBJECT *gpo;
@ -127,7 +127,7 @@ static int net_ads_gpo_refresh(int argc, const char **argv)
GPO_VERSION_USER(gpo->version),
GPO_VERSION_MACHINE(gpo->version));
result = ads_gpo_explode_filesyspath(ads, mem_ctx, gpo->file_sys_path,
result = gpo_explode_filesyspath(mem_ctx, gpo->file_sys_path,
&server, &share, &nt_path, &unix_path);
if (!NT_STATUS_IS_OK(result)) {
printf("got: %s\n", nt_errstr(result));