1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-27 03:21:53 +03:00

r608: - a couple of very minor fixes to the CreateGroup code

- added samr_GetUserPwInfo() samr server call
This commit is contained in:
Andrew Tridgell 2004-05-09 12:32:25 +00:00 committed by Gerald (Jerry) Carter
parent 64121aa1a9
commit 0250f5d6aa
2 changed files with 49 additions and 11 deletions

View File

@ -445,7 +445,7 @@ static void samr_Account_destroy(struct dcesrv_connection *conn, struct dcesrv_h
samr_CreateDomainGroup
*/
static NTSTATUS samr_CreateDomainGroup(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
struct samr_CreateDomainGroup *r)
struct samr_CreateDomainGroup *r)
{
struct samr_domain_state *d_state;
struct samr_account_state *state;
@ -475,7 +475,7 @@ static NTSTATUS samr_CreateDomainGroup(struct dcesrv_call_state *dce_call, TALLO
/* check if the group already exists */
name = samdb_search_string(d_state->sam_ctx, mem_ctx, d_state->basedn,
"name",
"sAMAccountName",
"(&(sAMAccountName=%s)(objectclass=group))",
groupname);
if (name != NULL) {
@ -533,7 +533,7 @@ static NTSTATUS samr_CreateDomainGroup(struct dcesrv_call_state *dce_call, TALLO
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
/* create user state and new policy handle */
/* create group state and new policy handle */
mem_ctx2 = talloc_init("CreateDomainGroup(%s)", groupname);
if (!mem_ctx2) {
return NT_STATUS_NO_MEMORY;
@ -620,7 +620,8 @@ static NTSTATUS samr_CreateUser2(struct dcesrv_call_state *dce_call, TALLOC_CTX
/* check if the user already exists */
name = samdb_search_string(d_state->sam_ctx, mem_ctx, d_state->basedn,
"name", "(&(sAMAccountName=%s)(objectclass=user))", username);
"sAMAccountName",
"(&(sAMAccountName=%s)(objectclass=user))", username);
if (name != NULL) {
return NT_STATUS_USER_EXISTS;
}
@ -1611,9 +1612,22 @@ static NTSTATUS samr_TestPrivateFunctionsUser(struct dcesrv_call_state *dce_call
samr_GetUserPwInfo
*/
static NTSTATUS samr_GetUserPwInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
struct samr_GetUserPwInfo *r)
struct samr_GetUserPwInfo *r)
{
DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
struct dcesrv_handle *h;
struct samr_account_state *state;
ZERO_STRUCT(r->out.info);
DCESRV_PULL_HANDLE(h, r->in.handle, SAMR_HANDLE_USER);
state = h->data;
r->out.info.min_pwd_len = samdb_search_uint(state->sam_ctx, mem_ctx, 0, NULL, "minPwdLength",
"dn=%s", state->domain_state->basedn);
r->out.info.password_properties = samdb_search_uint(state->sam_ctx, mem_ctx, 0, NULL, "pwdProperties",
"dn=%s", state->basedn);
return NT_STATUS_OK;
}

View File

@ -205,6 +205,33 @@ const char *samdb_search_string(void *ctx,
return str;
}
/*
search the sam for a single integer attribute in exactly 1 record
*/
uint_t samdb_search_uint(void *ctx,
TALLOC_CTX *mem_ctx,
uint_t default_value,
const char *basedn,
const char *attr_name,
const char *format, ...)
{
va_list ap;
int count;
struct ldb_message **res;
const char * const attrs[2] = { attr_name, NULL };
va_start(ap, format);
count = samdb_search_v(ctx, mem_ctx, basedn, &res, attrs, format, ap);
va_end(ap);
if (count != 1) {
return default_value;
}
return samdb_result_uint(res[0], attr_name, default_value);
}
/*
search the sam for multipe records each giving a single string attribute
return the number of matches, or -1 on error
@ -426,11 +453,8 @@ int samdb_copy_template(void *ctx, TALLOC_CTX *mem_ctx,
}
for (j=0;j<el->num_values;j++) {
if (strcasecmp(el->name, "objectClass") == 0 &&
strcasecmp((char *)el->values[j].data, "userTemplate") == 0) {
continue;
}
if (strcasecmp(el->name, "objectClass") == 0 &&
strcasecmp((char *)el->values[j].data, "groupTemplate") == 0) {
(strcasecmp((char *)el->values[j].data, "userTemplate") == 0 ||
strcasecmp((char *)el->values[j].data, "groupTemplate") == 0)) {
continue;
}
samdb_msg_add_string(ctx, mem_ctx, msg, el->name,