| 1 | /*
|
|---|
| 2 | Samba Unix/Linux SMB client library
|
|---|
| 3 | Distributed SMB/CIFS Server Management Utility
|
|---|
| 4 | Copyright (C) Gerald (Jerry) Carter 2004
|
|---|
| 5 | Copyright (C) Guenther Deschner 2008
|
|---|
| 6 |
|
|---|
| 7 | This program is free software; you can redistribute it and/or modify
|
|---|
| 8 | it under the terms of the GNU General Public License as published by
|
|---|
| 9 | the Free Software Foundation; either version 3 of the License, or
|
|---|
| 10 | (at your option) any later version.
|
|---|
| 11 |
|
|---|
| 12 | This program is distributed in the hope that it will be useful,
|
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 15 | GNU General Public License for more details.
|
|---|
| 16 |
|
|---|
| 17 | You should have received a copy of the GNU General Public License
|
|---|
| 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|---|
| 19 |
|
|---|
| 20 | #include "includes.h"
|
|---|
| 21 | #include "utils/net.h"
|
|---|
| 22 |
|
|---|
| 23 | /********************************************************************
|
|---|
| 24 | ********************************************************************/
|
|---|
| 25 |
|
|---|
| 26 | static NTSTATUS sid_to_name(struct rpc_pipe_client *pipe_hnd,
|
|---|
| 27 | TALLOC_CTX *mem_ctx,
|
|---|
| 28 | DOM_SID *sid,
|
|---|
| 29 | fstring name)
|
|---|
| 30 | {
|
|---|
| 31 | POLICY_HND pol;
|
|---|
| 32 | enum lsa_SidType *sid_types = NULL;
|
|---|
| 33 | NTSTATUS result;
|
|---|
| 34 | char **domains = NULL, **names = NULL;
|
|---|
| 35 |
|
|---|
| 36 | result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, True,
|
|---|
| 37 | SEC_RIGHTS_MAXIMUM_ALLOWED, &pol);
|
|---|
| 38 |
|
|---|
| 39 | if ( !NT_STATUS_IS_OK(result) )
|
|---|
| 40 | return result;
|
|---|
| 41 |
|
|---|
| 42 | result = rpccli_lsa_lookup_sids(pipe_hnd, mem_ctx, &pol, 1, sid, &domains, &names, &sid_types);
|
|---|
| 43 |
|
|---|
| 44 | if ( NT_STATUS_IS_OK(result) ) {
|
|---|
| 45 | if ( *domains[0] )
|
|---|
| 46 | fstr_sprintf( name, "%s\\%s", domains[0], names[0] );
|
|---|
| 47 | else
|
|---|
| 48 | fstrcpy( name, names[0] );
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | rpccli_lsa_Close(pipe_hnd, mem_ctx, &pol);
|
|---|
| 52 | return result;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | /********************************************************************
|
|---|
| 56 | ********************************************************************/
|
|---|
| 57 |
|
|---|
| 58 | static NTSTATUS name_to_sid(struct rpc_pipe_client *pipe_hnd,
|
|---|
| 59 | TALLOC_CTX *mem_ctx,
|
|---|
| 60 | DOM_SID *sid, const char *name)
|
|---|
| 61 | {
|
|---|
| 62 | POLICY_HND pol;
|
|---|
| 63 | enum lsa_SidType *sid_types;
|
|---|
| 64 | NTSTATUS result;
|
|---|
| 65 | DOM_SID *sids;
|
|---|
| 66 |
|
|---|
| 67 | /* maybe its a raw SID */
|
|---|
| 68 | if ( strncmp(name, "S-", 2) == 0 && string_to_sid(sid, name) ) {
|
|---|
| 69 | return NT_STATUS_OK;
|
|---|
| 70 | }
|
|---|
|
|---|