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 "rpcclient.h"
#include "../libcli/auth/libcli_auth.h"
+#include "../librpc/gen_ndr/cli_lsa.h"
/* useful function to allow entering a name instead of a SID and
* looking it up automatically */
if (!NT_STATUS_IS_OK(result))
goto done;
-
+
result = rpccli_lsa_QueryInfoPolicy2(cli, mem_ctx,
&pol,
info_class,
if (!NT_STATUS_IS_OK(result))
goto done;
-
+
result = rpccli_lsa_QueryInfoPolicy(cli, mem_ctx,
&pol,
info_class,
struct policy_handle user_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
uint32 des_access = 0x000f000f;
-
+
DOM_SID sid;
if (argc != 2 ) {
uint8_t session_key[16])
{
char *pwd, *pwd_old;
-
+
DATA_BLOB data = data_blob_const(p->password->data, p->password->length);
DATA_BLOB data_old = data_blob_const(p->old_password->data, p->old_password->length);
DATA_BLOB session_key_blob = data_blob_const(session_key, sizeof(session_key));
pwd = sess_decrypt_string(talloc_tos(), &data, &session_key_blob);
pwd_old = sess_decrypt_string(talloc_tos(), &data_old, &session_key_blob);
-
+
d_printf("Password:\t%s\n", pwd);
d_printf("Old Password:\t%s\n", pwd_old);
return status;
}
+static NTSTATUS cmd_lsa_create_trusted_domain(struct rpc_pipe_client *cli,
+ TALLOC_CTX *mem_ctx, int argc,
+ const char **argv)
+{
+ NTSTATUS status;
+ struct policy_handle handle, trustdom_handle;
+ struct dom_sid sid;
+ struct lsa_DomainInfo info;
+
+ if (argc < 3) {
+ printf("Usage: %s name sid\n", argv[0]);
+ return NT_STATUS_OK;
+ }
+
+ status = rpccli_lsa_open_policy2(cli, mem_ctx,
+ true,
+ SEC_FLAG_MAXIMUM_ALLOWED,
+ &handle);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ init_lsa_StringLarge(&info.name, argv[1]);
+ info.sid = &sid;
+ string_to_sid(&sid, argv[2]);
+
+ status = rpccli_lsa_CreateTrustedDomain(cli, mem_ctx,
+ &handle,
+ &info,
+ SEC_FLAG_MAXIMUM_ALLOWED,
+ &trustdom_handle);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ done:
+ if (is_valid_policy_hnd(&trustdom_handle)) {
+ rpccli_lsa_Close(cli, mem_ctx, &trustdom_handle);
+ }
+
+ if (is_valid_policy_hnd(&handle)) {
+ rpccli_lsa_Close(cli, mem_ctx, &handle);
+ }
+
+ return status;
+}
+
+static NTSTATUS cmd_lsa_delete_trusted_domain(struct rpc_pipe_client *cli,
+ TALLOC_CTX *mem_ctx, int argc,
+ const char **argv)
+{
+ NTSTATUS status;
+ struct policy_handle handle, trustdom_handle;
+ struct lsa_String name;
+ struct dom_sid *sid = NULL;
+
+ if (argc < 2) {
+ printf("Usage: %s name\n", argv[0]);
+ return NT_STATUS_OK;
+ }
+
+ status = rpccli_lsa_open_policy2(cli, mem_ctx,
+ true,
+ SEC_FLAG_MAXIMUM_ALLOWED,
+ &handle);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ init_lsa_String(&name, argv[1]);
+
+ status = rpccli_lsa_OpenTrustedDomainByName(cli, mem_ctx,
+ &handle,
+ name,
+ SEC_FLAG_MAXIMUM_ALLOWED,
+ &trustdom_handle);
+ if (NT_STATUS_IS_OK(status)) {
+ goto delete_object;
+ }
+
+ {
+ uint32_t resume_handle = 0;
+ struct lsa_DomainList domains;
+ int i;
+
+ status = rpccli_lsa_EnumTrustDom(cli, mem_ctx,
+ &handle,
+ &resume_handle,
+ &domains,
+ 0xffff);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ for (i=0; i < domains.count; i++) {
+ if (strequal(domains.domains[i].name.string, argv[1])) {
+ sid = domains.domains[i].sid;
+ break;
+ }
+ }
+
+ if (!sid) {
+ return NT_STATUS_INVALID_SID;
+ }
+ }
+
+ status = rpccli_lsa_OpenTrustedDomain(cli, mem_ctx,
+ &handle,
+ sid,
+ SEC_FLAG_MAXIMUM_ALLOWED,
+ &trustdom_handle);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ delete_object:
+ status = rpccli_lsa_DeleteObject(cli, mem_ctx,
+ &trustdom_handle);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto done;
+ }
+
+ done:
+ if (is_valid_policy_hnd(&trustdom_handle)) {
+ rpccli_lsa_Close(cli, mem_ctx, &trustdom_handle);
+ }
+
+ if (is_valid_policy_hnd(&handle)) {
+ rpccli_lsa_Close(cli, mem_ctx, &handle);
+ }
+
+ return status;
+}
+
/* List of commands exported by this module */
{ "setsecret", RPC_RTYPE_NTSTATUS, cmd_lsa_set_secret, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Set Secret", "" },
{ "retrieveprivatedata", RPC_RTYPE_NTSTATUS, cmd_lsa_retrieve_private_data, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Retrieve Private Data", "" },
{ "storeprivatedata", RPC_RTYPE_NTSTATUS, cmd_lsa_store_private_data, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Store Private Data", "" },
+ { "createtrustdom", RPC_RTYPE_NTSTATUS, cmd_lsa_create_trusted_domain, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Create Trusted Domain", "" },
+ { "deletetrustdom", RPC_RTYPE_NTSTATUS, cmd_lsa_delete_trusted_domain, NULL, &ndr_table_lsarpc.syntax_id, NULL, "Delete Trusted Domain", "" },
{ NULL }
};