2008-04-09 14:38:22 +04:00
/*
* Unix SMB / CIFS implementation .
* NetApi User Support
* Copyright ( C ) Guenther Deschner 2008
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
# include "librpc/gen_ndr/libnetapi.h"
# include "lib/netapi/netapi.h"
2008-04-10 23:52:03 +04:00
# include "lib/netapi/netapi_private.h"
2008-04-09 14:38:22 +04:00
# include "lib/netapi/libnetapi.h"
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-07-18 22:12:13 +04:00
static void convert_USER_INFO_X_to_samr_user_info21 ( struct USER_INFO_X * infoX ,
struct samr_UserInfo21 * info21 )
2008-04-09 14:38:22 +04:00
{
uint32_t fields_present = SAMR_FIELD_ACCT_FLAGS ;
struct samr_LogonHours zero_logon_hours ;
struct lsa_BinaryString zero_parameters ;
uint32_t acct_flags = 0 ;
NTTIME password_age ;
2008-07-18 22:12:13 +04:00
ZERO_STRUCTP ( info21 ) ;
2008-04-09 14:38:22 +04:00
ZERO_STRUCT ( zero_logon_hours ) ;
ZERO_STRUCT ( zero_parameters ) ;
2008-07-18 22:12:13 +04:00
if ( infoX - > usriX_name ) {
2008-04-09 14:38:22 +04:00
fields_present | = SAMR_FIELD_FULL_NAME ;
}
2008-07-18 22:12:13 +04:00
if ( infoX - > usriX_password ) {
2008-04-09 14:38:22 +04:00
fields_present | = SAMR_FIELD_PASSWORD ;
}
2008-07-18 22:12:13 +04:00
if ( infoX - > usriX_flags ) {
2008-04-09 14:38:22 +04:00
fields_present | = SAMR_FIELD_ACCT_FLAGS ;
}
2008-07-18 22:12:13 +04:00
if ( infoX - > usriX_name ) {
2008-04-09 14:38:22 +04:00
fields_present | = SAMR_FIELD_FULL_NAME ;
}
2008-07-18 22:12:13 +04:00
if ( infoX - > usriX_home_dir ) {
2008-04-09 14:38:22 +04:00
fields_present | = SAMR_FIELD_HOME_DIRECTORY ;
}
2008-07-18 22:12:13 +04:00
if ( infoX - > usriX_script_path ) {
2008-04-09 14:38:22 +04:00
fields_present | = SAMR_FIELD_LOGON_SCRIPT ;
}
2008-07-18 22:12:13 +04:00
if ( infoX - > usriX_comment ) {
2008-04-09 14:38:22 +04:00
fields_present | = SAMR_FIELD_DESCRIPTION ;
}
2008-07-18 22:12:13 +04:00
if ( infoX - > usriX_password_age ) {
2008-04-09 14:38:22 +04:00
fields_present | = SAMR_FIELD_FORCE_PWD_CHANGE ;
}
2008-07-18 22:12:13 +04:00
acct_flags | = infoX - > usriX_flags | ACB_NORMAL ;
2008-04-09 14:38:22 +04:00
2008-07-18 22:12:13 +04:00
unix_to_nt_time_abs ( & password_age , infoX - > usriX_password_age ) ;
2008-04-09 14:38:22 +04:00
2008-07-18 22:12:13 +04:00
/* TODO: infoX->usriX_priv */
init_samr_user_info21 ( info21 ,
2008-04-09 14:38:22 +04:00
0 ,
0 ,
0 ,
0 ,
0 ,
password_age ,
NULL ,
2008-07-18 22:12:13 +04:00
infoX - > usriX_name ,
infoX - > usriX_home_dir ,
2008-04-09 14:38:22 +04:00
NULL ,
2008-07-18 22:12:13 +04:00
infoX - > usriX_script_path ,
2008-04-09 14:38:22 +04:00
NULL ,
2008-07-18 22:12:13 +04:00
infoX - > usriX_comment ,
2008-04-09 14:38:22 +04:00
NULL ,
NULL ,
& zero_parameters ,
0 ,
0 ,
acct_flags ,
fields_present ,
zero_logon_hours ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ) ;
2008-07-18 22:12:13 +04:00
}
2008-04-09 14:38:22 +04:00
2008-07-18 22:12:13 +04:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-09 14:38:22 +04:00
2008-07-18 22:12:13 +04:00
static NTSTATUS construct_USER_INFO_X ( uint32_t level ,
uint8_t * buffer ,
struct USER_INFO_X * uX )
{
struct USER_INFO_0 * u0 = NULL ;
struct USER_INFO_1 * u1 = NULL ;
struct USER_INFO_2 * u2 = NULL ;
struct USER_INFO_1007 * u1007 = NULL ;
2008-04-09 14:38:22 +04:00
2008-07-18 22:12:13 +04:00
if ( ! buffer | | ! uX ) {
return NT_STATUS_INVALID_PARAMETER ;
}
2008-04-09 14:38:22 +04:00
2008-07-18 22:12:13 +04:00
ZERO_STRUCTP ( uX ) ;
2008-04-09 14:38:22 +04:00
2008-07-18 22:12:13 +04:00
switch ( level ) {
case 0 :
u0 = ( struct USER_INFO_0 * ) buffer ;
uX - > usriX_name = u0 - > usri0_name ;
break ;
case 1 :
u1 = ( struct USER_INFO_1 * ) buffer ;
uX - > usriX_name = u1 - > usri1_name ;
uX - > usriX_password = u1 - > usri1_password ;
uX - > usriX_password_age = u1 - > usri1_password_age ;
uX - > usriX_priv = u1 - > usri1_priv ;
uX - > usriX_home_dir = u1 - > usri1_home_dir ;
uX - > usriX_comment = u1 - > usri1_comment ;
uX - > usriX_flags = u1 - > usri1_flags ;
uX - > usriX_script_path = u1 - > usri1_script_path ;
break ;
case 2 :
u2 = ( struct USER_INFO_2 * ) buffer ;
uX - > usriX_name = u2 - > usri2_name ;
uX - > usriX_password = u2 - > usri2_password ;
uX - > usriX_password_age = u2 - > usri2_password_age ;
uX - > usriX_priv = u2 - > usri2_priv ;
uX - > usriX_home_dir = u2 - > usri2_home_dir ;
uX - > usriX_comment = u2 - > usri2_comment ;
uX - > usriX_flags = u2 - > usri2_flags ;
uX - > usriX_script_path = u2 - > usri2_script_path ;
uX - > usriX_auth_flags = u2 - > usri2_auth_flags ;
uX - > usriX_full_name = u2 - > usri2_full_name ;
uX - > usriX_usr_comment = u2 - > usri2_usr_comment ;
uX - > usriX_parms = u2 - > usri2_parms ;
uX - > usriX_workstations = u2 - > usri2_workstations ;
uX - > usriX_last_logon = u2 - > usri2_last_logon ;
uX - > usriX_last_logoff = u2 - > usri2_last_logoff ;
uX - > usriX_acct_expires = u2 - > usri2_acct_expires ;
uX - > usriX_max_storage = u2 - > usri2_max_storage ;
uX - > usriX_units_per_week = u2 - > usri2_units_per_week ;
uX - > usriX_logon_hours = u2 - > usri2_logon_hours ;
uX - > usriX_bad_pw_count = u2 - > usri2_bad_pw_count ;
uX - > usriX_num_logons = u2 - > usri2_num_logons ;
uX - > usriX_logon_server = u2 - > usri2_logon_server ;
uX - > usriX_country_code = u2 - > usri2_country_code ;
uX - > usriX_code_page = u2 - > usri2_code_page ;
break ;
case 1007 :
u1007 = ( struct USER_INFO_1007 * ) buffer ;
uX - > usriX_comment = u1007 - > usri1007_comment ;
break ;
case 3 :
case 4 :
default :
return NT_STATUS_INVALID_INFO_CLASS ;
2008-04-09 14:38:22 +04:00
}
2008-07-18 22:12:13 +04:00
return NT_STATUS_OK ;
2008-04-09 14:38:22 +04:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetUserAdd_r ( struct libnetapi_ctx * ctx ,
struct NetUserAdd * r )
{
struct cli_state * cli = NULL ;
struct rpc_pipe_client * pipe_cli = NULL ;
NTSTATUS status ;
WERROR werr ;
POLICY_HND connect_handle , domain_handle , user_handle ;
2008-06-02 19:31:00 +04:00
struct lsa_String lsa_account_name ;
2008-04-09 14:38:22 +04:00
struct dom_sid2 * domain_sid = NULL ;
2008-07-18 22:12:13 +04:00
struct samr_UserInfo21 info21 ;
2008-04-09 14:38:22 +04:00
union samr_UserInfo * user_info = NULL ;
struct samr_PwInfo pw_info ;
uint32_t access_granted = 0 ;
uint32_t rid = 0 ;
2008-07-18 22:12:13 +04:00
struct USER_INFO_X uX ;
2008-04-09 14:38:22 +04:00
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
ZERO_STRUCT ( user_handle ) ;
if ( ! r - > in . buffer ) {
return WERR_INVALID_PARAM ;
}
switch ( r - > in . level ) {
case 1 :
break ;
case 2 :
case 3 :
case 4 :
default :
werr = WERR_NOT_SUPPORTED ;
goto done ;
}
2008-04-11 00:04:04 +04:00
werr = libnetapi_open_ipc_connection ( ctx , r - > in . server_name , & cli ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-04-09 14:38:22 +04:00
goto done ;
}
2008-07-20 19:59:30 +04:00
werr = libnetapi_open_pipe ( ctx , cli , & ndr_table_samr . syntax_id ,
& pipe_cli ) ;
2008-04-11 00:44:00 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-04-09 14:38:22 +04:00
goto done ;
}
2008-07-18 22:12:13 +04:00
status = construct_USER_INFO_X ( r - > in . level , r - > in . buffer , & uX ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2008-06-03 01:55:45 +04:00
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
SAMR_ACCESS_OPEN_DOMAIN ,
SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 |
SAMR_DOMAIN_ACCESS_CREATE_USER |
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-04-09 14:38:22 +04:00
goto done ;
}
2008-07-18 22:12:13 +04:00
init_lsa_String ( & lsa_account_name , uX . usriX_name ) ;
2008-04-09 14:38:22 +04:00
status = rpccli_samr_CreateUser2 ( pipe_cli , ctx ,
& domain_handle ,
& lsa_account_name ,
ACB_NORMAL ,
SEC_STD_WRITE_DAC |
SEC_STD_DELETE |
SAMR_USER_ACCESS_SET_PASSWORD |
SAMR_USER_ACCESS_SET_ATTRIBUTES |
SAMR_USER_ACCESS_GET_ATTRIBUTES ,
& user_handle ,
& access_granted ,
& rid ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
status = rpccli_samr_QueryUserInfo ( pipe_cli , ctx ,
& user_handle ,
16 ,
& user_info ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
if ( ! ( user_info - > info16 . acct_flags & ACB_NORMAL ) ) {
werr = WERR_INVALID_PARAM ;
goto done ;
}
status = rpccli_samr_GetUserPwInfo ( pipe_cli , ctx ,
& user_handle ,
& pw_info ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2008-07-18 22:12:13 +04:00
convert_USER_INFO_X_to_samr_user_info21 ( & uX ,
& info21 ) ;
2008-04-09 14:38:22 +04:00
ZERO_STRUCTP ( user_info ) ;
2008-07-18 22:12:13 +04:00
if ( uX . usriX_password ) {
user_info - > info25 . info = info21 ;
2008-04-09 14:38:22 +04:00
2008-07-18 22:43:14 +04:00
init_samr_CryptPasswordEx ( uX . usriX_password ,
& cli - > user_session_key ,
& user_info - > info25 . password ) ;
2008-04-09 14:38:22 +04:00
status = rpccli_samr_SetUserInfo2 ( pipe_cli , ctx ,
& user_handle ,
25 ,
user_info ) ;
2008-07-18 03:10:31 +04:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS ( DCERPC_FAULT_INVALID_TAG ) ) ) {
2008-07-18 22:12:13 +04:00
user_info - > info23 . info = info21 ;
2008-07-18 03:10:31 +04:00
2008-07-18 22:43:14 +04:00
init_samr_CryptPassword ( uX . usriX_password ,
& cli - > user_session_key ,
& user_info - > info23 . password ) ;
2008-07-18 03:10:31 +04:00
status = rpccli_samr_SetUserInfo2 ( pipe_cli , ctx ,
& user_handle ,
23 ,
user_info ) ;
}
2008-04-09 14:38:22 +04:00
} else {
2008-07-18 22:43:14 +04:00
2008-07-18 22:12:13 +04:00
user_info - > info21 = info21 ;
2008-07-18 22:43:14 +04:00
2008-04-09 14:38:22 +04:00
status = rpccli_samr_SetUserInfo ( pipe_cli , ctx ,
& user_handle ,
21 ,
user_info ) ;
}
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto failed ;
}
werr = WERR_OK ;
goto done ;
failed :
2008-04-13 21:11:01 +04:00
rpccli_samr_DeleteUser ( pipe_cli , ctx ,
& user_handle ) ;
2008-04-09 14:38:22 +04:00
done :
if ( ! cli ) {
return werr ;
}
if ( is_valid_policy_hnd ( & user_handle ) ) {
rpccli_samr_Close ( pipe_cli , ctx , & user_handle ) ;
}
2008-07-18 00:44:24 +04:00
if ( ctx - > disable_policy_handle_cache ) {
libnetapi_samr_close_domain_handle ( ctx , & domain_handle ) ;
libnetapi_samr_close_connect_handle ( ctx , & connect_handle ) ;
2008-04-09 14:38:22 +04:00
}
return werr ;
}
2008-04-09 15:35:49 +04:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-16 04:38:13 +04:00
WERROR NetUserAdd_l ( struct libnetapi_ctx * ctx ,
struct NetUserAdd * r )
{
2008-08-12 17:25:06 +04:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetUserAdd ) ;
2008-04-16 04:38:13 +04:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-09 15:35:49 +04:00
WERROR NetUserDel_r ( struct libnetapi_ctx * ctx ,
struct NetUserDel * r )
{
struct cli_state * cli = NULL ;
struct rpc_pipe_client * pipe_cli = NULL ;
NTSTATUS status ;
WERROR werr ;
POLICY_HND connect_handle , builtin_handle , domain_handle , user_handle ;
2008-06-02 19:31:00 +04:00
struct lsa_String lsa_account_name ;
2008-04-09 15:35:49 +04:00
struct samr_Ids user_rids , name_types ;
struct dom_sid2 * domain_sid = NULL ;
struct dom_sid2 user_sid ;
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( builtin_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
ZERO_STRUCT ( user_handle ) ;
2008-04-11 00:04:04 +04:00
werr = libnetapi_open_ipc_connection ( ctx , r - > in . server_name , & cli ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-04-09 15:35:49 +04:00
goto done ;
}
2008-07-20 19:59:30 +04:00
werr = libnetapi_open_pipe ( ctx , cli , & ndr_table_samr . syntax_id ,
& pipe_cli ) ;
2008-04-11 00:44:00 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-04-09 15:35:49 +04:00
goto done ;
}
2008-06-03 01:55:45 +04:00
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
SAMR_ACCESS_OPEN_DOMAIN ,
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-04-09 15:35:49 +04:00
goto done ;
}
status = rpccli_samr_OpenDomain ( pipe_cli , ctx ,
& connect_handle ,
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
CONST_DISCARD ( DOM_SID * , & global_sid_Builtin ) ,
& builtin_handle ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
init_lsa_String ( & lsa_account_name , r - > in . user_name ) ;
status = rpccli_samr_LookupNames ( pipe_cli , ctx ,
& domain_handle ,
1 ,
& lsa_account_name ,
& user_rids ,
& name_types ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
status = rpccli_samr_OpenUser ( pipe_cli , ctx ,
& domain_handle ,
STD_RIGHT_DELETE_ACCESS ,
user_rids . ids [ 0 ] ,
& user_handle ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
sid_compose ( & user_sid , domain_sid , user_rids . ids [ 0 ] ) ;
status = rpccli_samr_RemoveMemberFromForeignDomain ( pipe_cli , ctx ,
& builtin_handle ,
& user_sid ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
status = rpccli_samr_DeleteUser ( pipe_cli , ctx ,
& user_handle ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
werr = WERR_OK ;
done :
if ( ! cli ) {
return werr ;
}
if ( is_valid_policy_hnd ( & user_handle ) ) {
rpccli_samr_Close ( pipe_cli , ctx , & user_handle ) ;
}
2008-07-18 00:44:24 +04:00
if ( ctx - > disable_policy_handle_cache ) {
libnetapi_samr_close_builtin_handle ( ctx , & builtin_handle ) ;
libnetapi_samr_close_domain_handle ( ctx , & domain_handle ) ;
libnetapi_samr_close_connect_handle ( ctx , & connect_handle ) ;
2008-04-09 15:35:49 +04:00
}
return werr ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetUserDel_l ( struct libnetapi_ctx * ctx ,
struct NetUserDel * r )
{
2008-08-12 17:25:06 +04:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetUserDel ) ;
2008-04-09 15:35:49 +04:00
}
2008-04-09 15:47:51 +04:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-07-01 22:19:10 +04:00
static NTSTATUS libnetapi_samr_lookup_user ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * pipe_cli ,
struct policy_handle * domain_handle ,
struct policy_handle * builtin_handle ,
const char * user_name ,
uint32_t rid ,
uint32_t level ,
struct samr_UserInfo21 * * info21 ,
struct sec_desc_buf * * sec_desc )
2008-04-09 15:47:51 +04:00
{
2008-07-01 22:19:10 +04:00
NTSTATUS status ;
struct policy_handle user_handle ;
union samr_UserInfo * user_info = NULL ;
struct samr_RidWithAttributeArray * rid_array = NULL ;
uint32_t access_mask = SEC_STD_READ_CONTROL |
SAMR_USER_ACCESS_GET_ATTRIBUTES |
SAMR_USER_ACCESS_GET_NAME_ETC ;
ZERO_STRUCT ( user_handle ) ;
switch ( level ) {
case 0 :
case 1 :
case 2 :
case 3 :
case 10 :
case 11 :
case 20 :
case 23 :
break ;
default :
return NT_STATUS_INVALID_LEVEL ;
}
if ( level = = 0 ) {
return NT_STATUS_OK ;
}
status = rpccli_samr_OpenUser ( pipe_cli , mem_ctx ,
domain_handle ,
access_mask ,
rid ,
& user_handle ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
status = rpccli_samr_QueryUserInfo ( pipe_cli , mem_ctx ,
& user_handle ,
21 ,
& user_info ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
status = rpccli_samr_QuerySecurity ( pipe_cli , mem_ctx ,
& user_handle ,
SECINFO_DACL ,
sec_desc ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
if ( level = = 1 ) {
status = rpccli_samr_GetGroupsForUser ( pipe_cli , mem_ctx ,
& user_handle ,
& rid_array ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
#if 0
status = rpccli_samr_GetAliasMembership ( pipe_cli , ctx ,
& builtin_handle ,
& sids ,
& rids ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
# endif
}
* info21 = & user_info - > info21 ;
done :
if ( is_valid_policy_hnd ( & user_handle ) ) {
rpccli_samr_Close ( pipe_cli , mem_ctx , & user_handle ) ;
}
return status ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS libnetapi_samr_lookup_user_map_USER_INFO ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * pipe_cli ,
struct dom_sid * domain_sid ,
struct policy_handle * domain_handle ,
struct policy_handle * builtin_handle ,
const char * user_name ,
uint32_t rid ,
uint32_t level ,
uint8_t * * buffer ,
uint32_t * num_entries )
{
NTSTATUS status ;
struct samr_UserInfo21 * info21 = NULL ;
struct sec_desc_buf * sec_desc = NULL ;
struct dom_sid sid ;
2008-07-19 01:35:33 +04:00
struct USER_INFO_0 info0 ;
struct USER_INFO_10 info10 ;
struct USER_INFO_20 info20 ;
struct USER_INFO_23 info23 ;
2008-04-09 15:47:51 +04:00
switch ( level ) {
case 0 :
2008-07-01 22:19:10 +04:00
case 1 :
case 2 :
case 3 :
case 10 :
case 11 :
case 20 :
case 23 :
break ;
default :
return NT_STATUS_INVALID_LEVEL ;
}
if ( level = = 0 ) {
2008-07-19 01:35:33 +04:00
info0 . usri0_name = talloc_strdup ( mem_ctx , user_name ) ;
NT_STATUS_HAVE_NO_MEMORY ( info0 . usri0_name ) ;
2008-07-01 22:19:10 +04:00
2008-07-19 01:35:33 +04:00
ADD_TO_ARRAY ( mem_ctx , struct USER_INFO_0 , info0 ,
2008-07-01 22:19:10 +04:00
( struct USER_INFO_0 * * ) buffer , num_entries ) ;
return NT_STATUS_OK ;
}
status = libnetapi_samr_lookup_user ( mem_ctx , pipe_cli ,
domain_handle ,
builtin_handle ,
user_name ,
rid ,
level ,
& info21 ,
& sec_desc ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
switch ( level ) {
case 10 :
2008-07-19 01:35:33 +04:00
info10 . usri10_name = talloc_strdup ( mem_ctx , user_name ) ;
NT_STATUS_HAVE_NO_MEMORY ( info10 . usri10_name ) ;
2008-07-01 22:19:10 +04:00
2008-07-19 01:35:33 +04:00
info10 . usri10_comment = talloc_strdup ( mem_ctx ,
2008-07-01 22:19:10 +04:00
info21 - > description . string ) ;
2008-07-19 01:35:33 +04:00
info10 . usri10_full_name = talloc_strdup ( mem_ctx ,
2008-07-01 22:19:10 +04:00
info21 - > full_name . string ) ;
2008-07-19 01:35:33 +04:00
info10 . usri10_usr_comment = talloc_strdup ( mem_ctx ,
2008-07-01 22:19:10 +04:00
info21 - > comment . string ) ;
2008-07-19 01:35:33 +04:00
ADD_TO_ARRAY ( mem_ctx , struct USER_INFO_10 , info10 ,
2008-07-01 22:19:10 +04:00
( struct USER_INFO_10 * * ) buffer , num_entries ) ;
break ;
case 20 :
2008-07-19 01:35:33 +04:00
info20 . usri20_name = talloc_strdup ( mem_ctx , user_name ) ;
NT_STATUS_HAVE_NO_MEMORY ( info20 . usri20_name ) ;
2008-07-01 22:19:10 +04:00
2008-07-19 01:35:33 +04:00
info20 . usri20_comment = talloc_strdup ( mem_ctx ,
2008-07-01 22:19:10 +04:00
info21 - > description . string ) ;
2008-07-19 01:35:33 +04:00
info20 . usri20_full_name = talloc_strdup ( mem_ctx ,
info21 - > full_name . string ) ;
info20 . usri20_flags = info21 - > acct_flags ;
info20 . usri20_user_id = rid ;
2008-07-01 22:19:10 +04:00
2008-07-19 01:35:33 +04:00
ADD_TO_ARRAY ( mem_ctx , struct USER_INFO_20 , info20 ,
2008-07-01 22:19:10 +04:00
( struct USER_INFO_20 * * ) buffer , num_entries ) ;
break ;
case 23 :
2008-07-19 01:35:33 +04:00
info23 . usri23_name = talloc_strdup ( mem_ctx , user_name ) ;
NT_STATUS_HAVE_NO_MEMORY ( info23 . usri23_name ) ;
2008-07-01 22:19:10 +04:00
2008-07-19 01:35:33 +04:00
info23 . usri23_comment = talloc_strdup ( mem_ctx ,
2008-07-01 22:19:10 +04:00
info21 - > description . string ) ;
2008-07-19 01:35:33 +04:00
info23 . usri23_full_name = talloc_strdup ( mem_ctx ,
info21 - > full_name . string ) ;
info23 . usri23_flags = info21 - > acct_flags ;
2008-07-01 22:19:10 +04:00
if ( ! sid_compose ( & sid , domain_sid , rid ) ) {
return NT_STATUS_NO_MEMORY ;
2008-04-09 15:47:51 +04:00
}
2008-07-19 01:35:33 +04:00
info23 . usri23_user_sid =
2008-07-01 22:19:10 +04:00
( struct domsid * ) sid_dup_talloc ( mem_ctx , & sid ) ;
2008-07-19 01:35:33 +04:00
ADD_TO_ARRAY ( mem_ctx , struct USER_INFO_23 , info23 ,
2008-07-01 22:19:10 +04:00
( struct USER_INFO_23 * * ) buffer , num_entries ) ;
2008-04-09 15:47:51 +04:00
break ;
}
2008-07-01 22:19:10 +04:00
done :
return status ;
2008-04-09 15:47:51 +04:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetUserEnum_r ( struct libnetapi_ctx * ctx ,
struct NetUserEnum * r )
{
struct cli_state * cli = NULL ;
struct rpc_pipe_client * pipe_cli = NULL ;
struct policy_handle connect_handle ;
struct dom_sid2 * domain_sid = NULL ;
struct policy_handle domain_handle ;
struct samr_SamArray * sam = NULL ;
2008-06-09 13:01:59 +04:00
uint32_t filter = ACB_NORMAL ;
2008-07-01 22:19:10 +04:00
int i ;
uint32_t entries_read = 0 ;
2008-04-09 15:47:51 +04:00
2008-07-01 22:19:10 +04:00
NTSTATUS status = NT_STATUS_OK ;
2008-04-09 15:47:51 +04:00
WERROR werr ;
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
2008-07-01 22:19:10 +04:00
if ( ! r - > out . buffer ) {
return WERR_INVALID_PARAM ;
}
* r - > out . buffer = NULL ;
* r - > out . entries_read = 0 ;
2008-04-09 15:47:51 +04:00
switch ( r - > in . level ) {
case 0 :
2008-07-01 22:19:10 +04:00
case 10 :
case 20 :
case 23 :
2008-04-09 15:47:51 +04:00
break ;
case 1 :
case 2 :
case 3 :
case 11 :
default :
return WERR_NOT_SUPPORTED ;
}
2008-04-11 00:04:04 +04:00
werr = libnetapi_open_ipc_connection ( ctx , r - > in . server_name , & cli ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-04-09 15:47:51 +04:00
goto done ;
}
2008-07-20 19:59:30 +04:00
werr = libnetapi_open_pipe ( ctx , cli , & ndr_table_samr . syntax_id ,
& pipe_cli ) ;
2008-04-11 00:44:00 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-04-09 15:47:51 +04:00
goto done ;
}
2008-06-03 01:55:45 +04:00
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
SAMR_ACCESS_OPEN_DOMAIN ,
SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 |
SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS |
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-04-09 15:47:51 +04:00
goto done ;
}
2008-06-09 13:01:59 +04:00
switch ( r - > in . filter ) {
case FILTER_NORMAL_ACCOUNT :
filter = ACB_NORMAL ;
break ;
case FILTER_TEMP_DUPLICATE_ACCOUNT :
filter = ACB_TEMPDUP ;
break ;
case FILTER_INTERDOMAIN_TRUST_ACCOUNT :
filter = ACB_DOMTRUST ;
break ;
case FILTER_WORKSTATION_TRUST_ACCOUNT :
filter = ACB_WSTRUST ;
break ;
case FILTER_SERVER_TRUST_ACCOUNT :
filter = ACB_SVRTRUST ;
break ;
default :
break ;
}
2008-04-09 15:47:51 +04:00
status = rpccli_samr_EnumDomainUsers ( pipe_cli ,
ctx ,
& domain_handle ,
r - > in . resume_handle ,
2008-06-09 13:01:59 +04:00
filter ,
2008-04-09 15:47:51 +04:00
& sam ,
r - > in . prefmaxlen ,
2008-07-01 22:19:10 +04:00
& entries_read ) ;
werr = ntstatus_to_werror ( status ) ;
if ( NT_STATUS_IS_ERR ( status ) ) {
2008-04-09 15:47:51 +04:00
goto done ;
}
2008-07-01 22:19:10 +04:00
for ( i = 0 ; i < sam - > count ; i + + ) {
status = libnetapi_samr_lookup_user_map_USER_INFO ( ctx , pipe_cli ,
domain_sid ,
& domain_handle ,
NULL , /*&builtin_handle, */
sam - > entries [ i ] . name . string ,
sam - > entries [ i ] . idx ,
r - > in . level ,
r - > out . buffer ,
r - > out . entries_read ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
}
2008-04-09 15:47:51 +04:00
done :
2008-04-11 00:04:04 +04:00
if ( ! cli ) {
return werr ;
}
2008-07-18 00:44:24 +04:00
/* if last query */
if ( NT_STATUS_IS_OK ( status ) | |
NT_STATUS_IS_ERR ( status ) ) {
if ( ctx - > disable_policy_handle_cache ) {
libnetapi_samr_close_domain_handle ( ctx , & domain_handle ) ;
libnetapi_samr_close_connect_handle ( ctx , & connect_handle ) ;
}
2008-04-09 15:47:51 +04:00
}
return werr ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetUserEnum_l ( struct libnetapi_ctx * ctx ,
struct NetUserEnum * r )
{
2008-08-12 17:25:06 +04:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetUserEnum ) ;
2008-04-09 15:47:51 +04:00
}
2008-04-13 21:04:18 +04:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-13 21:12:31 +04:00
static WERROR convert_samr_dispinfo_to_NET_DISPLAY_USER ( TALLOC_CTX * mem_ctx ,
struct samr_DispInfoGeneral * info ,
uint32_t * entries_read ,
void * * buffer )
{
struct NET_DISPLAY_USER * user = NULL ;
int i ;
user = TALLOC_ZERO_ARRAY ( mem_ctx ,
struct NET_DISPLAY_USER ,
info - > count ) ;
W_ERROR_HAVE_NO_MEMORY ( user ) ;
for ( i = 0 ; i < info - > count ; i + + ) {
user [ i ] . usri1_name = talloc_strdup ( mem_ctx ,
info - > entries [ i ] . account_name . string ) ;
user [ i ] . usri1_comment = talloc_strdup ( mem_ctx ,
info - > entries [ i ] . description . string ) ;
user [ i ] . usri1_flags =
info - > entries [ i ] . acct_flags ;
user [ i ] . usri1_full_name = talloc_strdup ( mem_ctx ,
info - > entries [ i ] . full_name . string ) ;
user [ i ] . usri1_user_id =
info - > entries [ i ] . rid ;
user [ i ] . usri1_next_index =
info - > entries [ i ] . idx ;
if ( ! user [ i ] . usri1_name ) {
return WERR_NOMEM ;
}
}
* buffer = talloc_memdup ( mem_ctx , user ,
sizeof ( struct NET_DISPLAY_USER ) * info - > count ) ;
W_ERROR_HAVE_NO_MEMORY ( * buffer ) ;
* entries_read = info - > count ;
return WERR_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static WERROR convert_samr_dispinfo_to_NET_DISPLAY_MACHINE ( TALLOC_CTX * mem_ctx ,
struct samr_DispInfoFull * info ,
uint32_t * entries_read ,
void * * buffer )
{
struct NET_DISPLAY_MACHINE * machine = NULL ;
int i ;
machine = TALLOC_ZERO_ARRAY ( mem_ctx ,
struct NET_DISPLAY_MACHINE ,
info - > count ) ;
W_ERROR_HAVE_NO_MEMORY ( machine ) ;
for ( i = 0 ; i < info - > count ; i + + ) {
machine [ i ] . usri2_name = talloc_strdup ( mem_ctx ,
info - > entries [ i ] . account_name . string ) ;
machine [ i ] . usri2_comment = talloc_strdup ( mem_ctx ,
info - > entries [ i ] . description . string ) ;
machine [ i ] . usri2_flags =
info - > entries [ i ] . acct_flags ;
machine [ i ] . usri2_user_id =
info - > entries [ i ] . rid ;
machine [ i ] . usri2_next_index =
info - > entries [ i ] . idx ;
if ( ! machine [ i ] . usri2_name ) {
return WERR_NOMEM ;
}
}
* buffer = talloc_memdup ( mem_ctx , machine ,
sizeof ( struct NET_DISPLAY_MACHINE ) * info - > count ) ;
W_ERROR_HAVE_NO_MEMORY ( * buffer ) ;
* entries_read = info - > count ;
return WERR_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static WERROR convert_samr_dispinfo_to_NET_DISPLAY_GROUP ( TALLOC_CTX * mem_ctx ,
struct samr_DispInfoFullGroups * info ,
uint32_t * entries_read ,
void * * buffer )
{
struct NET_DISPLAY_GROUP * group = NULL ;
int i ;
group = TALLOC_ZERO_ARRAY ( mem_ctx ,
struct NET_DISPLAY_GROUP ,
info - > count ) ;
W_ERROR_HAVE_NO_MEMORY ( group ) ;
for ( i = 0 ; i < info - > count ; i + + ) {
group [ i ] . grpi3_name = talloc_strdup ( mem_ctx ,
info - > entries [ i ] . account_name . string ) ;
group [ i ] . grpi3_comment = talloc_strdup ( mem_ctx ,
info - > entries [ i ] . description . string ) ;
group [ i ] . grpi3_group_id =
info - > entries [ i ] . rid ;
group [ i ] . grpi3_attributes =
info - > entries [ i ] . acct_flags ;
group [ i ] . grpi3_next_index =
info - > entries [ i ] . idx ;
if ( ! group [ i ] . grpi3_name ) {
return WERR_NOMEM ;
}
}
* buffer = talloc_memdup ( mem_ctx , group ,
sizeof ( struct NET_DISPLAY_GROUP ) * info - > count ) ;
W_ERROR_HAVE_NO_MEMORY ( * buffer ) ;
* entries_read = info - > count ;
return WERR_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-20 16:07:38 +04:00
static WERROR convert_samr_dispinfo_to_NET_DISPLAY ( TALLOC_CTX * mem_ctx ,
union samr_DispInfo * info ,
uint32_t level ,
uint32_t * entries_read ,
void * * buffer )
2008-04-13 21:12:31 +04:00
{
switch ( level ) {
case 1 :
return convert_samr_dispinfo_to_NET_DISPLAY_USER ( mem_ctx ,
& info - > info1 ,
entries_read ,
buffer ) ;
case 2 :
return convert_samr_dispinfo_to_NET_DISPLAY_MACHINE ( mem_ctx ,
& info - > info2 ,
entries_read ,
buffer ) ;
case 3 :
return convert_samr_dispinfo_to_NET_DISPLAY_GROUP ( mem_ctx ,
& info - > info3 ,
entries_read ,
buffer ) ;
default :
return WERR_UNKNOWN_LEVEL ;
}
return WERR_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-13 21:04:18 +04:00
WERROR NetQueryDisplayInformation_r ( struct libnetapi_ctx * ctx ,
struct NetQueryDisplayInformation * r )
{
2008-04-13 21:12:31 +04:00
struct cli_state * cli = NULL ;
struct rpc_pipe_client * pipe_cli = NULL ;
struct policy_handle connect_handle ;
struct dom_sid2 * domain_sid = NULL ;
struct policy_handle domain_handle ;
union samr_DispInfo info ;
uint32_t total_size = 0 ;
uint32_t returned_size = 0 ;
2008-07-18 00:44:24 +04:00
NTSTATUS status = NT_STATUS_OK ;
2008-04-13 21:12:31 +04:00
WERROR werr ;
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
switch ( r - > in . level ) {
case 1 :
case 2 :
case 3 :
break ;
default :
return WERR_UNKNOWN_LEVEL ;
}
werr = libnetapi_open_ipc_connection ( ctx , r - > in . server_name , & cli ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2008-07-20 19:59:30 +04:00
werr = libnetapi_open_pipe ( ctx , cli , & ndr_table_samr . syntax_id ,
& pipe_cli ) ;
2008-04-13 21:12:31 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2008-06-03 01:55:45 +04:00
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
SAMR_ACCESS_OPEN_DOMAIN ,
SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 |
SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS |
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-04-13 21:12:31 +04:00
goto done ;
}
status = rpccli_samr_QueryDisplayInfo2 ( pipe_cli ,
ctx ,
& domain_handle ,
r - > in . level ,
r - > in . idx ,
r - > in . entries_requested ,
r - > in . prefmaxlen ,
& total_size ,
& returned_size ,
& info ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
werr = convert_samr_dispinfo_to_NET_DISPLAY ( ctx , & info ,
r - > in . level ,
r - > out . entries_read ,
r - > out . buffer ) ;
done :
if ( ! cli ) {
return werr ;
}
2008-07-18 00:44:24 +04:00
/* if last query */
if ( NT_STATUS_IS_OK ( status ) | |
NT_STATUS_IS_ERR ( status ) ) {
if ( ctx - > disable_policy_handle_cache ) {
libnetapi_samr_close_domain_handle ( ctx , & domain_handle ) ;
libnetapi_samr_close_connect_handle ( ctx , & connect_handle ) ;
}
2008-04-13 21:12:31 +04:00
}
return werr ;
2008-04-13 21:04:18 +04:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetQueryDisplayInformation_l ( struct libnetapi_ctx * ctx ,
struct NetQueryDisplayInformation * r )
{
2008-08-12 17:25:06 +04:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetQueryDisplayInformation ) ;
2008-04-13 21:04:18 +04:00
}
2008-06-25 02:32:02 +04:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetUserChangePassword_r ( struct libnetapi_ctx * ctx ,
struct NetUserChangePassword * r )
{
return WERR_NOT_SUPPORTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetUserChangePassword_l ( struct libnetapi_ctx * ctx ,
struct NetUserChangePassword * r )
{
return WERR_NOT_SUPPORTED ;
}
2008-07-16 12:47:38 +04:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetUserGetInfo_r ( struct libnetapi_ctx * ctx ,
struct NetUserGetInfo * r )
{
2008-07-18 00:45:09 +04:00
struct cli_state * cli = NULL ;
struct rpc_pipe_client * pipe_cli = NULL ;
NTSTATUS status ;
WERROR werr ;
struct policy_handle connect_handle , domain_handle , builtin_handle , user_handle ;
struct lsa_String lsa_account_name ;
struct dom_sid2 * domain_sid = NULL ;
struct samr_Ids user_rids , name_types ;
uint32_t num_entries = 0 ;
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
ZERO_STRUCT ( builtin_handle ) ;
ZERO_STRUCT ( user_handle ) ;
if ( ! r - > out . buffer ) {
return WERR_INVALID_PARAM ;
}
switch ( r - > in . level ) {
case 0 :
/* case 1: */
case 10 :
case 20 :
case 23 :
break ;
default :
werr = WERR_NOT_SUPPORTED ;
goto done ;
}
werr = libnetapi_open_ipc_connection ( ctx , r - > in . server_name , & cli ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2008-07-20 19:59:30 +04:00
werr = libnetapi_open_pipe ( ctx , cli , & ndr_table_samr . syntax_id ,
& pipe_cli ) ;
2008-07-18 00:45:09 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
SAMR_ACCESS_OPEN_DOMAIN ,
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
werr = libnetapi_samr_open_builtin_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
SAMR_ACCESS_OPEN_DOMAIN ,
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT |
SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS ,
& connect_handle ,
& builtin_handle ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
init_lsa_String ( & lsa_account_name , r - > in . user_name ) ;
status = rpccli_samr_LookupNames ( pipe_cli , ctx ,
& domain_handle ,
1 ,
& lsa_account_name ,
& user_rids ,
& name_types ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
status = libnetapi_samr_lookup_user_map_USER_INFO ( ctx , pipe_cli ,
domain_sid ,
& domain_handle ,
& builtin_handle ,
r - > in . user_name ,
user_rids . ids [ 0 ] ,
r - > in . level ,
r - > out . buffer ,
& num_entries ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
done :
if ( ! cli ) {
return werr ;
}
if ( is_valid_policy_hnd ( & user_handle ) ) {
rpccli_samr_Close ( pipe_cli , ctx , & user_handle ) ;
}
2008-07-18 00:44:24 +04:00
if ( ctx - > disable_policy_handle_cache ) {
libnetapi_samr_close_domain_handle ( ctx , & domain_handle ) ;
libnetapi_samr_close_connect_handle ( ctx , & connect_handle ) ;
}
2008-07-18 00:45:09 +04:00
return werr ;
2008-07-16 12:47:38 +04:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetUserGetInfo_l ( struct libnetapi_ctx * ctx ,
struct NetUserGetInfo * r )
{
2008-08-12 17:25:06 +04:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetUserGetInfo ) ;
2008-07-16 12:47:38 +04:00
}
2008-07-17 03:00:33 +04:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetUserSetInfo_r ( struct libnetapi_ctx * ctx ,
struct NetUserSetInfo * r )
{
2008-07-18 22:12:45 +04:00
struct cli_state * cli = NULL ;
struct rpc_pipe_client * pipe_cli = NULL ;
NTSTATUS status ;
WERROR werr ;
struct policy_handle connect_handle , domain_handle , builtin_handle , user_handle ;
struct lsa_String lsa_account_name ;
struct dom_sid2 * domain_sid = NULL ;
struct samr_Ids user_rids , name_types ;
union samr_UserInfo user_info ;
struct USER_INFO_X uX ;
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
ZERO_STRUCT ( builtin_handle ) ;
ZERO_STRUCT ( user_handle ) ;
if ( ! r - > in . buffer ) {
return WERR_INVALID_PARAM ;
}
switch ( r - > in . level ) {
case 0 :
case 1007 :
break ;
default :
werr = WERR_NOT_SUPPORTED ;
goto done ;
}
werr = libnetapi_open_ipc_connection ( ctx , r - > in . server_name , & cli ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
werr = libnetapi_open_pipe ( ctx , cli , & ndr_table_samr . syntax_id ,
& pipe_cli ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
SAMR_ACCESS_OPEN_DOMAIN ,
SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 |
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
werr = libnetapi_samr_open_builtin_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
SAMR_ACCESS_OPEN_DOMAIN ,
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT |
SAMR_DOMAIN_ACCESS_LOOKUP_ALIAS ,
& connect_handle ,
& builtin_handle ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
init_lsa_String ( & lsa_account_name , r - > in . user_name ) ;
status = rpccli_samr_LookupNames ( pipe_cli , ctx ,
& domain_handle ,
1 ,
& lsa_account_name ,
& user_rids ,
& name_types ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
status = rpccli_samr_OpenUser ( pipe_cli , ctx ,
& domain_handle ,
SAMR_USER_ACCESS_SET_ATTRIBUTES ,
user_rids . ids [ 0 ] ,
& user_handle ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
status = construct_USER_INFO_X ( r - > in . level , r - > in . buffer , & uX ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
convert_USER_INFO_X_to_samr_user_info21 ( & uX , & user_info . info21 ) ;
status = rpccli_samr_SetUserInfo ( pipe_cli , ctx ,
& user_handle ,
21 ,
& user_info ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
werr = WERR_OK ;
done :
if ( ! cli ) {
return werr ;
}
if ( is_valid_policy_hnd ( & user_handle ) ) {
rpccli_samr_Close ( pipe_cli , ctx , & user_handle ) ;
}
if ( ctx - > disable_policy_handle_cache ) {
libnetapi_samr_close_domain_handle ( ctx , & domain_handle ) ;
libnetapi_samr_close_builtin_handle ( ctx , & builtin_handle ) ;
libnetapi_samr_close_connect_handle ( ctx , & connect_handle ) ;
}
return werr ;
2008-07-17 03:00:33 +04:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetUserSetInfo_l ( struct libnetapi_ctx * ctx ,
struct NetUserSetInfo * r )
{
2008-08-12 17:25:06 +04:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetUserSetInfo ) ;
2008-07-17 03:00:33 +04:00
}
2008-07-31 18:43:27 +04:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-07-31 21:26:29 +04:00
static NTSTATUS query_USER_MODALS_INFO_rpc ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * pipe_cli ,
struct policy_handle * domain_handle ,
struct samr_DomInfo1 * info1 ,
struct samr_DomInfo3 * info3 ,
struct samr_DomInfo5 * info5 ,
struct samr_DomInfo6 * info6 ,
struct samr_DomInfo7 * info7 ,
struct samr_DomInfo12 * info12 )
{
NTSTATUS status ;
union samr_DomainInfo * dom_info = NULL ;
if ( info1 ) {
status = rpccli_samr_QueryDomainInfo ( pipe_cli , mem_ctx ,
domain_handle ,
1 ,
& dom_info ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
* info1 = dom_info - > info1 ;
}
if ( info3 ) {
status = rpccli_samr_QueryDomainInfo ( pipe_cli , mem_ctx ,
domain_handle ,
3 ,
& dom_info ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
* info3 = dom_info - > info3 ;
}
if ( info5 ) {
status = rpccli_samr_QueryDomainInfo ( pipe_cli , mem_ctx ,
domain_handle ,
5 ,
& dom_info ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
* info5 = dom_info - > info5 ;
}
if ( info6 ) {
status = rpccli_samr_QueryDomainInfo ( pipe_cli , mem_ctx ,
domain_handle ,
6 ,
& dom_info ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
* info6 = dom_info - > info6 ;
}
if ( info7 ) {
status = rpccli_samr_QueryDomainInfo ( pipe_cli , mem_ctx ,
domain_handle ,
7 ,
& dom_info ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
* info7 = dom_info - > info7 ;
}
if ( info12 ) {
status = rpccli_samr_QueryDomainInfo2 ( pipe_cli , mem_ctx ,
domain_handle ,
12 ,
& dom_info ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
* info12 = dom_info - > info12 ;
}
return NT_STATUS_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS query_USER_MODALS_INFO_0 ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * pipe_cli ,
struct policy_handle * domain_handle ,
struct USER_MODALS_INFO_0 * info0 )
{
NTSTATUS status ;
struct samr_DomInfo1 dom_info1 ;
struct samr_DomInfo3 dom_info3 ;
ZERO_STRUCTP ( info0 ) ;
status = query_USER_MODALS_INFO_rpc ( mem_ctx ,
pipe_cli ,
domain_handle ,
& dom_info1 ,
& dom_info3 ,
NULL ,
NULL ,
NULL ,
NULL ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
info0 - > usrmod0_min_passwd_len =
dom_info1 . min_password_length ;
info0 - > usrmod0_max_passwd_age =
nt_time_to_unix_abs ( ( NTTIME * ) & dom_info1 . max_password_age ) ;
info0 - > usrmod0_min_passwd_age =
nt_time_to_unix_abs ( ( NTTIME * ) & dom_info1 . min_password_age ) ;
info0 - > usrmod0_password_hist_len =
dom_info1 . password_history_length ;
info0 - > usrmod0_force_logoff =
nt_time_to_unix_abs ( & dom_info3 . force_logoff_time ) ;
return NT_STATUS_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS query_USER_MODALS_INFO_1 ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * pipe_cli ,
struct policy_handle * domain_handle ,
struct USER_MODALS_INFO_1 * info1 )
{
NTSTATUS status ;
struct samr_DomInfo6 dom_info6 ;
struct samr_DomInfo7 dom_info7 ;
status = query_USER_MODALS_INFO_rpc ( mem_ctx ,
pipe_cli ,
domain_handle ,
NULL ,
NULL ,
NULL ,
& dom_info6 ,
& dom_info7 ,
NULL ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
info1 - > usrmod1_primary =
talloc_strdup ( mem_ctx , dom_info6 . primary . string ) ;
info1 - > usrmod1_role = dom_info7 . role ;
return NT_STATUS_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS query_USER_MODALS_INFO_2 ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * pipe_cli ,
struct policy_handle * domain_handle ,
struct dom_sid * domain_sid ,
struct USER_MODALS_INFO_2 * info2 )
{
NTSTATUS status ;
struct samr_DomInfo5 dom_info5 ;
status = query_USER_MODALS_INFO_rpc ( mem_ctx ,
pipe_cli ,
domain_handle ,
NULL ,
NULL ,
& dom_info5 ,
NULL ,
NULL ,
NULL ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
info2 - > usrmod2_domain_name =
talloc_strdup ( mem_ctx , dom_info5 . domain_name . string ) ;
info2 - > usrmod2_domain_id =
( struct domsid * ) sid_dup_talloc ( mem_ctx , domain_sid ) ;
NT_STATUS_HAVE_NO_MEMORY ( info2 - > usrmod2_domain_name ) ;
NT_STATUS_HAVE_NO_MEMORY ( info2 - > usrmod2_domain_id ) ;
return NT_STATUS_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS query_USER_MODALS_INFO_3 ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * pipe_cli ,
struct policy_handle * domain_handle ,
struct USER_MODALS_INFO_3 * info3 )
{
NTSTATUS status ;
struct samr_DomInfo12 dom_info12 ;
status = query_USER_MODALS_INFO_rpc ( mem_ctx ,
pipe_cli ,
domain_handle ,
NULL ,
NULL ,
NULL ,
NULL ,
NULL ,
& dom_info12 ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
info3 - > usrmod3_lockout_duration =
nt_time_to_unix_abs ( & dom_info12 . lockout_duration ) ;
info3 - > usrmod3_lockout_observation_window =
nt_time_to_unix_abs ( & dom_info12 . lockout_window ) ;
info3 - > usrmod3_lockout_threshold =
dom_info12 . lockout_threshold ;
return NT_STATUS_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS query_USER_MODALS_INFO_to_buffer ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * pipe_cli ,
uint32_t level ,
struct policy_handle * domain_handle ,
struct dom_sid * domain_sid ,
uint8_t * * buffer )
{
NTSTATUS status ;
struct USER_MODALS_INFO_0 info0 ;
struct USER_MODALS_INFO_1 info1 ;
struct USER_MODALS_INFO_2 info2 ;
struct USER_MODALS_INFO_3 info3 ;
if ( ! buffer ) {
return ERROR_INSUFFICIENT_BUFFER ;
}
switch ( level ) {
case 0 :
status = query_USER_MODALS_INFO_0 ( mem_ctx ,
pipe_cli ,
domain_handle ,
& info0 ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
* buffer = ( uint8_t * ) talloc_memdup ( mem_ctx , & info0 ,
sizeof ( info0 ) ) ;
break ;
case 1 :
status = query_USER_MODALS_INFO_1 ( mem_ctx ,
pipe_cli ,
domain_handle ,
& info1 ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
* buffer = ( uint8_t * ) talloc_memdup ( mem_ctx , & info1 ,
sizeof ( info1 ) ) ;
break ;
case 2 :
status = query_USER_MODALS_INFO_2 ( mem_ctx ,
pipe_cli ,
domain_handle ,
domain_sid ,
& info2 ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
* buffer = ( uint8_t * ) talloc_memdup ( mem_ctx , & info2 ,
sizeof ( info2 ) ) ;
break ;
case 3 :
status = query_USER_MODALS_INFO_3 ( mem_ctx ,
pipe_cli ,
domain_handle ,
& info3 ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
* buffer = ( uint8_t * ) talloc_memdup ( mem_ctx , & info3 ,
sizeof ( info3 ) ) ;
break ;
default :
break ;
}
NT_STATUS_HAVE_NO_MEMORY ( * buffer ) ;
return NT_STATUS_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-07-31 18:43:27 +04:00
WERROR NetUserModalsGet_r ( struct libnetapi_ctx * ctx ,
struct NetUserModalsGet * r )
{
2008-07-31 21:26:29 +04:00
struct cli_state * cli = NULL ;
struct rpc_pipe_client * pipe_cli = NULL ;
NTSTATUS status ;
WERROR werr ;
struct policy_handle connect_handle , domain_handle ;
struct dom_sid2 * domain_sid = NULL ;
uint32_t access_mask = SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ;
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
if ( ! r - > out . buffer ) {
return WERR_INVALID_PARAM ;
}
switch ( r - > in . level ) {
case 0 :
access_mask | = SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 |
SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 ;
break ;
case 1 :
case 2 :
access_mask | = SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 ;
break ;
case 3 :
access_mask | = SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 ;
break ;
default :
werr = WERR_UNKNOWN_LEVEL ;
goto done ;
}
werr = libnetapi_open_ipc_connection ( ctx , r - > in . server_name , & cli ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
werr = libnetapi_open_pipe ( ctx , cli , & ndr_table_samr . syntax_id ,
& pipe_cli ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
SAMR_ACCESS_OPEN_DOMAIN ,
access_mask ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
/* 0: 1 + 3 */
/* 1: 6 + 7 */
/* 2: 5 */
/* 3: 12 (DomainInfo2) */
status = query_USER_MODALS_INFO_to_buffer ( ctx ,
pipe_cli ,
r - > in . level ,
& domain_handle ,
domain_sid ,
r - > out . buffer ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
done :
if ( ! cli ) {
return werr ;
}
if ( ctx - > disable_policy_handle_cache ) {
libnetapi_samr_close_domain_handle ( ctx , & domain_handle ) ;
libnetapi_samr_close_connect_handle ( ctx , & connect_handle ) ;
}
return werr ;
2008-07-31 18:43:27 +04:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetUserModalsGet_l ( struct libnetapi_ctx * ctx ,
struct NetUserModalsGet * r )
{
2008-08-12 17:25:06 +04:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetUserModalsGet ) ;
2008-07-31 18:43:27 +04:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-07-31 23:08:31 +04:00
static NTSTATUS set_USER_MODALS_INFO_rpc ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * pipe_cli ,
struct policy_handle * domain_handle ,
struct samr_DomInfo1 * info1 ,
struct samr_DomInfo3 * info3 ,
struct samr_DomInfo12 * info12 )
{
NTSTATUS status ;
union samr_DomainInfo dom_info ;
if ( info1 ) {
ZERO_STRUCT ( dom_info ) ;
dom_info . info1 = * info1 ;
status = rpccli_samr_SetDomainInfo ( pipe_cli , mem_ctx ,
domain_handle ,
1 ,
& dom_info ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
}
if ( info3 ) {
ZERO_STRUCT ( dom_info ) ;
dom_info . info3 = * info3 ;
status = rpccli_samr_SetDomainInfo ( pipe_cli , mem_ctx ,
domain_handle ,
3 ,
& dom_info ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
}
if ( info12 ) {
ZERO_STRUCT ( dom_info ) ;
dom_info . info12 = * info12 ;
status = rpccli_samr_SetDomainInfo ( pipe_cli , mem_ctx ,
domain_handle ,
12 ,
& dom_info ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
}
return NT_STATUS_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS set_USER_MODALS_INFO_0_buffer ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * pipe_cli ,
struct policy_handle * domain_handle ,
struct USER_MODALS_INFO_0 * info0 )
{
NTSTATUS status ;
struct samr_DomInfo1 dom_info_1 ;
struct samr_DomInfo3 dom_info_3 ;
status = query_USER_MODALS_INFO_rpc ( mem_ctx ,
pipe_cli ,
domain_handle ,
& dom_info_1 ,
& dom_info_3 ,
NULL ,
NULL ,
NULL ,
NULL ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
dom_info_1 . min_password_length =
info0 - > usrmod0_min_passwd_len ;
dom_info_1 . password_history_length =
info0 - > usrmod0_password_hist_len ;
unix_to_nt_time_abs ( ( NTTIME * ) & dom_info_1 . max_password_age ,
info0 - > usrmod0_max_passwd_age ) ;
unix_to_nt_time_abs ( ( NTTIME * ) & dom_info_1 . min_password_age ,
info0 - > usrmod0_min_passwd_age ) ;
unix_to_nt_time_abs ( & dom_info_3 . force_logoff_time ,
info0 - > usrmod0_force_logoff ) ;
return set_USER_MODALS_INFO_rpc ( mem_ctx ,
pipe_cli ,
domain_handle ,
& dom_info_1 ,
& dom_info_3 ,
NULL ) ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS set_USER_MODALS_INFO_3_buffer ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * pipe_cli ,
struct policy_handle * domain_handle ,
struct USER_MODALS_INFO_3 * info3 )
{
NTSTATUS status ;
struct samr_DomInfo12 dom_info_12 ;
status = query_USER_MODALS_INFO_rpc ( mem_ctx ,
pipe_cli ,
domain_handle ,
NULL ,
NULL ,
NULL ,
NULL ,
NULL ,
& dom_info_12 ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
unix_to_nt_time_abs ( ( NTTIME * ) & dom_info_12 . lockout_duration ,
info3 - > usrmod3_lockout_duration ) ;
unix_to_nt_time_abs ( ( NTTIME * ) & dom_info_12 . lockout_window ,
info3 - > usrmod3_lockout_observation_window ) ;
dom_info_12 . lockout_threshold = info3 - > usrmod3_lockout_threshold ;
return set_USER_MODALS_INFO_rpc ( mem_ctx ,
pipe_cli ,
domain_handle ,
NULL ,
NULL ,
& dom_info_12 ) ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS set_USER_MODALS_INFO_1001_buffer ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * pipe_cli ,
struct policy_handle * domain_handle ,
struct USER_MODALS_INFO_1001 * info1001 )
{
NTSTATUS status ;
struct samr_DomInfo1 dom_info_1 ;
status = query_USER_MODALS_INFO_rpc ( mem_ctx ,
pipe_cli ,
domain_handle ,
& dom_info_1 ,
NULL ,
NULL ,
NULL ,
NULL ,
NULL ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
dom_info_1 . min_password_length =
info1001 - > usrmod1001_min_passwd_len ;
return set_USER_MODALS_INFO_rpc ( mem_ctx ,
pipe_cli ,
domain_handle ,
& dom_info_1 ,
NULL ,
NULL ) ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS set_USER_MODALS_INFO_1002_buffer ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * pipe_cli ,
struct policy_handle * domain_handle ,
struct USER_MODALS_INFO_1002 * info1002 )
{
NTSTATUS status ;
struct samr_DomInfo1 dom_info_1 ;
status = query_USER_MODALS_INFO_rpc ( mem_ctx ,
pipe_cli ,
domain_handle ,
& dom_info_1 ,
NULL ,
NULL ,
NULL ,
NULL ,
NULL ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
unix_to_nt_time_abs ( ( NTTIME * ) & dom_info_1 . max_password_age ,
info1002 - > usrmod1002_max_passwd_age ) ;
return set_USER_MODALS_INFO_rpc ( mem_ctx ,
pipe_cli ,
domain_handle ,
& dom_info_1 ,
NULL ,
NULL ) ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS set_USER_MODALS_INFO_1003_buffer ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * pipe_cli ,
struct policy_handle * domain_handle ,
struct USER_MODALS_INFO_1003 * info1003 )
{
NTSTATUS status ;
struct samr_DomInfo1 dom_info_1 ;
status = query_USER_MODALS_INFO_rpc ( mem_ctx ,
pipe_cli ,
domain_handle ,
& dom_info_1 ,
NULL ,
NULL ,
NULL ,
NULL ,
NULL ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
unix_to_nt_time_abs ( ( NTTIME * ) & dom_info_1 . min_password_age ,
info1003 - > usrmod1003_min_passwd_age ) ;
return set_USER_MODALS_INFO_rpc ( mem_ctx ,
pipe_cli ,
domain_handle ,
& dom_info_1 ,
NULL ,
NULL ) ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS set_USER_MODALS_INFO_1004_buffer ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * pipe_cli ,
struct policy_handle * domain_handle ,
struct USER_MODALS_INFO_1004 * info1004 )
{
NTSTATUS status ;
struct samr_DomInfo3 dom_info_3 ;
status = query_USER_MODALS_INFO_rpc ( mem_ctx ,
pipe_cli ,
domain_handle ,
NULL ,
& dom_info_3 ,
NULL ,
NULL ,
NULL ,
NULL ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
unix_to_nt_time_abs ( & dom_info_3 . force_logoff_time ,
info1004 - > usrmod1004_force_logoff ) ;
return set_USER_MODALS_INFO_rpc ( mem_ctx ,
pipe_cli ,
domain_handle ,
NULL ,
& dom_info_3 ,
NULL ) ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS set_USER_MODALS_INFO_1005_buffer ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * pipe_cli ,
struct policy_handle * domain_handle ,
struct USER_MODALS_INFO_1005 * info1005 )
{
NTSTATUS status ;
struct samr_DomInfo1 dom_info_1 ;
status = query_USER_MODALS_INFO_rpc ( mem_ctx ,
pipe_cli ,
domain_handle ,
& dom_info_1 ,
NULL ,
NULL ,
NULL ,
NULL ,
NULL ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
dom_info_1 . password_history_length =
info1005 - > usrmod1005_password_hist_len ;
return set_USER_MODALS_INFO_rpc ( mem_ctx ,
pipe_cli ,
domain_handle ,
& dom_info_1 ,
NULL ,
NULL ) ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS set_USER_MODALS_INFO_buffer ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * pipe_cli ,
uint32_t level ,
struct policy_handle * domain_handle ,
struct dom_sid * domain_sid ,
uint8_t * buffer )
{
struct USER_MODALS_INFO_0 * info0 ;
struct USER_MODALS_INFO_3 * info3 ;
struct USER_MODALS_INFO_1001 * info1001 ;
struct USER_MODALS_INFO_1002 * info1002 ;
struct USER_MODALS_INFO_1003 * info1003 ;
struct USER_MODALS_INFO_1004 * info1004 ;
struct USER_MODALS_INFO_1005 * info1005 ;
if ( ! buffer ) {
return ERROR_INSUFFICIENT_BUFFER ;
}
switch ( level ) {
case 0 :
info0 = ( struct USER_MODALS_INFO_0 * ) buffer ;
return set_USER_MODALS_INFO_0_buffer ( mem_ctx ,
pipe_cli ,
domain_handle ,
info0 ) ;
case 3 :
info3 = ( struct USER_MODALS_INFO_3 * ) buffer ;
return set_USER_MODALS_INFO_3_buffer ( mem_ctx ,
pipe_cli ,
domain_handle ,
info3 ) ;
case 1001 :
info1001 = ( struct USER_MODALS_INFO_1001 * ) buffer ;
return set_USER_MODALS_INFO_1001_buffer ( mem_ctx ,
pipe_cli ,
domain_handle ,
info1001 ) ;
case 1002 :
info1002 = ( struct USER_MODALS_INFO_1002 * ) buffer ;
return set_USER_MODALS_INFO_1002_buffer ( mem_ctx ,
pipe_cli ,
domain_handle ,
info1002 ) ;
case 1003 :
info1003 = ( struct USER_MODALS_INFO_1003 * ) buffer ;
return set_USER_MODALS_INFO_1003_buffer ( mem_ctx ,
pipe_cli ,
domain_handle ,
info1003 ) ;
case 1004 :
info1004 = ( struct USER_MODALS_INFO_1004 * ) buffer ;
return set_USER_MODALS_INFO_1004_buffer ( mem_ctx ,
pipe_cli ,
domain_handle ,
info1004 ) ;
case 1005 :
info1005 = ( struct USER_MODALS_INFO_1005 * ) buffer ;
return set_USER_MODALS_INFO_1005_buffer ( mem_ctx ,
pipe_cli ,
domain_handle ,
info1005 ) ;
default :
break ;
}
return NT_STATUS_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-07-31 18:43:27 +04:00
WERROR NetUserModalsSet_r ( struct libnetapi_ctx * ctx ,
struct NetUserModalsSet * r )
{
2008-07-31 23:08:31 +04:00
struct cli_state * cli = NULL ;
struct rpc_pipe_client * pipe_cli = NULL ;
NTSTATUS status ;
WERROR werr ;
struct policy_handle connect_handle , domain_handle ;
struct dom_sid2 * domain_sid = NULL ;
uint32_t access_mask = SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ;
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
if ( ! r - > in . buffer ) {
return WERR_INVALID_PARAM ;
}
switch ( r - > in . level ) {
case 0 :
access_mask | = SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 |
SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 |
SAMR_DOMAIN_ACCESS_SET_INFO_1 |
SAMR_DOMAIN_ACCESS_SET_INFO_2 ;
break ;
case 3 :
case 1001 :
case 1002 :
case 1003 :
case 1005 :
access_mask | = SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1 |
SAMR_DOMAIN_ACCESS_SET_INFO_1 ;
break ;
case 1004 :
access_mask | = SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 |
SAMR_DOMAIN_ACCESS_SET_INFO_2 ;
break ;
case 1 :
case 2 :
case 1006 :
case 1007 :
werr = WERR_NOT_SUPPORTED ;
break ;
default :
werr = WERR_UNKNOWN_LEVEL ;
goto done ;
}
werr = libnetapi_open_ipc_connection ( ctx , r - > in . server_name , & cli ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
werr = libnetapi_open_pipe ( ctx , cli , & ndr_table_samr . syntax_id ,
& pipe_cli ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
SAMR_ACCESS_OPEN_DOMAIN ,
access_mask ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
status = set_USER_MODALS_INFO_buffer ( ctx ,
pipe_cli ,
r - > in . level ,
& domain_handle ,
domain_sid ,
r - > in . buffer ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
done :
if ( ! cli ) {
return werr ;
}
if ( ctx - > disable_policy_handle_cache ) {
libnetapi_samr_close_domain_handle ( ctx , & domain_handle ) ;
libnetapi_samr_close_connect_handle ( ctx , & connect_handle ) ;
}
return werr ;
2008-07-31 18:43:27 +04:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetUserModalsSet_l ( struct libnetapi_ctx * ctx ,
struct NetUserModalsSet * r )
{
2008-08-12 17:25:06 +04:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetUserModalsSet ) ;
2008-07-31 18:43:27 +04:00
}