2008-06-02 17:34:53 +02:00
/*
* Unix SMB / CIFS implementation .
* NetApi LocalGroup 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 14:32:16 +02:00
# include "rpc_client/rpc_client.h"
2011-01-14 16:11:19 +01:00
# include "../librpc/gen_ndr/ndr_samr_c.h"
2011-01-18 14:48:58 +01:00
# include "../librpc/gen_ndr/ndr_lsa_c.h"
2010-05-18 18:26:16 +02:00
# include "rpc_client/cli_lsarpc.h"
2010-08-19 23:15:22 +02:00
# include "rpc_client/init_lsa.h"
2010-10-12 15:27:50 +11:00
# include "../libcli/security/security.h"
2008-06-02 17:34:53 +02:00
2008-08-11 20:39:14 +02:00
static NTSTATUS libnetapi_samr_lookup_and_open_alias ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * pipe_cli ,
struct policy_handle * domain_handle ,
const char * group_name ,
uint32_t access_rights ,
struct policy_handle * alias_handle )
2008-06-03 00:41:36 +02:00
{
2011-01-14 16:11:19 +01:00
NTSTATUS status , result ;
2008-07-18 16:24:02 +02:00
struct lsa_String lsa_account_name ;
2008-06-03 00:41:36 +02:00
struct samr_Ids user_rids , name_types ;
2011-01-14 16:11:19 +01:00
struct dcerpc_binding_handle * b = pipe_cli - > binding_handle ;
2008-06-03 00:41:36 +02:00
2008-07-18 16:24:02 +02:00
init_lsa_String ( & lsa_account_name , group_name ) ;
2011-01-14 16:11:19 +01:00
status = dcerpc_samr_LookupNames ( b , mem_ctx ,
2008-06-03 00:41:36 +02:00
domain_handle ,
1 ,
2008-07-18 16:24:02 +02:00
& lsa_account_name ,
2008-06-03 00:41:36 +02:00
& user_rids ,
2011-01-14 16:11:19 +01:00
& name_types ,
& result ) ;
2008-06-03 00:41:36 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2008-08-11 20:39:14 +02:00
return status ;
2008-06-03 00:41:36 +02:00
}
2011-01-14 16:11:19 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
return result ;
}
2013-11-07 21:40:55 -08:00
if ( user_rids . count ! = 1 ) {
return NT_STATUS_INVALID_NETWORK_RESPONSE ;
}
if ( name_types . count ! = 1 ) {
return NT_STATUS_INVALID_NETWORK_RESPONSE ;
}
2008-06-03 00:41:36 +02:00
switch ( name_types . ids [ 0 ] ) {
case SID_NAME_ALIAS :
case SID_NAME_WKN_GRP :
break ;
default :
2008-08-11 20:39:14 +02:00
return NT_STATUS_INVALID_SID ;
2008-06-03 00:41:36 +02:00
}
2011-01-14 16:11:19 +01:00
status = dcerpc_samr_OpenAlias ( b , mem_ctx ,
domain_handle ,
access_rights ,
user_rids . ids [ 0 ] ,
alias_handle ,
& result ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
return result ;
2008-06-03 00:41:36 +02:00
}
2008-06-02 17:34:53 +02:00
/****************************************************************
2008-07-18 15:01:21 +02:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static NTSTATUS libnetapi_samr_open_alias_queryinfo ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * pipe_cli ,
struct policy_handle * handle ,
uint32_t rid ,
uint32_t access_rights ,
enum samr_AliasInfoEnum level ,
union samr_AliasInfo * * alias_info )
{
2011-01-14 16:11:19 +01:00
NTSTATUS status , result ;
2008-07-18 15:01:21 +02:00
struct policy_handle alias_handle ;
union samr_AliasInfo * _alias_info = NULL ;
2011-01-14 16:11:19 +01:00
struct dcerpc_binding_handle * b = pipe_cli - > binding_handle ;
2008-07-18 15:01:21 +02:00
ZERO_STRUCT ( alias_handle ) ;
2011-01-14 16:11:19 +01:00
status = dcerpc_samr_OpenAlias ( b , mem_ctx ,
2008-07-18 15:01:21 +02:00
handle ,
access_rights ,
rid ,
2011-01-14 16:11:19 +01:00
& alias_handle ,
& result ) ;
2008-07-18 15:01:21 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
2011-01-14 16:11:19 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2008-07-18 15:01:21 +02:00
2011-01-14 16:11:19 +01:00
status = dcerpc_samr_QueryAliasInfo ( b , mem_ctx ,
2008-07-18 15:01:21 +02:00
& alias_handle ,
level ,
2011-01-14 16:11:19 +01:00
& _alias_info ,
& result ) ;
2008-07-18 15:01:21 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto done ;
}
2011-01-14 16:11:19 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
status = result ;
goto done ;
}
2008-07-18 15:01:21 +02:00
* alias_info = _alias_info ;
done :
if ( is_valid_policy_hnd ( & alias_handle ) ) {
2011-01-14 16:11:19 +01:00
dcerpc_samr_Close ( b , mem_ctx , & alias_handle , & result ) ;
2008-07-18 15:01:21 +02:00
}
return status ;
}
/****************************************************************
2008-06-02 17:34:53 +02:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetLocalGroupAdd_r ( struct libnetapi_ctx * ctx ,
struct NetLocalGroupAdd * r )
{
2008-06-02 19:02:52 +02:00
struct rpc_pipe_client * pipe_cli = NULL ;
2011-01-14 16:11:19 +01:00
NTSTATUS status , result ;
2008-06-02 19:02:52 +02:00
WERROR werr ;
struct lsa_String lsa_account_name ;
struct policy_handle connect_handle , domain_handle , builtin_handle , alias_handle ;
struct dom_sid2 * domain_sid = NULL ;
uint32_t rid ;
2011-01-14 16:11:19 +01:00
struct dcerpc_binding_handle * b = NULL ;
2008-06-02 19:02:52 +02:00
2008-06-03 01:37:55 +02:00
struct LOCALGROUP_INFO_0 * info0 = NULL ;
struct LOCALGROUP_INFO_1 * info1 = NULL ;
2008-06-02 19:02:52 +02:00
const char * alias_name = NULL ;
2008-07-18 23:33:08 +02:00
if ( ! r - > in . buffer ) {
2008-06-02 19:02:52 +02:00
return WERR_INVALID_PARAM ;
}
2012-12-10 13:24:46 +01:00
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( builtin_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
ZERO_STRUCT ( alias_handle ) ;
2008-06-02 19:02:52 +02:00
switch ( r - > in . level ) {
case 0 :
2008-07-18 23:33:08 +02:00
info0 = ( struct LOCALGROUP_INFO_0 * ) r - > in . buffer ;
2008-06-02 19:02:52 +02:00
alias_name = info0 - > lgrpi0_name ;
break ;
case 1 :
2008-07-18 23:33:08 +02:00
info1 = ( struct LOCALGROUP_INFO_1 * ) r - > in . buffer ;
2008-06-02 19:02:52 +02:00
alias_name = info1 - > lgrpi1_name ;
break ;
default :
werr = WERR_UNKNOWN_LEVEL ;
goto done ;
}
2008-08-12 17:59:23 +02:00
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 16:10:13 +02:00
& ndr_table_samr ,
2008-07-20 17:59:30 +02:00
& pipe_cli ) ;
2008-06-02 19:02:52 +02:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2011-01-14 16:11:19 +01:00
b = pipe_cli - > binding_handle ;
2008-06-03 00:13:59 +02:00
werr = libnetapi_samr_open_builtin_domain ( ctx , pipe_cli ,
2009-04-15 15:40:00 -07:00
SAMR_ACCESS_LOOKUP_DOMAIN |
2008-06-03 00:13:59 +02:00
SAMR_ACCESS_ENUM_DOMAINS ,
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& builtin_handle ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-06-02 19:02:52 +02:00
goto done ;
}
2008-08-11 20:39:14 +02:00
status = libnetapi_samr_lookup_and_open_alias ( ctx , pipe_cli ,
& builtin_handle ,
alias_name ,
SAMR_ALIAS_ACCESS_LOOKUP_INFO ,
& alias_handle ) ;
2008-07-17 22:44:24 +02:00
if ( ctx - > disable_policy_handle_cache ) {
libnetapi_samr_close_builtin_handle ( ctx , & builtin_handle ) ;
}
2008-06-02 19:02:52 +02:00
2008-08-11 20:39:14 +02:00
if ( NT_STATUS_IS_OK ( status ) ) {
2008-06-03 00:42:00 +02:00
werr = WERR_ALIAS_EXISTS ;
goto done ;
}
2008-06-02 23:55:45 +02:00
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
2009-04-15 15:40:00 -07:00
SAMR_ACCESS_LOOKUP_DOMAIN ,
2008-06-02 23:55:45 +02:00
SAMR_DOMAIN_ACCESS_CREATE_ALIAS |
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-06-02 19:02:52 +02:00
goto done ;
}
2008-07-18 20:10:37 +02:00
init_lsa_String ( & lsa_account_name , alias_name ) ;
2011-01-14 16:11:19 +01:00
status = dcerpc_samr_CreateDomAlias ( b , talloc_tos ( ) ,
2008-06-02 19:02:52 +02:00
& domain_handle ,
& lsa_account_name ,
SEC_STD_DELETE |
SAMR_ALIAS_ACCESS_SET_INFO ,
& alias_handle ,
2011-01-14 16:11:19 +01:00
& rid ,
& result ) ;
2008-06-02 19:02:52 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 16:11:19 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-06-02 19:02:52 +02:00
2008-07-31 15:11:20 +02:00
if ( r - > in . level = = 1 & & info1 - > lgrpi1_comment ) {
2008-06-02 19:02:52 +02:00
union samr_AliasInfo alias_info ;
init_lsa_String ( & alias_info . description , info1 - > lgrpi1_comment ) ;
2011-01-14 16:11:19 +01:00
status = dcerpc_samr_SetAliasInfo ( b , talloc_tos ( ) ,
2008-06-02 19:02:52 +02:00
& alias_handle ,
ALIASINFODESCRIPTION ,
2011-01-14 16:11:19 +01:00
& alias_info ,
& result ) ;
2008-06-02 19:02:52 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 16:11:19 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-06-02 19:02:52 +02:00
}
werr = WERR_OK ;
done :
if ( is_valid_policy_hnd ( & alias_handle ) ) {
2011-01-14 16:11:19 +01:00
dcerpc_samr_Close ( b , talloc_tos ( ) , & alias_handle , & result ) ;
2008-06-02 19:02:52 +02:00
}
2008-07-17 22:44:24 +02:00
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 ) ;
2008-06-02 19:02:52 +02:00
}
return werr ;
2008-06-02 17:34:53 +02:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetLocalGroupAdd_l ( struct libnetapi_ctx * ctx ,
struct NetLocalGroupAdd * r )
{
2008-08-12 15:25:06 +02:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetLocalGroupAdd ) ;
2008-06-02 17:34:53 +02:00
}
2008-06-02 19:20:25 +02:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetLocalGroupDel_r ( struct libnetapi_ctx * ctx ,
struct NetLocalGroupDel * r )
{
2008-06-02 19:44:32 +02:00
struct rpc_pipe_client * pipe_cli = NULL ;
2011-01-14 16:11:19 +01:00
NTSTATUS status , result ;
2008-06-02 19:44:32 +02:00
WERROR werr ;
struct policy_handle connect_handle , domain_handle , builtin_handle , alias_handle ;
struct dom_sid2 * domain_sid = NULL ;
2011-01-14 16:11:19 +01:00
struct dcerpc_binding_handle * b = NULL ;
2008-06-02 19:44:32 +02:00
if ( ! r - > in . group_name ) {
return WERR_INVALID_PARAM ;
}
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( builtin_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
ZERO_STRUCT ( alias_handle ) ;
2008-08-12 17:59:23 +02:00
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 16:10:13 +02:00
& ndr_table_samr ,
2008-07-20 17:59:30 +02:00
& pipe_cli ) ;
2008-06-02 19:44:32 +02:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2011-01-14 16:11:19 +01:00
b = pipe_cli - > binding_handle ;
2008-06-03 00:13:59 +02:00
werr = libnetapi_samr_open_builtin_domain ( ctx , pipe_cli ,
2009-04-15 15:40:00 -07:00
SAMR_ACCESS_LOOKUP_DOMAIN |
2008-06-03 00:13:59 +02:00
SAMR_ACCESS_ENUM_DOMAINS ,
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& builtin_handle ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-06-02 19:44:32 +02:00
goto done ;
}
2008-08-11 20:39:14 +02:00
status = libnetapi_samr_lookup_and_open_alias ( ctx , pipe_cli ,
& builtin_handle ,
r - > in . group_name ,
SEC_STD_DELETE ,
& alias_handle ) ;
2008-06-02 19:44:32 +02:00
2008-07-17 22:44:24 +02:00
if ( ctx - > disable_policy_handle_cache ) {
libnetapi_samr_close_builtin_handle ( ctx , & builtin_handle ) ;
}
2008-06-02 19:44:32 +02:00
2008-08-11 20:39:14 +02:00
if ( NT_STATUS_IS_OK ( status ) ) {
2008-06-03 00:42:00 +02:00
goto delete_alias ;
}
2008-06-02 23:55:45 +02:00
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
2009-04-15 15:40:00 -07:00
SAMR_ACCESS_LOOKUP_DOMAIN ,
2008-06-02 23:55:45 +02:00
SAMR_DOMAIN_ACCESS_CREATE_ALIAS |
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-06-02 19:44:32 +02:00
goto done ;
}
2008-08-11 20:39:14 +02:00
status = libnetapi_samr_lookup_and_open_alias ( ctx , pipe_cli ,
& domain_handle ,
r - > in . group_name ,
SEC_STD_DELETE ,
& alias_handle ) ;
2008-06-02 19:44:32 +02:00
2008-07-17 22:44:24 +02:00
if ( ctx - > disable_policy_handle_cache ) {
libnetapi_samr_close_domain_handle ( ctx , & domain_handle ) ;
}
2008-06-03 00:42:00 +02:00
2008-08-11 20:39:14 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
2008-06-02 19:44:32 +02:00
goto done ;
}
delete_alias :
2011-01-14 16:11:19 +01:00
status = dcerpc_samr_DeleteDomAlias ( b , talloc_tos ( ) ,
& alias_handle ,
& result ) ;
2008-06-02 19:44:32 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 16:11:19 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-06-02 19:44:32 +02:00
ZERO_STRUCT ( alias_handle ) ;
werr = WERR_OK ;
done :
if ( is_valid_policy_hnd ( & alias_handle ) ) {
2011-01-14 16:11:19 +01:00
dcerpc_samr_Close ( b , talloc_tos ( ) , & alias_handle , & result ) ;
2008-06-02 19:44:32 +02:00
}
2008-07-17 22:44:24 +02:00
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 ) ;
2008-06-02 19:44:32 +02:00
}
return werr ;
2008-06-02 19:20:25 +02:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetLocalGroupDel_l ( struct libnetapi_ctx * ctx ,
struct NetLocalGroupDel * r )
{
2008-08-12 15:25:06 +02:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetLocalGroupDel ) ;
2008-06-02 19:20:25 +02:00
}
2008-06-02 20:20:27 +02:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-06-02 22:20:14 +02:00
static WERROR map_alias_info_to_buffer ( TALLOC_CTX * mem_ctx ,
2008-07-18 15:10:43 +02:00
const char * alias_name ,
2008-06-02 22:20:14 +02:00
struct samr_AliasInfoAll * info ,
uint32_t level ,
2008-07-18 15:10:43 +02:00
uint32_t * entries_read ,
2008-06-02 22:20:14 +02:00
uint8_t * * buffer )
{
struct LOCALGROUP_INFO_0 g0 ;
struct LOCALGROUP_INFO_1 g1 ;
struct LOCALGROUP_INFO_1002 g1002 ;
switch ( level ) {
case 0 :
2008-07-18 15:10:43 +02:00
g0 . lgrpi0_name = talloc_strdup ( mem_ctx , alias_name ) ;
W_ERROR_HAVE_NO_MEMORY ( g0 . lgrpi0_name ) ;
2008-06-02 22:20:14 +02:00
2008-07-18 15:10:43 +02:00
ADD_TO_ARRAY ( mem_ctx , struct LOCALGROUP_INFO_0 , g0 ,
( struct LOCALGROUP_INFO_0 * * ) buffer , entries_read ) ;
2008-06-02 22:20:14 +02:00
break ;
case 1 :
2008-07-18 15:10:43 +02:00
g1 . lgrpi1_name = talloc_strdup ( mem_ctx , alias_name ) ;
g1 . lgrpi1_comment = talloc_strdup ( mem_ctx , info - > description . string ) ;
W_ERROR_HAVE_NO_MEMORY ( g1 . lgrpi1_name ) ;
2008-06-02 22:20:14 +02:00
2008-07-18 15:10:43 +02:00
ADD_TO_ARRAY ( mem_ctx , struct LOCALGROUP_INFO_1 , g1 ,
( struct LOCALGROUP_INFO_1 * * ) buffer , entries_read ) ;
2008-06-02 22:20:14 +02:00
break ;
case 1002 :
2008-07-18 15:10:43 +02:00
g1002 . lgrpi1002_comment = talloc_strdup ( mem_ctx , info - > description . string ) ;
2008-06-02 22:20:14 +02:00
2008-07-18 15:10:43 +02:00
ADD_TO_ARRAY ( mem_ctx , struct LOCALGROUP_INFO_1002 , g1002 ,
( struct LOCALGROUP_INFO_1002 * * ) buffer , entries_read ) ;
2008-06-02 22:20:14 +02:00
break ;
default :
return WERR_UNKNOWN_LEVEL ;
}
return WERR_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-06-02 20:20:27 +02:00
WERROR NetLocalGroupGetInfo_r ( struct libnetapi_ctx * ctx ,
struct NetLocalGroupGetInfo * r )
{
2008-06-02 22:20:14 +02:00
struct rpc_pipe_client * pipe_cli = NULL ;
2011-01-14 16:11:19 +01:00
NTSTATUS status , result ;
2008-06-02 22:20:14 +02:00
WERROR werr ;
struct policy_handle connect_handle , domain_handle , builtin_handle , alias_handle ;
struct dom_sid2 * domain_sid = NULL ;
union samr_AliasInfo * alias_info = NULL ;
2008-07-18 15:10:43 +02:00
uint32_t entries_read = 0 ;
2011-01-14 16:11:19 +01:00
struct dcerpc_binding_handle * b = NULL ;
2008-06-02 22:20:14 +02:00
if ( ! r - > in . group_name ) {
return WERR_INVALID_PARAM ;
}
switch ( r - > in . level ) {
case 0 :
case 1 :
case 1002 :
break ;
default :
return WERR_UNKNOWN_LEVEL ;
}
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( builtin_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
ZERO_STRUCT ( alias_handle ) ;
2008-08-12 17:59:23 +02:00
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 16:10:13 +02:00
& ndr_table_samr ,
2008-07-20 17:59:30 +02:00
& pipe_cli ) ;
2008-06-02 22:20:14 +02:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2011-01-14 16:11:19 +01:00
b = pipe_cli - > binding_handle ;
2008-06-03 00:13:59 +02:00
werr = libnetapi_samr_open_builtin_domain ( ctx , pipe_cli ,
2009-04-15 15:40:00 -07:00
SAMR_ACCESS_LOOKUP_DOMAIN |
2008-06-03 00:13:59 +02:00
SAMR_ACCESS_ENUM_DOMAINS ,
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& builtin_handle ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-06-02 22:20:14 +02:00
goto done ;
}
2008-08-11 20:39:14 +02:00
status = libnetapi_samr_lookup_and_open_alias ( ctx , pipe_cli ,
& builtin_handle ,
r - > in . group_name ,
SAMR_ALIAS_ACCESS_LOOKUP_INFO ,
& alias_handle ) ;
2008-06-02 22:20:14 +02:00
2008-07-17 22:44:24 +02:00
if ( ctx - > disable_policy_handle_cache ) {
libnetapi_samr_close_builtin_handle ( ctx , & builtin_handle ) ;
}
2008-06-02 22:20:14 +02:00
2008-08-11 20:39:14 +02:00
if ( NT_STATUS_IS_OK ( status ) ) {
2008-06-03 00:42:00 +02:00
goto query_alias ;
}
2008-06-02 23:55:45 +02:00
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
2009-04-15 15:40:00 -07:00
SAMR_ACCESS_LOOKUP_DOMAIN ,
2008-06-02 23:55:45 +02:00
SAMR_DOMAIN_ACCESS_CREATE_ALIAS |
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-06-02 22:20:14 +02:00
goto done ;
}
2008-08-11 20:39:14 +02:00
status = libnetapi_samr_lookup_and_open_alias ( ctx , pipe_cli ,
& domain_handle ,
r - > in . group_name ,
SAMR_ALIAS_ACCESS_LOOKUP_INFO ,
& alias_handle ) ;
2008-06-02 22:20:14 +02:00
2008-07-17 22:44:24 +02:00
if ( ctx - > disable_policy_handle_cache ) {
libnetapi_samr_close_domain_handle ( ctx , & domain_handle ) ;
}
2008-06-03 00:42:00 +02:00
2008-08-11 20:39:14 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
2008-06-02 22:20:14 +02:00
goto done ;
}
query_alias :
2011-01-14 16:11:19 +01:00
status = dcerpc_samr_QueryAliasInfo ( b , talloc_tos ( ) ,
2008-06-02 22:20:14 +02:00
& alias_handle ,
ALIASINFOALL ,
2011-01-14 16:11:19 +01:00
& alias_info ,
& result ) ;
2008-06-02 22:20:14 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 16:11:19 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-06-02 22:20:14 +02:00
2008-07-18 15:10:43 +02:00
werr = map_alias_info_to_buffer ( ctx ,
r - > in . group_name ,
& alias_info - > all ,
r - > in . level , & entries_read ,
2008-07-18 23:33:08 +02:00
r - > out . buffer ) ;
2008-06-02 22:20:14 +02:00
done :
if ( is_valid_policy_hnd ( & alias_handle ) ) {
2011-01-14 16:11:19 +01:00
dcerpc_samr_Close ( b , talloc_tos ( ) , & alias_handle , & result ) ;
2008-06-02 22:20:14 +02:00
}
2008-07-17 22:44:24 +02:00
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 ) ;
2008-06-02 22:20:14 +02:00
}
return werr ;
2008-06-02 20:20:27 +02:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetLocalGroupGetInfo_l ( struct libnetapi_ctx * ctx ,
struct NetLocalGroupGetInfo * r )
{
2008-08-12 15:25:06 +02:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetLocalGroupGetInfo ) ;
2008-06-02 20:20:27 +02:00
}
2008-06-02 22:29:32 +02:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-06-02 23:36:25 +02:00
static WERROR map_buffer_to_alias_info ( TALLOC_CTX * mem_ctx ,
uint32_t level ,
uint8_t * buffer ,
enum samr_AliasInfoEnum * alias_level ,
union samr_AliasInfo * * alias_info )
{
struct LOCALGROUP_INFO_0 * info0 ;
struct LOCALGROUP_INFO_1 * info1 ;
struct LOCALGROUP_INFO_1002 * info1002 ;
union samr_AliasInfo * info = NULL ;
2011-06-07 11:44:43 +10:00
info = talloc_zero ( mem_ctx , union samr_AliasInfo ) ;
2008-06-02 23:36:25 +02:00
W_ERROR_HAVE_NO_MEMORY ( info ) ;
switch ( level ) {
case 0 :
info0 = ( struct LOCALGROUP_INFO_0 * ) buffer ;
init_lsa_String ( & info - > name , info0 - > lgrpi0_name ) ;
* alias_level = ALIASINFONAME ;
break ;
case 1 :
info1 = ( struct LOCALGROUP_INFO_1 * ) buffer ;
/* group name will be ignored */
init_lsa_String ( & info - > description , info1 - > lgrpi1_comment ) ;
* alias_level = ALIASINFODESCRIPTION ;
break ;
case 1002 :
info1002 = ( struct LOCALGROUP_INFO_1002 * ) buffer ;
init_lsa_String ( & info - > description , info1002 - > lgrpi1002_comment ) ;
* alias_level = ALIASINFODESCRIPTION ;
break ;
}
* alias_info = info ;
return WERR_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-06-02 22:29:32 +02:00
WERROR NetLocalGroupSetInfo_r ( struct libnetapi_ctx * ctx ,
struct NetLocalGroupSetInfo * r )
{
2008-06-02 23:36:25 +02:00
struct rpc_pipe_client * pipe_cli = NULL ;
2011-01-14 16:11:19 +01:00
NTSTATUS status , result ;
2008-06-02 23:36:25 +02:00
WERROR werr ;
struct lsa_String lsa_account_name ;
struct policy_handle connect_handle , domain_handle , builtin_handle , alias_handle ;
struct dom_sid2 * domain_sid = NULL ;
2008-06-03 01:37:55 +02:00
enum samr_AliasInfoEnum alias_level = 0 ;
2008-06-02 23:36:25 +02:00
union samr_AliasInfo * alias_info = NULL ;
2011-01-14 16:11:19 +01:00
struct dcerpc_binding_handle * b = NULL ;
2008-06-02 23:36:25 +02:00
if ( ! r - > in . group_name ) {
return WERR_INVALID_PARAM ;
}
switch ( r - > in . level ) {
case 0 :
case 1 :
case 1002 :
break ;
default :
return WERR_UNKNOWN_LEVEL ;
}
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( builtin_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
ZERO_STRUCT ( alias_handle ) ;
2008-08-12 17:59:23 +02:00
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 16:10:13 +02:00
& ndr_table_samr ,
2008-07-20 17:59:30 +02:00
& pipe_cli ) ;
2008-06-02 23:36:25 +02:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2011-01-14 16:11:19 +01:00
b = pipe_cli - > binding_handle ;
2008-06-03 00:13:59 +02:00
werr = libnetapi_samr_open_builtin_domain ( ctx , pipe_cli ,
2009-04-15 15:40:00 -07:00
SAMR_ACCESS_LOOKUP_DOMAIN |
2008-06-03 00:13:59 +02:00
SAMR_ACCESS_ENUM_DOMAINS ,
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& builtin_handle ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-06-02 23:36:25 +02:00
goto done ;
}
init_lsa_String ( & lsa_account_name , r - > in . group_name ) ;
2008-08-11 20:39:14 +02:00
status = libnetapi_samr_lookup_and_open_alias ( ctx , pipe_cli ,
& builtin_handle ,
r - > in . group_name ,
SAMR_ALIAS_ACCESS_SET_INFO ,
& alias_handle ) ;
2008-06-02 23:36:25 +02:00
2008-07-17 22:44:24 +02:00
if ( ctx - > disable_policy_handle_cache ) {
libnetapi_samr_close_builtin_handle ( ctx , & builtin_handle ) ;
}
2008-06-02 23:36:25 +02:00
2008-08-11 20:39:14 +02:00
if ( NT_STATUS_IS_OK ( status ) ) {
2008-06-03 00:42:00 +02:00
goto set_alias ;
}
2008-06-02 23:55:45 +02:00
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
2009-04-15 15:40:00 -07:00
SAMR_ACCESS_LOOKUP_DOMAIN ,
2008-06-02 23:55:45 +02:00
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2008-06-02 23:36:25 +02:00
goto done ;
}
2008-08-11 20:39:14 +02:00
status = libnetapi_samr_lookup_and_open_alias ( ctx , pipe_cli ,
& domain_handle ,
r - > in . group_name ,
SAMR_ALIAS_ACCESS_SET_INFO ,
& alias_handle ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
2008-06-02 23:36:25 +02:00
goto done ;
}
2008-07-17 22:44:24 +02:00
if ( ctx - > disable_policy_handle_cache ) {
libnetapi_samr_close_domain_handle ( ctx , & domain_handle ) ;
}
2008-06-02 23:36:25 +02:00
set_alias :
2008-07-18 23:33:08 +02:00
werr = map_buffer_to_alias_info ( ctx , r - > in . level , r - > in . buffer ,
2008-06-02 23:36:25 +02:00
& alias_level , & alias_info ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2011-01-14 16:11:19 +01:00
status = dcerpc_samr_SetAliasInfo ( b , talloc_tos ( ) ,
2008-06-02 23:36:25 +02:00
& alias_handle ,
alias_level ,
2011-01-14 16:11:19 +01:00
alias_info ,
& result ) ;
2008-06-02 23:36:25 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 16:11:19 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-06-02 23:36:25 +02:00
werr = WERR_OK ;
done :
if ( is_valid_policy_hnd ( & alias_handle ) ) {
2011-01-14 16:11:19 +01:00
dcerpc_samr_Close ( b , talloc_tos ( ) , & alias_handle , & result ) ;
2008-06-02 23:36:25 +02:00
}
2008-07-17 22:44:24 +02:00
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 ) ;
2008-06-02 23:36:25 +02:00
}
return werr ;
2008-06-02 22:29:32 +02:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetLocalGroupSetInfo_l ( struct libnetapi_ctx * ctx ,
struct NetLocalGroupSetInfo * r )
{
2008-08-12 15:25:06 +02:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetLocalGroupSetInfo ) ;
2008-06-02 22:29:32 +02:00
}
2008-07-18 01:23:26 +02:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetLocalGroupEnum_r ( struct libnetapi_ctx * ctx ,
struct NetLocalGroupEnum * r )
{
2008-07-18 15:11:08 +02:00
struct rpc_pipe_client * pipe_cli = NULL ;
2011-01-14 16:11:19 +01:00
NTSTATUS status , result ;
2008-07-18 15:11:08 +02:00
WERROR werr ;
struct policy_handle connect_handle , domain_handle , builtin_handle , alias_handle ;
struct dom_sid2 * domain_sid = NULL ;
uint32_t entries_read = 0 ;
union samr_DomainInfo * domain_info = NULL ;
union samr_DomainInfo * builtin_info = NULL ;
struct samr_SamArray * domain_sam_array = NULL ;
struct samr_SamArray * builtin_sam_array = NULL ;
int i ;
2011-01-14 16:11:19 +01:00
struct dcerpc_binding_handle * b = NULL ;
2008-07-18 15:11:08 +02:00
if ( ! r - > out . buffer ) {
return WERR_INVALID_PARAM ;
}
switch ( r - > in . level ) {
case 0 :
case 1 :
break ;
default :
return WERR_UNKNOWN_LEVEL ;
}
2008-07-18 20:10:37 +02:00
if ( r - > out . total_entries ) {
* r - > out . total_entries = 0 ;
}
if ( r - > out . entries_read ) {
* r - > out . entries_read = 0 ;
}
2008-07-18 15:11:08 +02:00
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( builtin_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
ZERO_STRUCT ( alias_handle ) ;
2008-08-12 17:59:23 +02:00
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 16:10:13 +02:00
& ndr_table_samr ,
2008-07-20 17:59:30 +02:00
& pipe_cli ) ;
2008-07-18 15:11:08 +02:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2011-01-14 16:11:19 +01:00
b = pipe_cli - > binding_handle ;
2008-07-18 15:11:08 +02:00
werr = libnetapi_samr_open_builtin_domain ( ctx , pipe_cli ,
2009-04-15 15:40:00 -07:00
SAMR_ACCESS_LOOKUP_DOMAIN |
2008-07-18 15:11:08 +02:00
SAMR_ACCESS_ENUM_DOMAINS ,
SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 |
SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS |
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& builtin_handle ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
2009-04-15 15:40:00 -07:00
SAMR_ACCESS_LOOKUP_DOMAIN |
2008-07-18 15:11:08 +02:00
SAMR_ACCESS_ENUM_DOMAINS ,
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 16:11:19 +01:00
status = dcerpc_samr_QueryDomainInfo ( b , talloc_tos ( ) ,
2008-07-18 15:11:08 +02:00
& builtin_handle ,
2 ,
2011-01-14 16:11:19 +01:00
& builtin_info ,
& result ) ;
2008-07-18 15:11:08 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 16:11:19 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-07-18 15:11:08 +02:00
2008-07-18 20:10:37 +02:00
if ( r - > out . total_entries ) {
2008-10-15 17:10:53 +02:00
* r - > out . total_entries + = builtin_info - > general . num_aliases ;
2008-07-18 20:10:37 +02:00
}
2011-01-14 16:11:19 +01:00
status = dcerpc_samr_QueryDomainInfo ( b , talloc_tos ( ) ,
2008-07-18 15:11:08 +02:00
& domain_handle ,
2 ,
2011-01-14 16:11:19 +01:00
& domain_info ,
& result ) ;
2008-07-18 15:11:08 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 16:11:19 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-07-18 15:11:08 +02:00
2008-07-18 20:10:37 +02:00
if ( r - > out . total_entries ) {
2008-10-15 17:10:53 +02:00
* r - > out . total_entries + = domain_info - > general . num_aliases ;
2008-07-18 20:10:37 +02:00
}
2011-01-14 16:11:19 +01:00
status = dcerpc_samr_EnumDomainAliases ( b , talloc_tos ( ) ,
2008-07-18 15:11:08 +02:00
& builtin_handle ,
r - > in . resume_handle ,
& builtin_sam_array ,
r - > in . prefmaxlen ,
2011-01-14 16:11:19 +01:00
& entries_read ,
& result ) ;
2008-07-18 15:11:08 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 16:11:19 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-07-18 15:11:08 +02:00
for ( i = 0 ; i < builtin_sam_array - > count ; i + + ) {
union samr_AliasInfo * alias_info = NULL ;
if ( r - > in . level = = 1 ) {
status = libnetapi_samr_open_alias_queryinfo ( ctx , pipe_cli ,
& builtin_handle ,
builtin_sam_array - > entries [ i ] . idx ,
SAMR_ALIAS_ACCESS_LOOKUP_INFO ,
ALIASINFOALL ,
& alias_info ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
}
werr = map_alias_info_to_buffer ( ctx ,
builtin_sam_array - > entries [ i ] . name . string ,
alias_info ? & alias_info - > all : NULL ,
r - > in . level ,
r - > out . entries_read ,
r - > out . buffer ) ;
}
2011-01-14 16:11:19 +01:00
status = dcerpc_samr_EnumDomainAliases ( b , talloc_tos ( ) ,
2008-07-18 15:11:08 +02:00
& domain_handle ,
r - > in . resume_handle ,
& domain_sam_array ,
r - > in . prefmaxlen ,
2011-01-14 16:11:19 +01:00
& entries_read ,
& result ) ;
2008-07-18 15:11:08 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 16:11:19 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-07-18 15:11:08 +02:00
for ( i = 0 ; i < domain_sam_array - > count ; i + + ) {
union samr_AliasInfo * alias_info = NULL ;
if ( r - > in . level = = 1 ) {
status = libnetapi_samr_open_alias_queryinfo ( ctx , pipe_cli ,
& domain_handle ,
domain_sam_array - > entries [ i ] . idx ,
SAMR_ALIAS_ACCESS_LOOKUP_INFO ,
ALIASINFOALL ,
& alias_info ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
}
werr = map_alias_info_to_buffer ( ctx ,
domain_sam_array - > entries [ i ] . name . string ,
alias_info ? & alias_info - > all : NULL ,
r - > in . level ,
r - > out . entries_read ,
r - > out . buffer ) ;
}
done :
2008-07-17 22:44:24 +02:00
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 ) ;
}
2008-07-18 15:11:08 +02:00
return werr ;
2008-07-18 01:23:26 +02:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetLocalGroupEnum_l ( struct libnetapi_ctx * ctx ,
struct NetLocalGroupEnum * r )
{
2008-08-12 15:25:06 +02:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetLocalGroupEnum ) ;
2008-07-18 01:23:26 +02:00
}
2008-07-31 16:05:11 +02:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-08-01 16:02:21 +02:00
static NTSTATUS libnetapi_lsa_lookup_names3 ( TALLOC_CTX * mem_ctx ,
struct rpc_pipe_client * lsa_pipe ,
const char * name ,
struct dom_sid * sid )
{
2011-01-18 14:48:58 +01:00
NTSTATUS status , result ;
2008-08-01 16:02:21 +02:00
struct policy_handle lsa_handle ;
2011-01-18 14:48:58 +01:00
struct dcerpc_binding_handle * b = lsa_pipe - > binding_handle ;
2008-08-01 16:02:21 +02:00
struct lsa_RefDomainList * domains = NULL ;
struct lsa_TransSidArray3 sids ;
uint32_t count = 0 ;
struct lsa_String names ;
uint32_t num_names = 1 ;
if ( ! sid | | ! name ) {
return NT_STATUS_INVALID_PARAMETER ;
}
ZERO_STRUCT ( sids ) ;
init_lsa_String ( & names , name ) ;
status = rpccli_lsa_open_policy2 ( lsa_pipe , mem_ctx ,
false ,
2010-06-03 10:36:05 +02:00
SEC_STD_READ_CONTROL |
2008-08-01 16:02:21 +02:00
LSA_POLICY_VIEW_LOCAL_INFORMATION |
LSA_POLICY_LOOKUP_NAMES ,
& lsa_handle ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
2011-01-18 14:48:58 +01:00
status = dcerpc_lsa_LookupNames3 ( b , mem_ctx ,
2008-08-01 16:02:21 +02:00
& lsa_handle ,
num_names ,
& names ,
& domains ,
& sids ,
LSA_LOOKUP_NAMES_ALL , /* sure ? */
& count ,
2011-01-18 14:48:58 +01:00
0 , 0 ,
& result ) ;
2008-08-01 16:02:21 +02:00
NT_STATUS_NOT_OK_RETURN ( status ) ;
2011-01-18 14:48:58 +01:00
NT_STATUS_NOT_OK_RETURN ( result ) ;
2008-08-01 16:02:21 +02:00
if ( count ! = 1 | | sids . count ! = 1 ) {
2013-11-07 21:40:55 -08:00
return NT_STATUS_INVALID_NETWORK_RESPONSE ;
2008-08-01 16:02:21 +02:00
}
sid_copy ( sid , sids . sids [ 0 ] . sid ) ;
return NT_STATUS_OK ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static WERROR NetLocalGroupModifyMembers_r ( struct libnetapi_ctx * ctx ,
2008-08-11 19:42:42 +02:00
struct NetLocalGroupAddMembers * add ,
2008-08-11 19:43:24 +02:00
struct NetLocalGroupDelMembers * del ,
struct NetLocalGroupSetMembers * set )
2008-08-01 16:02:21 +02:00
{
struct NetLocalGroupAddMembers * r = NULL ;
struct rpc_pipe_client * pipe_cli = NULL ;
struct rpc_pipe_client * lsa_pipe = NULL ;
2011-01-14 16:11:19 +01:00
NTSTATUS status , result ;
2008-08-01 16:02:21 +02:00
WERROR werr ;
struct lsa_String lsa_account_name ;
struct policy_handle connect_handle , domain_handle , builtin_handle , alias_handle ;
struct dom_sid2 * domain_sid = NULL ;
struct dom_sid * member_sids = NULL ;
2008-08-11 19:43:24 +02:00
int i = 0 , k = 0 ;
2008-08-01 16:02:21 +02:00
struct LOCALGROUP_MEMBERS_INFO_0 * info0 = NULL ;
struct LOCALGROUP_MEMBERS_INFO_3 * info3 = NULL ;
struct dom_sid * add_sids = NULL ;
2008-08-11 19:42:42 +02:00
struct dom_sid * del_sids = NULL ;
2010-08-26 20:54:13 +10:00
uint32_t num_add_sids = 0 ;
uint32_t num_del_sids = 0 ;
2011-01-14 16:11:19 +01:00
struct dcerpc_binding_handle * b = NULL ;
2008-08-01 16:02:21 +02:00
2008-08-11 19:43:24 +02:00
if ( ( ! add & & ! del & & ! set ) | | ( add & & del & & set ) ) {
2008-08-01 16:02:21 +02:00
return WERR_INVALID_PARAM ;
}
if ( add ) {
r = add ;
}
2008-08-11 19:42:42 +02:00
if ( del ) {
r = ( struct NetLocalGroupAddMembers * ) del ;
}
2008-08-11 19:43:24 +02:00
if ( set ) {
r = ( struct NetLocalGroupAddMembers * ) set ;
}
2008-08-01 16:02:21 +02:00
if ( ! r - > in . group_name ) {
return WERR_INVALID_PARAM ;
}
switch ( r - > in . level ) {
case 0 :
case 3 :
break ;
default :
return WERR_UNKNOWN_LEVEL ;
}
if ( r - > in . total_entries = = 0 | | ! r - > in . buffer ) {
return WERR_INVALID_PARAM ;
}
ZERO_STRUCT ( connect_handle ) ;
ZERO_STRUCT ( builtin_handle ) ;
ZERO_STRUCT ( domain_handle ) ;
ZERO_STRUCT ( alias_handle ) ;
2011-06-07 11:58:39 +10:00
member_sids = talloc_zero_array ( ctx , struct dom_sid ,
2008-08-01 16:02:21 +02:00
r - > in . total_entries ) ;
W_ERROR_HAVE_NO_MEMORY ( member_sids ) ;
switch ( r - > in . level ) {
case 0 :
info0 = ( struct LOCALGROUP_MEMBERS_INFO_0 * ) r - > in . buffer ;
for ( i = 0 ; i < r - > in . total_entries ; i + + ) {
sid_copy ( & member_sids [ i ] , ( struct dom_sid * ) info0 [ i ] . lgrmi0_sid ) ;
}
break ;
case 3 :
info3 = ( struct LOCALGROUP_MEMBERS_INFO_3 * ) r - > in . buffer ;
break ;
default :
break ;
}
if ( r - > in . level = = 3 ) {
2008-08-12 17:59:23 +02:00
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 16:10:13 +02:00
& ndr_table_lsarpc ,
2008-08-01 16:02:21 +02:00
& lsa_pipe ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
for ( i = 0 ; i < r - > in . total_entries ; i + + ) {
status = libnetapi_lsa_lookup_names3 ( ctx , lsa_pipe ,
info3 [ i ] . lgrmi3_domainandname ,
& member_sids [ i ] ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
}
TALLOC_FREE ( lsa_pipe ) ;
}
2008-08-12 17:59:23 +02:00
werr = libnetapi_open_pipe ( ctx , r - > in . server_name ,
2013-05-17 16:10:13 +02:00
& ndr_table_samr ,
2008-08-01 16:02:21 +02:00
& pipe_cli ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2011-01-14 16:11:19 +01:00
b = pipe_cli - > binding_handle ;
2008-08-01 16:02:21 +02:00
werr = libnetapi_samr_open_builtin_domain ( ctx , pipe_cli ,
2009-04-15 15:40:00 -07:00
SAMR_ACCESS_LOOKUP_DOMAIN |
2008-08-01 16:02:21 +02:00
SAMR_ACCESS_ENUM_DOMAINS ,
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& builtin_handle ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
init_lsa_String ( & lsa_account_name , r - > in . group_name ) ;
2008-08-11 20:39:14 +02:00
status = libnetapi_samr_lookup_and_open_alias ( ctx , pipe_cli ,
& builtin_handle ,
r - > in . group_name ,
SAMR_ALIAS_ACCESS_ADD_MEMBER |
SAMR_ALIAS_ACCESS_REMOVE_MEMBER |
SAMR_ALIAS_ACCESS_GET_MEMBERS |
SAMR_ALIAS_ACCESS_LOOKUP_INFO ,
& alias_handle ) ;
2008-08-01 16:02:21 +02:00
if ( ctx - > disable_policy_handle_cache ) {
libnetapi_samr_close_builtin_handle ( ctx , & builtin_handle ) ;
}
2008-08-11 20:39:14 +02:00
if ( NT_STATUS_IS_OK ( status ) ) {
2008-08-01 16:02:21 +02:00
goto modify_membership ;
}
werr = libnetapi_samr_open_domain ( ctx , pipe_cli ,
SAMR_ACCESS_ENUM_DOMAINS |
2009-04-15 15:40:00 -07:00
SAMR_ACCESS_LOOKUP_DOMAIN ,
2008-08-01 16:02:21 +02:00
SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT ,
& connect_handle ,
& domain_handle ,
& domain_sid ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2008-08-11 20:39:14 +02:00
status = libnetapi_samr_lookup_and_open_alias ( ctx , pipe_cli ,
& domain_handle ,
r - > in . group_name ,
SAMR_ALIAS_ACCESS_ADD_MEMBER |
SAMR_ALIAS_ACCESS_REMOVE_MEMBER |
SAMR_ALIAS_ACCESS_GET_MEMBERS |
SAMR_ALIAS_ACCESS_LOOKUP_INFO ,
& alias_handle ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
2008-08-01 16:02:21 +02:00
goto done ;
}
if ( ctx - > disable_policy_handle_cache ) {
libnetapi_samr_close_domain_handle ( ctx , & domain_handle ) ;
}
modify_membership :
if ( add ) {
for ( i = 0 ; i < r - > in . total_entries ; i + + ) {
status = add_sid_to_array_unique ( ctx , & member_sids [ i ] ,
& add_sids ,
& num_add_sids ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
}
}
2008-08-11 19:42:42 +02:00
if ( del ) {
for ( i = 0 ; i < r - > in . total_entries ; i + + ) {
status = add_sid_to_array_unique ( ctx , & member_sids [ i ] ,
& del_sids ,
& num_del_sids ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
}
}
2008-08-11 19:43:24 +02:00
if ( set ) {
struct lsa_SidArray current_sids ;
2011-01-14 16:11:19 +01:00
status = dcerpc_samr_GetMembersInAlias ( b , talloc_tos ( ) ,
2008-08-11 19:43:24 +02:00
& alias_handle ,
2011-01-14 16:11:19 +01:00
& current_sids ,
& result ) ;
2008-08-11 19:43:24 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 16:11:19 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-08-11 19:43:24 +02:00
/* add list */
for ( i = 0 ; i < r - > in . total_entries ; i + + ) {
bool already_member = false ;
for ( k = 0 ; k < current_sids . num_sids ; k + + ) {
2010-08-26 15:48:50 +02:00
if ( dom_sid_equal ( & member_sids [ i ] ,
2008-08-11 19:43:24 +02:00
current_sids . sids [ k ] . sid ) ) {
already_member = true ;
break ;
}
}
if ( ! already_member ) {
status = add_sid_to_array_unique ( ctx ,
& member_sids [ i ] ,
& add_sids , & num_add_sids ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
}
}
/* del list */
for ( k = 0 ; k < current_sids . num_sids ; k + + ) {
bool keep_member = false ;
for ( i = 0 ; i < r - > in . total_entries ; i + + ) {
2010-08-26 15:48:50 +02:00
if ( dom_sid_equal ( & member_sids [ i ] ,
2008-08-11 19:43:24 +02:00
current_sids . sids [ k ] . sid ) ) {
keep_member = true ;
break ;
}
}
if ( ! keep_member ) {
status = add_sid_to_array_unique ( ctx ,
current_sids . sids [ k ] . sid ,
& del_sids , & num_del_sids ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
}
}
}
2008-08-01 16:02:21 +02:00
/* add list */
for ( i = 0 ; i < num_add_sids ; i + + ) {
2011-01-14 16:11:19 +01:00
status = dcerpc_samr_AddAliasMember ( b , talloc_tos ( ) ,
2008-08-01 16:02:21 +02:00
& alias_handle ,
2011-01-14 16:11:19 +01:00
& add_sids [ i ] ,
& result ) ;
2008-08-01 16:02:21 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 16:11:19 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-08-01 16:02:21 +02:00
}
2008-08-11 19:42:42 +02:00
/* del list */
for ( i = 0 ; i < num_del_sids ; i + + ) {
2011-01-14 16:11:19 +01:00
status = dcerpc_samr_DeleteAliasMember ( b , talloc_tos ( ) ,
2008-08-11 19:42:42 +02:00
& alias_handle ,
2011-01-14 16:11:19 +01:00
& del_sids [ i ] ,
& result ) ;
2008-08-11 19:42:42 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
werr = ntstatus_to_werror ( status ) ;
goto done ;
}
2011-01-14 16:11:19 +01:00
if ( ! NT_STATUS_IS_OK ( result ) ) {
werr = ntstatus_to_werror ( result ) ;
goto done ;
}
2008-08-11 19:42:42 +02:00
}
2008-08-01 16:02:21 +02:00
werr = WERR_OK ;
done :
2011-04-27 15:41:49 +02:00
if ( b & & is_valid_policy_hnd ( & alias_handle ) ) {
2011-01-14 16:11:19 +01:00
dcerpc_samr_Close ( b , talloc_tos ( ) , & alias_handle , & result ) ;
2008-08-01 16:02:21 +02:00
}
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-31 16:05:11 +02:00
WERROR NetLocalGroupAddMembers_r ( struct libnetapi_ctx * ctx ,
struct NetLocalGroupAddMembers * r )
{
2008-08-11 19:43:24 +02:00
return NetLocalGroupModifyMembers_r ( ctx , r , NULL , NULL ) ;
2008-07-31 16:05:11 +02:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetLocalGroupAddMembers_l ( struct libnetapi_ctx * ctx ,
struct NetLocalGroupAddMembers * r )
{
2008-08-12 15:25:06 +02:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetLocalGroupAddMembers ) ;
2008-07-31 16:05:11 +02:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetLocalGroupDelMembers_r ( struct libnetapi_ctx * ctx ,
struct NetLocalGroupDelMembers * r )
{
2008-08-11 19:43:24 +02:00
return NetLocalGroupModifyMembers_r ( ctx , NULL , r , NULL ) ;
2008-07-31 16:05:11 +02:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetLocalGroupDelMembers_l ( struct libnetapi_ctx * ctx ,
struct NetLocalGroupDelMembers * r )
{
2008-08-12 15:25:06 +02:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetLocalGroupDelMembers ) ;
2008-07-31 16:05:11 +02:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetLocalGroupGetMembers_r ( struct libnetapi_ctx * ctx ,
struct NetLocalGroupGetMembers * r )
{
return WERR_NOT_SUPPORTED ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetLocalGroupGetMembers_l ( struct libnetapi_ctx * ctx ,
struct NetLocalGroupGetMembers * r )
{
2008-08-12 15:25:06 +02:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetLocalGroupGetMembers ) ;
2008-07-31 16:05:11 +02:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetLocalGroupSetMembers_r ( struct libnetapi_ctx * ctx ,
struct NetLocalGroupSetMembers * r )
{
2008-08-11 19:43:24 +02:00
return NetLocalGroupModifyMembers_r ( ctx , NULL , NULL , r ) ;
2008-07-31 16:05:11 +02:00
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WERROR NetLocalGroupSetMembers_l ( struct libnetapi_ctx * ctx ,
struct NetLocalGroupSetMembers * r )
{
2008-08-12 15:25:06 +02:00
LIBNETAPI_REDIRECT_TO_LOCALHOST ( ctx , r , NetLocalGroupSetMembers ) ;
2008-07-31 16:05:11 +02:00
}