2008-05-27 14:11:28 +04:00
/*
* Unix SMB / CIFS implementation .
* NetApi Group 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"
# include "lib/netapi/netapi_private.h"
# include "lib/netapi/libnetapi.h"
2011-04-13 16:32:16 +04:00
# include "rpc_client/rpc_client.h"
2011-01-14 17:49:37 +03:00
# include "../librpc/gen_ndr/ndr_samr_c.h"
2010-08-20 01:15:22 +04:00
# include "rpc_client/init_lsa.h"
2010-10-12 08:27:50 +04:00
# include "../libcli/security/security.h"
2008-05-27 14:11:28 +04:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetGroupAdd_r ( struct libnetapi_ctx * ctx ,
struct NetGroupAdd * r )
{
2008-05-28 16:48:30 +04:00
struct rpc_pipe_client * pipe_cli = NULL ;
2011-01-14 17:49:37 +03:00
NTSTATUS status , result ;
2008-05-28 16:48:30 +04:00
WERROR werr ;
2009-03-19 00:49:41 +03:00
struct policy_handle connect_handle , domain_handle , group_handle ;
2008-06-02 19:31:00 +04:00
struct lsa_String lsa_group_name ;
2008-05-28 16:48:30 +04:00
struct dom_sid2 * domain_sid = NULL ;
uint32_t rid = 0 ;
2011-01-14 17:49:37 +03:00
struct dcerpc_binding_handle * b = NULL ;
2008-06-02 19:31:00 +04:00
2008-06-03 03:37:55 +04:00
struct GROUP_INFO_0 * info0 = NULL ;
struct GROUP_INFO_1 * info1 = NULL ;
struct GROUP_INFO_2 * info2 = NULL ;
struct GROUP_INFO_3 * info3 = NULL ;
2008-05-28 16:48:30 +04:00
union samr_GroupInfo info ;
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
ZERO_STRUCT ( group_handle ) ;
2008-07-19 01:33:08 +04:00
if ( ! r - > in . buffer ) {
2008-05-28 16:48:30 +04:00
return WERR_INVALID_PARAM ;
}
switch ( r - > in . level ) {
case 0 :
2008-07-19 01:33:08 +04:00
info0 = ( struct GROUP_INFO_0 * ) r - > in . buffer ;
2008-05-28 16:48:30 +04:00
break ;
case 1 :
2008-07-19 01:33:08 +04:00
info1 = ( struct GROUP_INFO_1 * ) r - > in . buffer ;
2008-05-28 16:48:30 +04:00
break ;
case 2 :
2008-07-19 01:33:08 +04:00
info2 = ( struct GROUP_INFO_2 * ) r - > in . buffer ;
2008-05-28 16:48:30 +04:00
break ;
case 3 :
2008-07-19 01:33:08 +04:00
info3 = ( struct GROUP_INFO_3 * ) r - > in . buffer ;
2008-05-28 16:48:30 +04:00
break ;
default :
werr = WERR_UNKNOWN_LEVEL ;
goto done ;
}
2008-08-12 19:59:23 +04:00
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 18:10:13 +04:00
& ndr_table_samr ,
2008-07-20 19:59:30 +04:00
& pipe_cli ) ;
2008-05-28 16:48:30 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2011-01-14 17:49:37 +03:00
b = pipe_cli - > binding_handle ;
2008-06-03 01:55:45 +04:00
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
2009-04-16 02:40:00 +04:00
SAMR_ACCESS_LOOKUP_DOMAIN ,
2008-06-03 01:55:45 +04:00
SAMR_DOMAIN_ACCESS_CREATE_GROUP |
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-05-28 16:48:30 +04:00
goto done ;
}
switch ( r - > in . level ) {
case 0 :
init_lsa_String ( & lsa_group_name , info0 - > grpi0_name ) ;
break ;
case 1 :
init_lsa_String ( & lsa_group_name , info1 - > grpi1_name ) ;
break ;
case 2 :
init_lsa_String ( & lsa_group_name , info2 - > grpi2_name ) ;
break ;
case 3 :
init_lsa_String ( & lsa_group_name , info3 - > grpi3_name ) ;
break ;
}
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_CreateDomainGroup ( b , talloc_tos ( ) ,
2008-05-28 16:48:30 +04:00
& domain_handle ,
& lsa_group_name ,
SEC_STD_DELETE |
SAMR_GROUP_ACCESS_SET_INFO ,
& group_handle ,
2011-01-14 17:49:37 +03:00
& rid ,
& result ) ;
2008-05-28 16:48:30 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-05-28 16:48:30 +04:00
switch ( r - > in . level ) {
case 1 :
if ( info1 - > grpi1_comment ) {
init_lsa_String ( & info . description ,
info1 - > grpi1_comment ) ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_SetGroupInfo ( b , talloc_tos ( ) ,
2008-05-28 16:48:30 +04:00
& group_handle ,
GROUPINFODESCRIPTION ,
2011-01-14 17:49:37 +03:00
& info ,
& result ) ;
2008-05-28 16:48:30 +04:00
}
break ;
case 2 :
if ( info2 - > grpi2_comment ) {
init_lsa_String ( & info . description ,
info2 - > grpi2_comment ) ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_SetGroupInfo ( b , talloc_tos ( ) ,
2008-05-28 16:48:30 +04:00
& group_handle ,
GROUPINFODESCRIPTION ,
2011-01-14 17:49:37 +03:00
& info ,
& result ) ;
2008-05-28 16:48:30 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto failed ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto failed ;
}
2008-05-28 16:48:30 +04:00
}
if ( info2 - > grpi2_attributes ! = 0 ) {
info . attributes . attributes = info2 - > grpi2_attributes ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_SetGroupInfo ( b , talloc_tos ( ) ,
2008-05-28 16:48:30 +04:00
& group_handle ,
GROUPINFOATTRIBUTES ,
2011-01-14 17:49:37 +03:00
& info ,
& result ) ;
2008-05-28 16:48:30 +04:00
}
break ;
case 3 :
if ( info3 - > grpi3_comment ) {
init_lsa_String ( & info . description ,
info3 - > grpi3_comment ) ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_SetGroupInfo ( b , talloc_tos ( ) ,
2008-05-28 16:48:30 +04:00
& group_handle ,
GROUPINFODESCRIPTION ,
2011-01-14 17:49:37 +03:00
& info ,
& result ) ;
2008-05-28 16:48:30 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto failed ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto failed ;
}
2008-05-28 16:48:30 +04:00
}
if ( info3 - > grpi3_attributes ! = 0 ) {
info . attributes . attributes = info3 - > grpi3_attributes ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_SetGroupInfo ( b , talloc_tos ( ) ,
2008-05-28 16:48:30 +04:00
& group_handle ,
GROUPINFOATTRIBUTES ,
2011-01-14 17:49:37 +03:00
& info ,
& result ) ;
2008-05-28 16:48:30 +04:00
}
break ;
default :
break ;
}
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto failed ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto failed ;
}
2008-05-28 16:48:30 +04:00
werr = WERR_OK ;
goto done ;
failed :
2011-01-14 17:49:37 +03:00
dcerpc_samr_DeleteDomainGroup ( b , talloc_tos ( ) ,
& group_handle , & result ) ;
2008-05-28 16:48:30 +04:00
done :
if ( is_valid_policy_hnd ( & group_handle ) ) {
2011-01-14 17:49:37 +03:00
dcerpc_samr_Close ( b , talloc_tos ( ) , & group_handle , & result ) ;
2008-05-28 16:48:30 +04:00
}
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-05-28 16:48:30 +04:00
}
return werr ;
2008-05-27 14:11:28 +04:00
}
2008-05-28 16:48:30 +04:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-05-27 14:11:28 +04:00
WERROR NetGroupAdd_l ( struct libnetapi_ctx * ctx ,
struct NetGroupAdd * r )
{
2008-08-12 17:25:06 +04:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetGroupAdd ) ;
2008-05-27 14:11:28 +04:00
}
2008-05-29 03:43:06 +04:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-05-27 14:11:28 +04:00
WERROR NetGroupDel_r ( struct libnetapi_ctx * ctx ,
struct NetGroupDel * r )
{
2008-05-29 03:43:06 +04:00
struct rpc_pipe_client * pipe_cli = NULL ;
2011-01-14 17:49:37 +03:00
NTSTATUS status , result ;
2008-05-29 03:43:06 +04:00
WERROR werr ;
2009-03-19 00:49:41 +03:00
struct policy_handle connect_handle , domain_handle , group_handle ;
2008-06-02 19:31:00 +04:00
struct lsa_String lsa_group_name ;
2008-05-29 03:43:06 +04:00
struct dom_sid2 * domain_sid = NULL ;
2008-06-02 19:31:00 +04:00
int i = 0 ;
2011-01-14 17:49:37 +03:00
struct dcerpc_binding_handle * b = NULL ;
2008-05-29 03:43:06 +04:00
struct samr_Ids rids ;
struct samr_Ids types ;
union samr_GroupInfo * info = NULL ;
2010-10-07 15:01:29 +04:00
struct samr_RidAttrArray * rid_array = NULL ;
2008-05-29 03:43:06 +04:00
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
ZERO_STRUCT ( group_handle ) ;
if ( ! r - > in . group_name ) {
return WERR_INVALID_PARAM ;
}
2008-08-12 19:59:23 +04:00
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 18:10:13 +04:00
& ndr_table_samr ,
2008-07-20 19:59:30 +04:00
& pipe_cli ) ;
2008-05-29 03:43:06 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2011-01-14 17:49:37 +03:00
b = pipe_cli - > binding_handle ;
2008-06-03 01:55:45 +04:00
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
2009-04-16 02:40:00 +04:00
SAMR_ACCESS_LOOKUP_DOMAIN ,
2008-06-03 01:55:45 +04:00
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-05-29 03:43:06 +04:00
goto done ;
}
init_lsa_String ( & lsa_group_name , r - > in . group_name ) ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_LookupNames ( b , talloc_tos ( ) ,
2008-05-29 03:43:06 +04:00
& domain_handle ,
1 ,
& lsa_group_name ,
& rids ,
2011-01-14 17:49:37 +03:00
& types ,
& result ) ;
2008-05-29 03:43:06 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-05-29 03:43:06 +04:00
2013-11-08 09:40:55 +04:00
if ( rids . count ! = 1 ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
if ( types . count ! = 1 ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
2008-05-29 03:43:06 +04:00
if ( types . ids [ 0 ] ! = SID_NAME_DOM_GRP ) {
werr = WERR_INVALID_DATATYPE ;
goto done ;
}
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_OpenGroup ( b , talloc_tos ( ) ,
2008-05-29 03:43:06 +04:00
& domain_handle ,
SEC_STD_DELETE |
SAMR_GROUP_ACCESS_GET_MEMBERS |
SAMR_GROUP_ACCESS_REMOVE_MEMBER |
SAMR_GROUP_ACCESS_ADD_MEMBER |
SAMR_GROUP_ACCESS_LOOKUP_INFO ,
rids . ids [ 0 ] ,
2011-01-14 17:49:37 +03:00
& group_handle ,
& result ) ;
2008-05-29 03:43:06 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-05-29 03:43:06 +04:00
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_QueryGroupInfo ( b , talloc_tos ( ) ,
2008-05-29 03:43:06 +04:00
& group_handle ,
GROUPINFOATTRIBUTES ,
2011-01-14 17:49:37 +03:00
& info ,
& result ) ;
2008-05-29 03:43:06 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-05-29 03:43:06 +04:00
2008-07-18 03:11:08 +04:00
#if 0
/* breaks against NT4 */
2008-05-29 03:43:06 +04:00
if ( ! ( info - > attributes . attributes & SE_GROUP_ENABLED ) ) {
werr = WERR_ACCESS_DENIED ;
goto done ;
}
2008-07-18 03:11:08 +04:00
# endif
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_QueryGroupMember ( b , talloc_tos ( ) ,
2008-05-29 03:43:06 +04:00
& group_handle ,
2011-01-14 17:49:37 +03:00
& rid_array ,
& result ) ;
2008-05-29 03:43:06 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-05-29 03:43:06 +04:00
{
struct lsa_Strings names ;
struct samr_Ids member_types ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_LookupRids ( b , talloc_tos ( ) ,
2008-05-29 03:43:06 +04:00
& domain_handle ,
rid_array - > count ,
rid_array - > rids ,
& names ,
2011-01-14 17:49:37 +03:00
& member_types ,
& result ) ;
2008-05-29 03:43:06 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2013-11-08 10:41:22 +04:00
if ( names . count ! = rid_array - > count ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
if ( member_types . count ! = rid_array - > count ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
2008-05-29 03:43:06 +04:00
}
for ( i = 0 ; i < rid_array - > count ; i + + ) {
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_DeleteGroupMember ( b , talloc_tos ( ) ,
2008-05-29 03:43:06 +04:00
& group_handle ,
2011-01-14 17:49:37 +03:00
rid_array - > rids [ i ] ,
& result ) ;
2008-05-29 03:43:06 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-05-29 03:43:06 +04:00
}
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_DeleteDomainGroup ( b , talloc_tos ( ) ,
& group_handle ,
& result ) ;
2008-05-29 03:43:06 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-05-29 03:43:06 +04:00
ZERO_STRUCT ( group_handle ) ;
werr = WERR_OK ;
done :
if ( is_valid_policy_hnd ( & group_handle ) ) {
2011-01-14 17:49:37 +03:00
dcerpc_samr_Close ( b , talloc_tos ( ) , & group_handle , & result ) ;
2008-05-29 03:43:06 +04:00
}
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-05-29 03:43:06 +04:00
}
return werr ;
2008-05-27 14:11:28 +04:00
}
2008-05-29 03:43:06 +04:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-05-27 14:11:28 +04:00
WERROR NetGroupDel_l ( struct libnetapi_ctx * ctx ,
struct NetGroupDel * r )
{
2008-08-12 17:25:06 +04:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetGroupDel ) ;
2008-05-27 14:11:28 +04:00
}
2008-06-02 14:54:17 +04:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetGroupSetInfo_r ( struct libnetapi_ctx * ctx ,
struct NetGroupSetInfo * r )
{
2008-06-02 14:58:02 +04:00
struct rpc_pipe_client * pipe_cli = NULL ;
2011-01-14 17:49:37 +03:00
NTSTATUS status , result ;
2008-06-02 14:58:02 +04:00
WERROR werr ;
2009-03-19 00:49:41 +03:00
struct policy_handle connect_handle , domain_handle , group_handle ;
2008-06-02 19:31:00 +04:00
struct lsa_String lsa_group_name ;
2008-06-02 14:58:02 +04:00
struct dom_sid2 * domain_sid = NULL ;
2011-01-14 17:49:37 +03:00
struct dcerpc_binding_handle * b = NULL ;
2008-06-02 14:58:02 +04:00
struct samr_Ids rids ;
struct samr_Ids types ;
union samr_GroupInfo info ;
struct GROUP_INFO_0 * g0 ;
struct GROUP_INFO_1 * g1 ;
struct GROUP_INFO_2 * g2 ;
struct GROUP_INFO_3 * g3 ;
struct GROUP_INFO_1002 * g1002 ;
struct GROUP_INFO_1005 * g1005 ;
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
ZERO_STRUCT ( group_handle ) ;
if ( ! r - > in . group_name ) {
return WERR_INVALID_PARAM ;
}
2008-08-12 19:59:23 +04:00
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 18:10:13 +04:00
& ndr_table_samr ,
2008-07-20 19:59:30 +04:00
& pipe_cli ) ;
2008-06-02 14:58:02 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2011-01-14 17:49:37 +03:00
b = pipe_cli - > binding_handle ;
2008-06-03 01:55:45 +04:00
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
2009-04-16 02:40:00 +04:00
SAMR_ACCESS_LOOKUP_DOMAIN ,
2008-06-03 01:55:45 +04:00
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-06-02 14:58:02 +04:00
goto done ;
}
init_lsa_String ( & lsa_group_name , r - > in . group_name ) ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_LookupNames ( b , talloc_tos ( ) ,
2008-06-02 14:58:02 +04:00
& domain_handle ,
1 ,
& lsa_group_name ,
& rids ,
2011-01-14 17:49:37 +03:00
& types ,
& result ) ;
2008-06-02 14:58:02 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2013-11-08 09:40:55 +04:00
if ( rids . count ! = 1 ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
if ( types . count ! = 1 ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
2008-06-02 14:58:02 +04:00
if ( types . ids [ 0 ] ! = SID_NAME_DOM_GRP ) {
werr = WERR_INVALID_DATATYPE ;
goto done ;
}
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_OpenGroup ( b , talloc_tos ( ) ,
2008-06-02 14:58:02 +04:00
& domain_handle ,
SAMR_GROUP_ACCESS_SET_INFO |
SAMR_GROUP_ACCESS_LOOKUP_INFO ,
rids . ids [ 0 ] ,
2011-01-14 17:49:37 +03:00
& group_handle ,
& result ) ;
2008-06-02 14:58:02 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-06-02 14:58:02 +04:00
switch ( r - > in . level ) {
case 0 :
2008-07-19 01:33:08 +04:00
g0 = ( struct GROUP_INFO_0 * ) r - > in . buffer ;
2008-06-02 14:58:02 +04:00
init_lsa_String ( & info . name , g0 - > grpi0_name ) ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_SetGroupInfo ( b , talloc_tos ( ) ,
2008-06-02 14:58:02 +04:00
& group_handle ,
GROUPINFONAME ,
2011-01-14 17:49:37 +03:00
& info ,
& result ) ;
2008-06-02 14:58:02 +04:00
break ;
case 1 :
2008-07-19 01:33:08 +04:00
g1 = ( struct GROUP_INFO_1 * ) r - > in . buffer ;
2008-06-02 14:58:02 +04:00
init_lsa_String ( & info . description , g1 - > grpi1_comment ) ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_SetGroupInfo ( b , talloc_tos ( ) ,
2008-06-02 14:58:02 +04:00
& group_handle ,
GROUPINFODESCRIPTION ,
2011-01-14 17:49:37 +03:00
& info ,
& result ) ;
2008-06-02 14:58:02 +04:00
break ;
case 2 :
2008-07-19 01:33:08 +04:00
g2 = ( struct GROUP_INFO_2 * ) r - > in . buffer ;
2008-06-02 14:58:02 +04:00
init_lsa_String ( & info . description , g2 - > grpi2_comment ) ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_SetGroupInfo ( b , talloc_tos ( ) ,
2008-06-02 14:58:02 +04:00
& group_handle ,
GROUPINFODESCRIPTION ,
2011-01-14 17:49:37 +03:00
& info ,
& result ) ;
2008-06-02 14:58:02 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-06-02 14:58:02 +04:00
info . attributes . attributes = g2 - > grpi2_attributes ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_SetGroupInfo ( b , talloc_tos ( ) ,
2008-06-02 14:58:02 +04:00
& group_handle ,
GROUPINFOATTRIBUTES ,
2011-01-14 17:49:37 +03:00
& info ,
& result ) ;
2008-06-02 14:58:02 +04:00
break ;
case 3 :
2008-07-19 01:33:08 +04:00
g3 = ( struct GROUP_INFO_3 * ) r - > in . buffer ;
2008-06-02 14:58:02 +04:00
init_lsa_String ( & info . description , g3 - > grpi3_comment ) ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_SetGroupInfo ( b , talloc_tos ( ) ,
2008-06-02 14:58:02 +04:00
& group_handle ,
GROUPINFODESCRIPTION ,
2011-01-14 17:49:37 +03:00
& info ,
& result ) ;
2008-06-02 14:58:02 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-06-02 14:58:02 +04:00
info . attributes . attributes = g3 - > grpi3_attributes ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_SetGroupInfo ( b , talloc_tos ( ) ,
2008-06-02 14:58:02 +04:00
& group_handle ,
GROUPINFOATTRIBUTES ,
2011-01-14 17:49:37 +03:00
& info ,
& result ) ;
2008-06-02 14:58:02 +04:00
break ;
case 1002 :
2008-07-19 01:33:08 +04:00
g1002 = ( struct GROUP_INFO_1002 * ) r - > in . buffer ;
2008-06-02 14:58:02 +04:00
init_lsa_String ( & info . description , g1002 - > grpi1002_comment ) ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_SetGroupInfo ( b , talloc_tos ( ) ,
2008-06-02 14:58:02 +04:00
& group_handle ,
GROUPINFODESCRIPTION ,
2011-01-14 17:49:37 +03:00
& info ,
& result ) ;
2008-06-02 14:58:02 +04:00
break ;
case 1005 :
2008-07-19 01:33:08 +04:00
g1005 = ( struct GROUP_INFO_1005 * ) r - > in . buffer ;
2008-06-02 14:58:02 +04:00
info . attributes . attributes = g1005 - > grpi1005_attributes ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_SetGroupInfo ( b , talloc_tos ( ) ,
2008-06-02 14:58:02 +04:00
& group_handle ,
GROUPINFOATTRIBUTES ,
2011-01-14 17:49:37 +03:00
& info ,
& result ) ;
2008-06-02 14:58:02 +04:00
break ;
default :
status = NT_STATUS_INVALID_LEVEL ;
break ;
}
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-06-02 14:58:02 +04:00
werr = WERR_OK ;
done :
if ( is_valid_policy_hnd ( & group_handle ) ) {
2011-01-14 17:49:37 +03:00
dcerpc_samr_Close ( b , talloc_tos ( ) , & group_handle , & result ) ;
2008-06-02 14:58:02 +04:00
}
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-06-02 14:58:02 +04:00
}
return werr ;
2008-06-02 14:54:17 +04:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetGroupSetInfo_l ( struct libnetapi_ctx * ctx ,
struct NetGroupSetInfo * r )
{
2008-08-12 17:25:06 +04:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetGroupSetInfo ) ;
2008-06-02 14:54:17 +04:00
}
2008-06-02 15:04:15 +04:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-06-02 15:04:58 +04:00
static WERROR map_group_info_to_buffer ( TALLOC_CTX * mem_ctx ,
uint32_t level ,
struct samr_GroupInfoAll * info ,
struct dom_sid2 * domain_sid ,
uint32_t rid ,
uint8_t * * buffer )
{
struct GROUP_INFO_0 info0 ;
struct GROUP_INFO_1 info1 ;
struct GROUP_INFO_2 info2 ;
struct GROUP_INFO_3 info3 ;
2008-07-16 18:14:47 +04:00
struct dom_sid sid ;
2008-06-02 15:04:58 +04:00
switch ( level ) {
case 0 :
info0 . grpi0_name = info - > name . string ;
* buffer = ( uint8_t * ) talloc_memdup ( mem_ctx , & info0 , sizeof ( info0 ) ) ;
break ;
case 1 :
info1 . grpi1_name = info - > name . string ;
info1 . grpi1_comment = info - > description . string ;
* buffer = ( uint8_t * ) talloc_memdup ( mem_ctx , & info1 , sizeof ( info1 ) ) ;
break ;
case 2 :
info2 . grpi2_name = info - > name . string ;
info2 . grpi2_comment = info - > description . string ;
info2 . grpi2_group_id = rid ;
info2 . grpi2_attributes = info - > attributes ;
* buffer = ( uint8_t * ) talloc_memdup ( mem_ctx , & info2 , sizeof ( info2 ) ) ;
break ;
case 3 :
2008-07-16 18:14:47 +04:00
if ( ! sid_compose ( & sid , domain_sid , rid ) ) {
return WERR_NOMEM ;
}
2008-06-02 15:04:58 +04:00
info3 . grpi3_name = info - > name . string ;
info3 . grpi3_comment = info - > description . string ;
info3 . grpi3_attributes = info - > attributes ;
2010-08-26 19:21:39 +04:00
info3 . grpi3_group_sid = ( struct domsid * ) dom_sid_dup ( mem_ctx , & sid ) ;
2008-06-02 15:04:58 +04:00
* buffer = ( uint8_t * ) talloc_memdup ( mem_ctx , & info3 , sizeof ( info3 ) ) ;
break ;
default :
return WERR_UNKNOWN_LEVEL ;
}
W_ERROR_HAVE_NO_MEMORY ( * buffer ) ;
return WERR_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-06-02 15:04:15 +04:00
WERROR NetGroupGetInfo_r ( struct libnetapi_ctx * ctx ,
struct NetGroupGetInfo * r )
{
2008-06-02 15:04:58 +04:00
struct rpc_pipe_client * pipe_cli = NULL ;
2011-01-14 17:49:37 +03:00
NTSTATUS status , result ;
2008-06-02 15:04:58 +04:00
WERROR werr ;
2009-03-19 00:49:41 +03:00
struct policy_handle connect_handle , domain_handle , group_handle ;
2008-06-02 19:31:00 +04:00
struct lsa_String lsa_group_name ;
2008-06-02 15:04:58 +04:00
struct dom_sid2 * domain_sid = NULL ;
2011-01-14 17:49:37 +03:00
struct dcerpc_binding_handle * b = NULL ;
2008-06-02 15:04:58 +04:00
struct samr_Ids rids ;
struct samr_Ids types ;
union samr_GroupInfo * info = NULL ;
2008-07-18 03:11:32 +04:00
bool group_info_all = false ;
2008-06-02 15:04:58 +04:00
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
ZERO_STRUCT ( group_handle ) ;
if ( ! r - > in . group_name ) {
return WERR_INVALID_PARAM ;
}
2008-08-12 19:59:23 +04:00
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 18:10:13 +04:00
& ndr_table_samr ,
2008-07-20 19:59:30 +04:00
& pipe_cli ) ;
2008-06-02 15:04:58 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2011-01-14 17:49:37 +03:00
b = pipe_cli - > binding_handle ;
2008-06-03 01:55:45 +04:00
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
2009-04-16 02:40:00 +04:00
SAMR_ACCESS_LOOKUP_DOMAIN ,
2008-06-03 01:55:45 +04:00
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-06-02 15:04:58 +04:00
goto done ;
}
init_lsa_String ( & lsa_group_name , r - > in . group_name ) ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_LookupNames ( b , talloc_tos ( ) ,
2008-06-02 15:04:58 +04:00
& domain_handle ,
1 ,
& lsa_group_name ,
& rids ,
2011-01-14 17:49:37 +03:00
& types ,
& result ) ;
2008-06-02 15:04:58 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2013-11-08 09:40:55 +04:00
if ( rids . count ! = 1 ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
if ( types . count ! = 1 ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
2008-06-02 15:04:58 +04:00
if ( types . ids [ 0 ] ! = SID_NAME_DOM_GRP ) {
werr = WERR_INVALID_DATATYPE ;
goto done ;
}
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_OpenGroup ( b , talloc_tos ( ) ,
2008-06-02 15:04:58 +04:00
& domain_handle ,
SAMR_GROUP_ACCESS_LOOKUP_INFO ,
rids . ids [ 0 ] ,
2011-01-14 17:49:37 +03:00
& group_handle ,
& result ) ;
2008-06-02 15:04:58 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-06-02 15:04:58 +04:00
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_QueryGroupInfo ( b , talloc_tos ( ) ,
2008-06-02 15:04:58 +04:00
& group_handle ,
GROUPINFOALL2 ,
2011-01-14 17:49:37 +03:00
& info ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
if ( NT_STATUS_EQUAL ( result , NT_STATUS_INVALID_INFO_CLASS ) ) {
status = dcerpc_samr_QueryGroupInfo ( b , talloc_tos ( ) ,
2008-07-18 03:11:32 +04:00
& group_handle ,
GROUPINFOALL ,
2011-01-14 17:49:37 +03:00
& info ,
& result ) ;
2008-07-18 03:11:32 +04:00
group_info_all = true ;
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2008-07-18 03:11:32 +04:00
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
2008-06-02 15:04:58 +04:00
goto done ;
}
werr = map_group_info_to_buffer ( ctx , r - > in . level ,
2008-07-18 03:11:32 +04:00
group_info_all ? & info - > all : & info - > all2 ,
domain_sid , rids . ids [ 0 ] ,
2008-07-19 01:33:08 +04:00
r - > out . buffer ) ;
2008-06-02 15:04:58 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
done :
if ( is_valid_policy_hnd ( & group_handle ) ) {
2011-01-14 17:49:37 +03:00
dcerpc_samr_Close ( b , talloc_tos ( ) , & group_handle , & result ) ;
2008-06-02 15:04:58 +04:00
}
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-06-02 15:04:58 +04:00
}
return werr ;
2008-06-02 15:04:15 +04:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetGroupGetInfo_l ( struct libnetapi_ctx * ctx ,
struct NetGroupGetInfo * r )
{
2008-08-12 17:25:06 +04:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetGroupGetInfo ) ;
2008-06-02 15:04:15 +04:00
}
2008-06-02 15:43:21 +04:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetGroupAddUser_r ( struct libnetapi_ctx * ctx ,
struct NetGroupAddUser * r )
{
2008-06-02 16:46:56 +04:00
struct rpc_pipe_client * pipe_cli = NULL ;
2011-01-14 17:49:37 +03:00
NTSTATUS status , result ;
2008-06-02 16:46:56 +04:00
WERROR werr ;
2009-03-19 00:49:41 +03:00
struct policy_handle connect_handle , domain_handle , group_handle ;
2008-06-02 19:31:00 +04:00
struct lsa_String lsa_group_name , lsa_user_name ;
2008-06-02 16:46:56 +04:00
struct dom_sid2 * domain_sid = NULL ;
2011-01-14 17:49:37 +03:00
struct dcerpc_binding_handle * b = NULL ;
2008-06-02 16:46:56 +04:00
struct samr_Ids rids ;
struct samr_Ids types ;
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
ZERO_STRUCT ( group_handle ) ;
if ( ! r - > in . group_name ) {
return WERR_INVALID_PARAM ;
}
2008-08-12 19:59:23 +04:00
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 18:10:13 +04:00
& ndr_table_samr ,
2008-07-20 19:59:30 +04:00
& pipe_cli ) ;
2008-06-02 16:46:56 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2011-01-14 17:49:37 +03:00
b = pipe_cli - > binding_handle ;
2008-06-03 01:55:45 +04:00
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
2009-04-16 02:40:00 +04:00
SAMR_ACCESS_LOOKUP_DOMAIN ,
2008-06-03 01:55:45 +04:00
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-06-02 16:46:56 +04:00
goto done ;
}
init_lsa_String ( & lsa_group_name , r - > in . group_name ) ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_LookupNames ( b , talloc_tos ( ) ,
2008-06-02 16:46:56 +04:00
& domain_handle ,
1 ,
& lsa_group_name ,
& rids ,
2011-01-14 17:49:37 +03:00
& types ,
& result ) ;
2008-06-02 16:46:56 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-01-14 17:49:37 +03:00
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-09-18 01:20:23 +04:00
werr = WERR_GROUPNOTFOUND ;
2008-06-02 16:46:56 +04:00
goto done ;
}
2013-11-08 09:40:55 +04:00
if ( rids . count ! = 1 ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
if ( types . count ! = 1 ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
2008-06-02 16:46:56 +04:00
if ( types . ids [ 0 ] ! = SID_NAME_DOM_GRP ) {
2009-09-18 01:20:23 +04:00
werr = WERR_GROUPNOTFOUND ;
2008-06-02 16:46:56 +04:00
goto done ;
}
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_OpenGroup ( b , talloc_tos ( ) ,
2008-06-02 16:46:56 +04:00
& domain_handle ,
SAMR_GROUP_ACCESS_ADD_MEMBER ,
rids . ids [ 0 ] ,
2011-01-14 17:49:37 +03:00
& group_handle ,
& result ) ;
2008-06-02 16:46:56 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-06-02 16:46:56 +04:00
init_lsa_String ( & lsa_user_name , r - > in . user_name ) ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_LookupNames ( b , talloc_tos ( ) ,
2008-06-02 16:46:56 +04:00
& domain_handle ,
1 ,
& lsa_user_name ,
& rids ,
2011-01-14 17:49:37 +03:00
& types ,
& result ) ;
2008-06-02 16:46:56 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-01-14 17:49:37 +03:00
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
if ( ! NT_STATUS_IS_OK ( result ) ) {
2008-06-02 16:46:56 +04:00
werr = WERR_USER_NOT_FOUND ;
goto done ;
}
2013-11-08 09:40:55 +04:00
if ( rids . count ! = 1 ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
if ( types . count ! = 1 ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
2008-06-02 16:46:56 +04:00
if ( types . ids [ 0 ] ! = SID_NAME_USER ) {
werr = WERR_USER_NOT_FOUND ;
goto done ;
}
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_AddGroupMember ( b , talloc_tos ( ) ,
2008-06-02 16:46:56 +04:00
& group_handle ,
rids . ids [ 0 ] ,
2011-01-14 17:49:37 +03:00
7 , /* why ? */
& result ) ;
2008-06-02 16:46:56 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-06-02 16:46:56 +04:00
werr = WERR_OK ;
done :
if ( is_valid_policy_hnd ( & group_handle ) ) {
2011-01-14 17:49:37 +03:00
dcerpc_samr_Close ( b , talloc_tos ( ) , & group_handle , & result ) ;
2008-06-02 16:46:56 +04:00
}
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-06-02 16:46:56 +04:00
}
return werr ;
2008-06-02 15:43:21 +04:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetGroupAddUser_l ( struct libnetapi_ctx * ctx ,
struct NetGroupAddUser * r )
{
2008-08-12 17:25:06 +04:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetGroupAddUser ) ;
2008-06-02 15:43:21 +04:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetGroupDelUser_r ( struct libnetapi_ctx * ctx ,
struct NetGroupDelUser * r )
{
2008-06-02 16:58:01 +04:00
struct rpc_pipe_client * pipe_cli = NULL ;
2011-01-14 17:49:37 +03:00
NTSTATUS status , result ;
2008-06-02 16:58:01 +04:00
WERROR werr ;
2009-03-19 00:49:41 +03:00
struct policy_handle connect_handle , domain_handle , group_handle ;
2008-06-02 19:31:00 +04:00
struct lsa_String lsa_group_name , lsa_user_name ;
2008-06-02 16:58:01 +04:00
struct dom_sid2 * domain_sid = NULL ;
2011-01-14 17:49:37 +03:00
struct dcerpc_binding_handle * b = NULL ;
2008-06-02 16:58:01 +04:00
struct samr_Ids rids ;
struct samr_Ids types ;
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
ZERO_STRUCT ( group_handle ) ;
if ( ! r - > in . group_name ) {
return WERR_INVALID_PARAM ;
}
2008-08-12 19:59:23 +04:00
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 18:10:13 +04:00
& ndr_table_samr ,
2008-07-20 19:59:30 +04:00
& pipe_cli ) ;
2008-06-02 16:58:01 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2011-01-14 17:49:37 +03:00
b = pipe_cli - > binding_handle ;
2008-06-03 01:55:45 +04:00
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
2009-04-16 02:40:00 +04:00
SAMR_ACCESS_LOOKUP_DOMAIN ,
2008-06-03 01:55:45 +04:00
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-06-02 16:58:01 +04:00
goto done ;
}
init_lsa_String ( & lsa_group_name , r - > in . group_name ) ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_LookupNames ( b , talloc_tos ( ) ,
2008-06-02 16:58:01 +04:00
& domain_handle ,
1 ,
& lsa_group_name ,
& rids ,
2011-01-14 17:49:37 +03:00
& types ,
& result ) ;
2008-06-02 16:58:01 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-01-14 17:49:37 +03:00
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
if ( ! NT_STATUS_IS_OK ( result ) ) {
2009-09-18 01:20:23 +04:00
werr = WERR_GROUPNOTFOUND ;
2008-06-02 16:58:01 +04:00
goto done ;
}
2013-11-08 09:40:55 +04:00
if ( rids . count ! = 1 ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
if ( types . count ! = 1 ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
2008-06-02 16:58:01 +04:00
if ( types . ids [ 0 ] ! = SID_NAME_DOM_GRP ) {
2009-09-18 01:20:23 +04:00
werr = WERR_GROUPNOTFOUND ;
2008-06-02 16:58:01 +04:00
goto done ;
}
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_OpenGroup ( b , talloc_tos ( ) ,
2008-06-02 16:58:01 +04:00
& domain_handle ,
SAMR_GROUP_ACCESS_REMOVE_MEMBER ,
rids . ids [ 0 ] ,
2011-01-14 17:49:37 +03:00
& group_handle ,
& result ) ;
2008-06-02 16:58:01 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-06-02 16:58:01 +04:00
init_lsa_String ( & lsa_user_name , r - > in . user_name ) ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_LookupNames ( b , talloc_tos ( ) ,
2008-06-02 16:58:01 +04:00
& domain_handle ,
1 ,
& lsa_user_name ,
& rids ,
2011-01-14 17:49:37 +03:00
& types ,
& result ) ;
2008-06-02 16:58:01 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-01-14 17:49:37 +03:00
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
if ( ! NT_STATUS_IS_OK ( result ) ) {
2008-06-02 16:58:01 +04:00
werr = WERR_USER_NOT_FOUND ;
goto done ;
}
2013-11-08 09:40:55 +04:00
if ( rids . count ! = 1 ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
if ( types . count ! = 1 ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
2008-06-02 16:58:01 +04:00
if ( types . ids [ 0 ] ! = SID_NAME_USER ) {
werr = WERR_USER_NOT_FOUND ;
goto done ;
}
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_DeleteGroupMember ( b , talloc_tos ( ) ,
2008-06-02 16:58:01 +04:00
& group_handle ,
2011-01-14 17:49:37 +03:00
rids . ids [ 0 ] ,
& result ) ;
2008-06-02 16:58:01 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-06-02 16:58:01 +04:00
werr = WERR_OK ;
done :
if ( is_valid_policy_hnd ( & group_handle ) ) {
2011-01-14 17:49:37 +03:00
dcerpc_samr_Close ( b , talloc_tos ( ) , & group_handle , & result ) ;
2008-06-02 16:58:01 +04:00
}
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-06-02 16:58:01 +04:00
}
return werr ;
2008-06-02 15:43:21 +04:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetGroupDelUser_l ( struct libnetapi_ctx * ctx ,
struct NetGroupDelUser * r )
{
2008-08-12 17:25:06 +04:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetGroupDelUser ) ;
2008-06-02 15:43:21 +04:00
}
2008-07-01 22:11:02 +04:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-07-17 03:06:29 +04:00
static WERROR convert_samr_disp_groups_to_GROUP_INFO_0_buffer ( TALLOC_CTX * mem_ctx ,
struct samr_DispInfoFullGroups * groups ,
uint8_t * * buffer )
{
struct GROUP_INFO_0 * g0 ;
int i ;
2011-06-07 05:58:39 +04:00
g0 = talloc_zero_array ( mem_ctx , struct GROUP_INFO_0 , groups - > count ) ;
2008-07-17 03:06:29 +04:00
W_ERROR_HAVE_NO_MEMORY ( g0 ) ;
for ( i = 0 ; i < groups - > count ; i + + ) {
g0 [ i ] . grpi0_name = talloc_strdup ( mem_ctx ,
groups - > entries [ i ] . account_name . string ) ;
W_ERROR_HAVE_NO_MEMORY ( g0 [ i ] . grpi0_name ) ;
}
* buffer = ( uint8_t * ) talloc_memdup ( mem_ctx , g0 ,
sizeof ( struct GROUP_INFO_0 ) * groups - > count ) ;
W_ERROR_HAVE_NO_MEMORY ( * buffer ) ;
return WERR_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static WERROR convert_samr_disp_groups_to_GROUP_INFO_1_buffer ( TALLOC_CTX * mem_ctx ,
struct samr_DispInfoFullGroups * groups ,
uint8_t * * buffer )
{
struct GROUP_INFO_1 * g1 ;
int i ;
2011-06-07 05:58:39 +04:00
g1 = talloc_zero_array ( mem_ctx , struct GROUP_INFO_1 , groups - > count ) ;
2008-07-17 03:06:29 +04:00
W_ERROR_HAVE_NO_MEMORY ( g1 ) ;
for ( i = 0 ; i < groups - > count ; i + + ) {
g1 [ i ] . grpi1_name = talloc_strdup ( mem_ctx ,
groups - > entries [ i ] . account_name . string ) ;
g1 [ i ] . grpi1_comment = talloc_strdup ( mem_ctx ,
groups - > entries [ i ] . description . string ) ;
W_ERROR_HAVE_NO_MEMORY ( g1 [ i ] . grpi1_name ) ;
}
* buffer = ( uint8_t * ) talloc_memdup ( mem_ctx , g1 ,
sizeof ( struct GROUP_INFO_1 ) * groups - > count ) ;
W_ERROR_HAVE_NO_MEMORY ( * buffer ) ;
return WERR_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static WERROR convert_samr_disp_groups_to_GROUP_INFO_2_buffer ( TALLOC_CTX * mem_ctx ,
struct samr_DispInfoFullGroups * groups ,
uint8_t * * buffer )
{
struct GROUP_INFO_2 * g2 ;
int i ;
2011-06-07 05:58:39 +04:00
g2 = talloc_zero_array ( mem_ctx , struct GROUP_INFO_2 , groups - > count ) ;
2008-07-17 03:06:29 +04:00
W_ERROR_HAVE_NO_MEMORY ( g2 ) ;
for ( i = 0 ; i < groups - > count ; i + + ) {
g2 [ i ] . grpi2_name = talloc_strdup ( mem_ctx ,
groups - > entries [ i ] . account_name . string ) ;
g2 [ i ] . grpi2_comment = talloc_strdup ( mem_ctx ,
groups - > entries [ i ] . description . string ) ;
g2 [ i ] . grpi2_group_id = groups - > entries [ i ] . rid ;
g2 [ i ] . grpi2_attributes = groups - > entries [ i ] . acct_flags ;
W_ERROR_HAVE_NO_MEMORY ( g2 [ i ] . grpi2_name ) ;
}
* buffer = ( uint8_t * ) talloc_memdup ( mem_ctx , g2 ,
sizeof ( struct GROUP_INFO_2 ) * groups - > count ) ;
W_ERROR_HAVE_NO_MEMORY ( * buffer ) ;
return WERR_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static WERROR convert_samr_disp_groups_to_GROUP_INFO_3_buffer ( TALLOC_CTX * mem_ctx ,
struct samr_DispInfoFullGroups * groups ,
const struct dom_sid * domain_sid ,
uint8_t * * buffer )
{
struct GROUP_INFO_3 * g3 ;
int i ;
2011-06-07 05:58:39 +04:00
g3 = talloc_zero_array ( mem_ctx , struct GROUP_INFO_3 , groups - > count ) ;
2008-07-17 03:06:29 +04:00
W_ERROR_HAVE_NO_MEMORY ( g3 ) ;
for ( i = 0 ; i < groups - > count ; i + + ) {
struct dom_sid sid ;
if ( ! sid_compose ( & sid , domain_sid , groups - > entries [ i ] . rid ) ) {
return WERR_NOMEM ;
}
g3 [ i ] . grpi3_name = talloc_strdup ( mem_ctx ,
groups - > entries [ i ] . account_name . string ) ;
g3 [ i ] . grpi3_comment = talloc_strdup ( mem_ctx ,
groups - > entries [ i ] . description . string ) ;
2010-08-26 19:21:39 +04:00
g3 [ i ] . grpi3_group_sid = ( struct domsid * ) dom_sid_dup ( mem_ctx , & sid ) ;
2008-07-17 03:06:29 +04:00
g3 [ i ] . grpi3_attributes = groups - > entries [ i ] . acct_flags ;
W_ERROR_HAVE_NO_MEMORY ( g3 [ i ] . grpi3_name ) ;
}
* buffer = ( uint8_t * ) talloc_memdup ( mem_ctx , g3 ,
sizeof ( struct GROUP_INFO_3 ) * groups - > count ) ;
W_ERROR_HAVE_NO_MEMORY ( * buffer ) ;
return WERR_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static WERROR convert_samr_disp_groups_to_GROUP_INFO_buffer ( TALLOC_CTX * mem_ctx ,
uint32_t level ,
struct samr_DispInfoFullGroups * groups ,
const struct dom_sid * domain_sid ,
uint32_t * entries_read ,
uint8_t * * buffer )
{
if ( entries_read ) {
* entries_read = groups - > count ;
}
switch ( level ) {
case 0 :
return convert_samr_disp_groups_to_GROUP_INFO_0_buffer ( mem_ctx , groups , buffer ) ;
case 1 :
return convert_samr_disp_groups_to_GROUP_INFO_1_buffer ( mem_ctx , groups , buffer ) ;
case 2 :
return convert_samr_disp_groups_to_GROUP_INFO_2_buffer ( mem_ctx , groups , buffer ) ;
case 3 :
return convert_samr_disp_groups_to_GROUP_INFO_3_buffer ( mem_ctx , groups , domain_sid , buffer ) ;
default :
return WERR_UNKNOWN_LEVEL ;
}
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-07-01 22:11:02 +04:00
WERROR NetGroupEnum_r ( struct libnetapi_ctx * ctx ,
struct NetGroupEnum * r )
{
2008-07-17 03:06:29 +04:00
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 ;
union samr_DomainInfo * domain_info = NULL ;
2011-01-14 17:49:37 +03:00
struct dcerpc_binding_handle * b = NULL ;
2008-07-17 03:06:29 +04:00
uint32_t total_size = 0 ;
uint32_t returned_size = 0 ;
2011-01-14 17:49:37 +03:00
NTSTATUS result = NT_STATUS_OK ;
2008-07-18 00:44:24 +04:00
NTSTATUS status = NT_STATUS_OK ;
2008-07-17 03:06:29 +04:00
WERROR werr , tmp_werr ;
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
switch ( r - > in . level ) {
case 0 :
case 1 :
case 2 :
case 3 :
break ;
default :
return WERR_UNKNOWN_LEVEL ;
}
2008-08-12 19:59:23 +04:00
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 18:10:13 +04:00
& ndr_table_samr ,
2008-07-20 19:59:30 +04:00
& pipe_cli ) ;
2008-07-17 03:06:29 +04:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2011-01-14 17:49:37 +03:00
b = pipe_cli - > binding_handle ;
2008-07-17 03:06:29 +04:00
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
2009-04-16 02:40:00 +04:00
SAMR_ACCESS_LOOKUP_DOMAIN ,
2008-07-17 03:06:29 +04:00
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 ) ) {
goto done ;
}
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_QueryDomainInfo ( b , talloc_tos ( ) ,
2008-07-17 03:06:29 +04:00
& domain_handle ,
2 ,
2011-01-14 17:49:37 +03:00
& domain_info ,
& result ) ;
2008-07-17 03:06:29 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-07-17 03:06:29 +04:00
if ( r - > out . total_entries ) {
2008-10-15 19:10:53 +04:00
* r - > out . total_entries = domain_info - > general . num_groups ;
2008-07-17 03:06:29 +04:00
}
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_QueryDisplayInfo2 ( b ,
2008-07-17 03:06:29 +04:00
ctx ,
& domain_handle ,
3 ,
r - > in . resume_handle ?
* r - > in . resume_handle : 0 ,
( uint32_t ) - 1 ,
r - > in . prefmaxlen ,
& total_size ,
& returned_size ,
2011-01-14 17:49:37 +03:00
& info ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
werr = ntstatus_to_werror ( result ) ;
if ( NT_STATUS_IS_ERR ( result ) ) {
2008-07-17 03:06:29 +04:00
goto done ;
}
2008-10-23 03:43:06 +04:00
if ( r - > out . resume_handle & & info . info3 . count > 0 ) {
2008-07-17 03:06:29 +04:00
* r - > out . resume_handle =
info . info3 . entries [ info . info3 . count - 1 ] . idx ;
}
tmp_werr = convert_samr_disp_groups_to_GROUP_INFO_buffer ( ctx ,
r - > in . level ,
& info . info3 ,
domain_sid ,
r - > out . entries_read ,
r - > out . buffer ) ;
if ( ! W_ERROR_IS_OK ( tmp_werr ) ) {
werr = tmp_werr ;
goto done ;
}
done :
2008-07-18 00:44:24 +04:00
/* if last query */
2011-01-14 17:49:37 +03:00
if ( NT_STATUS_IS_OK ( result ) | |
NT_STATUS_IS_ERR ( result ) ) {
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-17 03:06:29 +04:00
}
2008-07-18 00:44:24 +04:00
2008-07-17 03:06:29 +04:00
return werr ;
2008-07-01 22:11:02 +04:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetGroupEnum_l ( struct libnetapi_ctx * ctx ,
struct NetGroupEnum * r )
{
2008-08-12 17:25:06 +04:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetGroupEnum ) ;
2008-07-01 22:11:02 +04:00
}
2008-07-19 01:40:33 +04:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetGroupGetUsers_r ( struct libnetapi_ctx * ctx ,
struct NetGroupGetUsers * r )
{
2008-09-08 18:42:38 +04:00
/* FIXME: this call needs to cope with large replies */
struct rpc_pipe_client * pipe_cli = NULL ;
struct policy_handle connect_handle , domain_handle , group_handle ;
struct lsa_String lsa_account_name ;
struct dom_sid2 * domain_sid = NULL ;
struct samr_Ids group_rids , name_types ;
2010-10-07 15:01:29 +04:00
struct samr_RidAttrArray * rid_array = NULL ;
2008-09-08 18:42:38 +04:00
struct lsa_Strings names ;
struct samr_Ids member_types ;
2011-01-14 17:49:37 +03:00
struct dcerpc_binding_handle * b = NULL ;
2008-09-08 18:42:38 +04:00
int i ;
uint32_t entries_read = 0 ;
NTSTATUS status = NT_STATUS_OK ;
2011-01-14 17:49:37 +03:00
NTSTATUS result = NT_STATUS_OK ;
2008-09-08 18:42:38 +04:00
WERROR werr ;
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
2012-12-06 21:06:59 +04:00
ZERO_STRUCT ( group_handle ) ;
2008-09-08 18:42:38 +04:00
if ( ! r - > out . buffer ) {
return WERR_INVALID_PARAM ;
}
* r - > out . buffer = NULL ;
* r - > out . entries_read = 0 ;
2009-03-20 13:17:50 +03:00
* r - > out . total_entries = 0 ;
2008-09-08 18:42:38 +04:00
switch ( r - > in . level ) {
case 0 :
case 1 :
break ;
default :
return WERR_UNKNOWN_LEVEL ;
}
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 18:10:13 +04:00
& ndr_table_samr ,
2008-09-08 18:42:38 +04:00
& pipe_cli ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2011-01-14 17:49:37 +03:00
b = pipe_cli - > binding_handle ;
2008-09-08 18:42:38 +04:00
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
2009-04-16 02:40:00 +04:00
SAMR_ACCESS_LOOKUP_DOMAIN ,
2008-09-08 18:42:38 +04:00
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
init_lsa_String ( & lsa_account_name , r - > in . group_name ) ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_LookupNames ( b , talloc_tos ( ) ,
2008-09-08 18:42:38 +04:00
& domain_handle ,
1 ,
& lsa_account_name ,
& group_rids ,
2011-01-14 17:49:37 +03:00
& name_types ,
& result ) ;
2008-09-08 18:42:38 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2013-11-08 09:40:55 +04:00
if ( group_rids . count ! = 1 ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
if ( name_types . count ! = 1 ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
2008-09-08 18:42:38 +04:00
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_OpenGroup ( b , talloc_tos ( ) ,
2008-09-08 18:42:38 +04:00
& domain_handle ,
SAMR_GROUP_ACCESS_GET_MEMBERS ,
group_rids . ids [ 0 ] ,
2011-01-14 17:49:37 +03:00
& group_handle ,
& result ) ;
2008-09-08 18:42:38 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-09-08 18:42:38 +04:00
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_QueryGroupMember ( b , talloc_tos ( ) ,
2008-09-08 18:42:38 +04:00
& group_handle ,
2011-01-14 17:49:37 +03:00
& rid_array ,
& result ) ;
2008-09-08 18:42:38 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-09-08 18:42:38 +04:00
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_LookupRids ( b , talloc_tos ( ) ,
2008-09-08 18:42:38 +04:00
& domain_handle ,
rid_array - > count ,
rid_array - > rids ,
& names ,
2011-01-14 17:49:37 +03:00
& member_types ,
& result ) ;
2008-09-08 18:42:38 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2013-11-08 10:41:22 +04:00
if ( names . count ! = rid_array - > count ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
if ( member_types . count ! = rid_array - > count ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
2008-09-08 18:42:38 +04:00
for ( i = 0 ; i < names . count ; i + + ) {
2008-09-12 13:28:42 +04:00
if ( member_types . ids [ i ] ! = SID_NAME_USER ) {
continue ;
}
2008-09-08 18:42:38 +04:00
status = add_GROUP_USERS_INFO_X_buffer ( ctx ,
r - > in . level ,
names . names [ i ] . string ,
2008-09-12 13:28:42 +04:00
7 ,
2008-09-08 18:42:38 +04:00
r - > out . buffer ,
& entries_read ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
}
2009-03-20 13:17:50 +03:00
* r - > out . entries_read = entries_read ;
* r - > out . total_entries = entries_read ;
2008-09-08 18:42:38 +04:00
werr = WERR_OK ;
done :
if ( is_valid_policy_hnd ( & group_handle ) ) {
2011-01-14 17:49:37 +03:00
dcerpc_samr_Close ( b , talloc_tos ( ) , & group_handle , & result ) ;
2008-09-08 18:42:38 +04:00
}
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-19 01:40:33 +04:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetGroupGetUsers_l ( struct libnetapi_ctx * ctx ,
struct NetGroupGetUsers * r )
{
2008-08-12 17:25:06 +04:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetGroupGetUsers ) ;
2008-07-19 01:40:33 +04:00
}
2008-09-08 12:21:17 +04:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetGroupSetUsers_r ( struct libnetapi_ctx * ctx ,
struct NetGroupSetUsers * r )
{
2008-09-09 15:17:22 +04:00
struct rpc_pipe_client * pipe_cli = NULL ;
struct policy_handle connect_handle , domain_handle , group_handle ;
struct lsa_String lsa_account_name ;
struct dom_sid2 * domain_sid = NULL ;
union samr_GroupInfo * group_info = NULL ;
struct samr_Ids user_rids , name_types ;
struct samr_Ids group_rids , group_types ;
2010-10-07 15:01:29 +04:00
struct samr_RidAttrArray * rid_array = NULL ;
2008-09-12 13:13:20 +04:00
struct lsa_String * lsa_names = NULL ;
2011-01-14 17:49:37 +03:00
struct dcerpc_binding_handle * b = NULL ;
2008-09-09 15:17:22 +04:00
uint32_t * add_rids = NULL ;
uint32_t * del_rids = NULL ;
size_t num_add_rids = 0 ;
size_t num_del_rids = 0 ;
uint32_t * member_rids = NULL ;
struct GROUP_USERS_INFO_0 * i0 = NULL ;
struct GROUP_USERS_INFO_1 * i1 = NULL ;
int i , k ;
NTSTATUS status = NT_STATUS_OK ;
2011-01-14 17:49:37 +03:00
NTSTATUS result = NT_STATUS_OK ;
2008-09-09 15:17:22 +04:00
WERROR werr ;
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
2012-12-06 20:04:47 +04:00
ZERO_STRUCT ( group_handle ) ;
2008-09-09 15:17:22 +04:00
if ( ! r - > in . buffer ) {
return WERR_INVALID_PARAM ;
}
switch ( r - > in . level ) {
case 0 :
case 1 :
break ;
default :
return WERR_UNKNOWN_LEVEL ;
}
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 18:10:13 +04:00
& ndr_table_samr ,
2008-09-09 15:17:22 +04:00
& pipe_cli ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2011-01-14 17:49:37 +03:00
b = pipe_cli - > binding_handle ;
2008-09-09 15:17:22 +04:00
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
2009-04-16 02:40:00 +04:00
SAMR_ACCESS_LOOKUP_DOMAIN ,
2008-09-09 15:17:22 +04:00
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
init_lsa_String ( & lsa_account_name , r - > in . group_name ) ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_LookupNames ( b , talloc_tos ( ) ,
2008-09-09 15:17:22 +04:00
& domain_handle ,
1 ,
& lsa_account_name ,
& group_rids ,
2011-01-14 17:49:37 +03:00
& group_types ,
& result ) ;
2008-09-09 15:17:22 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2013-11-08 09:40:55 +04:00
if ( group_rids . count ! = 1 ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
if ( group_types . count ! = 1 ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
2008-09-09 15:17:22 +04:00
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_OpenGroup ( b , talloc_tos ( ) ,
2008-09-09 15:17:22 +04:00
& domain_handle ,
SAMR_GROUP_ACCESS_GET_MEMBERS |
SAMR_GROUP_ACCESS_ADD_MEMBER |
SAMR_GROUP_ACCESS_REMOVE_MEMBER |
SAMR_GROUP_ACCESS_LOOKUP_INFO ,
group_rids . ids [ 0 ] ,
2011-01-14 17:49:37 +03:00
& group_handle ,
& result ) ;
2008-09-09 15:17:22 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-09-09 15:17:22 +04:00
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_QueryGroupInfo ( b , talloc_tos ( ) ,
2008-09-09 15:17:22 +04:00
& group_handle ,
GROUPINFOATTRIBUTES ,
2011-01-14 17:49:37 +03:00
& group_info ,
& result ) ;
2008-09-09 15:17:22 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-09-09 15:17:22 +04:00
switch ( r - > in . level ) {
case 0 :
i0 = ( struct GROUP_USERS_INFO_0 * ) r - > in . buffer ;
break ;
case 1 :
i1 = ( struct GROUP_USERS_INFO_1 * ) r - > in . buffer ;
break ;
}
2008-09-12 13:13:20 +04:00
lsa_names = talloc_array ( ctx , struct lsa_String , r - > in . num_entries ) ;
if ( ! lsa_names ) {
werr = WERR_NOMEM ;
goto done ;
}
2008-09-09 15:17:22 +04:00
for ( i = 0 ; i < r - > in . num_entries ; i + + ) {
switch ( r - > in . level ) {
case 0 :
2008-09-12 13:13:20 +04:00
init_lsa_String ( & lsa_names [ i ] , i0 - > grui0_name ) ;
2008-09-09 15:17:22 +04:00
i0 + + ;
break ;
case 1 :
2008-09-12 13:13:20 +04:00
init_lsa_String ( & lsa_names [ i ] , i1 - > grui1_name ) ;
2008-09-09 15:17:22 +04:00
i1 + + ;
break ;
}
2008-09-12 13:13:20 +04:00
}
2008-09-09 15:17:22 +04:00
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_LookupNames ( b , talloc_tos ( ) ,
2008-09-12 13:13:20 +04:00
& domain_handle ,
r - > in . num_entries ,
lsa_names ,
& user_rids ,
2011-01-14 17:49:37 +03:00
& name_types ,
& result ) ;
2008-09-12 13:13:20 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
2008-09-09 15:17:22 +04:00
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-09-09 15:17:22 +04:00
2013-11-08 09:40:55 +04:00
if ( r - > in . num_entries ! = user_rids . count ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
if ( r - > in . num_entries ! = name_types . count ) {
werr = WERR_BAD_NET_RESP ;
goto done ;
}
2008-09-12 13:13:20 +04:00
member_rids = user_rids . ids ;
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_QueryGroupMember ( b , talloc_tos ( ) ,
2008-09-09 15:17:22 +04:00
& group_handle ,
2011-01-14 17:49:37 +03:00
& rid_array ,
& result ) ;
2008-09-09 15:17:22 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-09-09 15:17:22 +04:00
/* add list */
for ( i = 0 ; i < r - > in . num_entries ; i + + ) {
bool already_member = false ;
for ( k = 0 ; k < rid_array - > count ; k + + ) {
if ( member_rids [ i ] = = rid_array - > rids [ k ] ) {
already_member = true ;
break ;
}
}
if ( ! already_member ) {
if ( ! add_rid_to_array_unique ( ctx ,
member_rids [ i ] ,
& add_rids , & num_add_rids ) ) {
werr = WERR_GENERAL_FAILURE ;
goto done ;
}
}
}
/* del list */
for ( k = 0 ; k < rid_array - > count ; k + + ) {
bool keep_member = false ;
for ( i = 0 ; i < r - > in . num_entries ; i + + ) {
if ( member_rids [ i ] = = rid_array - > rids [ k ] ) {
keep_member = true ;
break ;
}
}
if ( ! keep_member ) {
if ( ! add_rid_to_array_unique ( ctx ,
rid_array - > rids [ k ] ,
& del_rids , & num_del_rids ) ) {
werr = WERR_GENERAL_FAILURE ;
goto done ;
}
}
}
/* add list */
for ( i = 0 ; i < num_add_rids ; i + + ) {
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_AddGroupMember ( b , talloc_tos ( ) ,
2008-09-09 15:17:22 +04:00
& group_handle ,
add_rids [ i ] ,
2011-01-14 17:49:37 +03:00
7 /* ? */ ,
& result ) ;
2008-09-09 15:17:22 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-09-09 15:17:22 +04:00
}
/* del list */
for ( i = 0 ; i < num_del_rids ; i + + ) {
2011-01-14 17:49:37 +03:00
status = dcerpc_samr_DeleteGroupMember ( b , talloc_tos ( ) ,
2008-09-09 15:17:22 +04:00
& group_handle ,
2011-01-14 17:49:37 +03:00
del_rids [ i ] ,
& result ) ;
2008-09-09 15:17:22 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 17:49:37 +03:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-09-09 15:17:22 +04:00
}
werr = WERR_OK ;
done :
if ( is_valid_policy_hnd ( & group_handle ) ) {
2011-01-14 17:49:37 +03:00
dcerpc_samr_Close ( b , talloc_tos ( ) , & group_handle , & result ) ;
2008-09-09 15:17:22 +04:00
}
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-09-08 12:21:17 +04:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetGroupSetUsers_l ( struct libnetapi_ctx * ctx ,
struct NetGroupSetUsers * r )
{
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetGroupSetUsers ) ;
}