summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/include/sids.h39
-rw-r--r--source3/libsmb/cli_dfs.c245
-rw-r--r--source3/libsmb/cli_lsarpc.c1168
-rw-r--r--source3/libsmb/cli_netlogon.c664
-rw-r--r--source3/libsmb/cli_pipe_util.c82
-rw-r--r--source3/libsmb/cli_reg.c102
-rw-r--r--source3/libsmb/cli_samr.c1294
-rw-r--r--source3/libsmb/cli_spoolss.c2156
-rw-r--r--source3/libsmb/cli_spoolss_notify.c223
-rw-r--r--source3/libsmb/cli_srvsvc.c442
-rw-r--r--source3/libsmb/cli_wkssvc.c93
-rw-r--r--source3/nsswitch/winbindd_proto.h143
-rw-r--r--source3/passdb/passgrp.c219
-rw-r--r--source3/rpc_client/cli_login.c173
-rw-r--r--source3/rpc_client/msrpc_spoolss.c812
-rw-r--r--source3/rpc_client/ntclienttrust.c157
-rw-r--r--source3/smbd/ssl.c286
17 files changed, 0 insertions, 8298 deletions
diff --git a/source3/include/sids.h b/source3/include/sids.h
deleted file mode 100644
index 860d96b193..0000000000
--- a/source3/include/sids.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- SMB parameters and setup
- Copyright (C) Andrew Tridgell 1992-2000
- Copyright (C) Luke Kenneth Casson Leighton 1996-2000
- Copyright (C) Elrond 2000
-
- 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 2 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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#ifndef _SIDS_H
-#define _SIDS_H
-
-extern DOM_SID global_sam_sid;
-extern fstring global_sam_name;
-
-extern DOM_SID global_member_sid;
-
-extern DOM_SID global_sid_S_1_5_32; /* local well-known domain */
-extern DOM_SID global_sid_S_1_1; /* Global Domain */
-extern DOM_SID global_sid_NULL;
-
-extern const DOM_SID *global_sid_everyone;
-extern const DOM_SID *global_sid_system; /* SYSTEM */
-extern const DOM_SID *global_sid_builtin;
-
-#endif /* _SIDS_H */
diff --git a/source3/libsmb/cli_dfs.c b/source3/libsmb/cli_dfs.c
deleted file mode 100644
index 7fc27b9c3b..0000000000
--- a/source3/libsmb/cli_dfs.c
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- RPC pipe client
- Copyright (C) Tim Potter 2000-2001,
-
- 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 2 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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "includes.h"
-
-/* Query DFS support */
-
-NTSTATUS cli_dfs_exist(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- BOOL *dfs_exists)
-{
- prs_struct qbuf, rbuf;
- DFS_Q_DFS_EXIST q;
- DFS_R_DFS_EXIST r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_dfs_q_dfs_exist(&q);
-
- if (!dfs_io_q_dfs_exist("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, DFS_EXIST, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!dfs_io_r_dfs_exist("", &r, &rbuf, 0)) {
- goto done;
- }
-
- /* Return result */
-
- *dfs_exists = (r.status != 0);
-
- result = NT_STATUS_OK;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-NTSTATUS cli_dfs_add(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- char *entrypath, char *servername, char *sharename,
- char *comment, uint32 flags)
-{
- prs_struct qbuf, rbuf;
- DFS_Q_DFS_ADD q;
- DFS_R_DFS_ADD r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_dfs_q_dfs_add(&q, entrypath, servername, sharename, comment,
- flags);
-
- if (!dfs_io_q_dfs_add("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, DFS_ADD, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!dfs_io_r_dfs_add("", &r, &rbuf, 0)) {
- goto done;
- }
-
- /* Return result */
-
- result = werror_to_ntstatus(r.status);
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-NTSTATUS cli_dfs_remove(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- char *entrypath, char *servername, char *sharename)
-{
- prs_struct qbuf, rbuf;
- DFS_Q_DFS_REMOVE q;
- DFS_R_DFS_REMOVE r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_dfs_q_dfs_remove(&q, entrypath, servername, sharename);
-
- if (!dfs_io_q_dfs_remove("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, DFS_REMOVE, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!dfs_io_r_dfs_remove("", &r, &rbuf, 0)) {
- goto done;
- }
-
- /* Return result */
-
- result = werror_to_ntstatus(r.status);
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-NTSTATUS cli_dfs_get_info(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- char *entrypath, char *servername, char *sharename,
- uint32 info_level, DFS_INFO_CTR *ctr)
-
-{
- prs_struct qbuf, rbuf;
- DFS_Q_DFS_GET_INFO q;
- DFS_R_DFS_GET_INFO r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_dfs_q_dfs_get_info(&q, entrypath, servername, sharename,
- info_level);
-
- if (!dfs_io_q_dfs_get_info("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, DFS_GET_INFO, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!dfs_io_r_dfs_get_info("", &r, &rbuf, 0)) {
- goto done;
- }
-
- /* Return result */
-
- result = werror_to_ntstatus(r.status);
- *ctr = r.ctr;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Enumerate dfs shares */
-
-NTSTATUS cli_dfs_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- uint32 info_level, DFS_INFO_CTR *ctr)
-{
- prs_struct qbuf, rbuf;
- DFS_Q_DFS_ENUM q;
- DFS_R_DFS_ENUM r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_dfs_q_dfs_enum(&q, info_level, ctr);
-
- if (!dfs_io_q_dfs_enum("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, DFS_ENUM, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarshall response */
-
- r.ctr = ctr;
-
- if (!dfs_io_r_dfs_enum("", &r, &rbuf, 0)) {
- goto done;
- }
-
- /* Return result */
-
- result = werror_to_ntstatus(r.status);
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
diff --git a/source3/libsmb/cli_lsarpc.c b/source3/libsmb/cli_lsarpc.c
deleted file mode 100644
index 7dfee46fae..0000000000
--- a/source3/libsmb/cli_lsarpc.c
+++ /dev/null
@@ -1,1168 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- RPC pipe client
- Copyright (C) Tim Potter 2000-2001,
- Copyright (C) Andrew Tridgell 1992-1997,2000,
- Copyright (C) Luke Kenneth Casson Leighton 1996-1997,2000,
- Copyright (C) Paul Ashton 1997,2000,
- Copyright (C) Elrond 2000,
- Copyright (C) Rafal Szczesniak 2002
-
- 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 2 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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "includes.h"
-
-/** @defgroup lsa LSA - Local Security Architecture
- * @ingroup rpc_client
- *
- * @{
- **/
-
-/**
- * @file cli_lsarpc.c
- *
- * RPC client routines for the LSA RPC pipe. LSA means "local
- * security authority", which is half of a password database.
- **/
-
-/** Open a LSA policy handle
- *
- * @param cli Handle on an initialised SMB connection */
-
-NTSTATUS cli_lsa_open_policy(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- BOOL sec_qos, uint32 des_access, POLICY_HND *pol)
-{
- prs_struct qbuf, rbuf;
- LSA_Q_OPEN_POL q;
- LSA_R_OPEN_POL r;
- LSA_SEC_QOS qos;
- NTSTATUS result;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- if (sec_qos) {
- init_lsa_sec_qos(&qos, 2, 1, 0);
- init_q_open_pol(&q, '\\', 0, des_access, &qos);
- } else {
- init_q_open_pol(&q, '\\', 0, des_access, NULL);
- }
-
- /* Marshall data and send request */
-
- if (!lsa_io_q_open_pol("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, LSA_OPENPOLICY, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!lsa_io_r_open_pol("", &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Return output parameters */
-
- if (NT_STATUS_IS_OK(result = r.status)) {
- *pol = r.pol;
-#ifdef __INSURE__
- pol->marker = malloc(1);
-#endif
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** Open a LSA policy handle
- *
- * @param cli Handle on an initialised SMB connection
- */
-
-NTSTATUS cli_lsa_open_policy2(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- BOOL sec_qos, uint32 des_access, POLICY_HND *pol)
-{
- prs_struct qbuf, rbuf;
- LSA_Q_OPEN_POL2 q;
- LSA_R_OPEN_POL2 r;
- LSA_SEC_QOS qos;
- NTSTATUS result;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- if (sec_qos) {
- init_lsa_sec_qos(&qos, 2, 1, 0);
- init_q_open_pol2(&q, cli->srv_name_slash, 0, des_access,
- &qos);
- } else {
- init_q_open_pol2(&q, cli->srv_name_slash, 0, des_access,
- NULL);
- }
-
- /* Marshall data and send request */
-
- if (!lsa_io_q_open_pol2("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, LSA_OPENPOLICY2, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!lsa_io_r_open_pol2("", &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Return output parameters */
-
- if (NT_STATUS_IS_OK(result = r.status)) {
- *pol = r.pol;
-#ifdef __INSURE__
- pol->marker = (char *)malloc(1);
-#endif
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** Close a LSA policy handle */
-
-NTSTATUS cli_lsa_close(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *pol)
-{
- prs_struct qbuf, rbuf;
- LSA_Q_CLOSE q;
- LSA_R_CLOSE r;
- NTSTATUS result;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_lsa_q_close(&q, pol);
-
- if (!lsa_io_q_close("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, LSA_CLOSE, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!lsa_io_r_close("", &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Return output parameters */
-
- if (NT_STATUS_IS_OK(result = r.status)) {
-#ifdef __INSURE__
- SAFE_FREE(pol->marker);
-#endif
- *pol = r.pol;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** Lookup a list of sids */
-
-NTSTATUS cli_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *pol, int num_sids, DOM_SID *sids,
- char ***domains, char ***names, uint32 **types)
-{
- prs_struct qbuf, rbuf;
- LSA_Q_LOOKUP_SIDS q;
- LSA_R_LOOKUP_SIDS r;
- DOM_R_REF ref;
- LSA_TRANS_NAME_ENUM t_names;
- NTSTATUS result;
- int i;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_q_lookup_sids(mem_ctx, &q, pol, num_sids, sids, 1);
-
- if (!lsa_io_q_lookup_sids("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, LSA_LOOKUPSIDS, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- ZERO_STRUCT(ref);
- ZERO_STRUCT(t_names);
-
- r.dom_ref = &ref;
- r.names = &t_names;
-
- if (!lsa_io_r_lookup_sids("", &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- result = r.status;
-
- if (!NT_STATUS_IS_OK(result) &&
- NT_STATUS_V(result) != NT_STATUS_V(STATUS_SOME_UNMAPPED)) {
-
- /* An actual error occured */
-
- goto done;
- }
-
- /* Return output parameters */
-
- if (r.mapped_count == 0) {
- result = NT_STATUS_NONE_MAPPED;
- goto done;
- }
-
- if (!((*domains) = (char **)talloc(mem_ctx, sizeof(char *) *
- num_sids))) {
- DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- if (!((*names) = (char **)talloc(mem_ctx, sizeof(char *) *
- num_sids))) {
- DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- if (!((*types) = (uint32 *)talloc(mem_ctx, sizeof(uint32) *
- num_sids))) {
- DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- for (i = 0; i < num_sids; i++) {
- fstring name, dom_name;
- uint32 dom_idx = t_names.name[i].domain_idx;
-
- /* Translate optimised name through domain index array */
-
- if (dom_idx != 0xffffffff) {
-
- rpcstr_pull_unistr2_fstring(
- dom_name, &ref.ref_dom[dom_idx].uni_dom_name);
- rpcstr_pull_unistr2_fstring(
- name, &t_names.uni_name[i]);
-
- (*names)[i] = talloc_strdup(mem_ctx, name);
- (*domains)[i] = talloc_strdup(mem_ctx, dom_name);
- (*types)[i] = t_names.name[i].sid_name_use;
-
- if (((*names)[i] == NULL) || ((*domains)[i] == NULL)) {
- DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- } else {
- (*names)[i] = NULL;
- (*types)[i] = SID_NAME_UNKNOWN;
- }
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** Lookup a list of names */
-
-NTSTATUS cli_lsa_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *pol, int num_names,
- const char **names, DOM_SID **sids,
- uint32 **types)
-{
- prs_struct qbuf, rbuf;
- LSA_Q_LOOKUP_NAMES q;
- LSA_R_LOOKUP_NAMES r;
- DOM_R_REF ref;
- NTSTATUS result;
- int i;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_q_lookup_names(mem_ctx, &q, pol, num_names, names);
-
- if (!lsa_io_q_lookup_names("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, LSA_LOOKUPNAMES, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- ZERO_STRUCT(ref);
- r.dom_ref = &ref;
-
- if (!lsa_io_r_lookup_names("", &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- result = r.status;
-
- if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
- NT_STATUS_V(STATUS_SOME_UNMAPPED)) {
-
- /* An actual error occured */
-
- goto done;
- }
-
- /* Return output parameters */
-
- if (r.mapped_count == 0) {
- result = NT_STATUS_NONE_MAPPED;
- goto done;
- }
-
- if (!((*sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) *
- num_names)))) {
- DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- if (!((*types = (uint32 *)talloc(mem_ctx, sizeof(uint32) *
- num_names)))) {
- DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- for (i = 0; i < num_names; i++) {
- DOM_RID2 *t_rids = r.dom_rid;
- uint32 dom_idx = t_rids[i].rid_idx;
- uint32 dom_rid = t_rids[i].rid;
- DOM_SID *sid = &(*sids)[i];
-
- /* Translate optimised sid through domain index array */
-
- if (dom_idx != 0xffffffff) {
-
- sid_copy(sid, &ref.ref_dom[dom_idx].ref_dom.sid);
-
- if (dom_rid != 0xffffffff) {
- sid_append_rid(sid, dom_rid);
- }
-
- (*types)[i] = t_rids[i].type;
- } else {
- ZERO_STRUCTP(sid);
- (*types)[i] = SID_NAME_UNKNOWN;
- }
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** Query info policy
- *
- * @param domain_sid - returned remote server's domain sid */
-
-NTSTATUS cli_lsa_query_info_policy(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *pol, uint16 info_class,
- fstring domain_name, DOM_SID *domain_sid)
-{
- prs_struct qbuf, rbuf;
- LSA_Q_QUERY_INFO q;
- LSA_R_QUERY_INFO r;
- NTSTATUS result;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_q_query(&q, pol, info_class);
-
- if (!lsa_io_q_query("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, LSA_QUERYINFOPOLICY, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!lsa_io_r_query("", &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- if (!NT_STATUS_IS_OK(result = r.status)) {
- goto done;
- }
-
- /* Return output parameters */
-
- ZERO_STRUCTP(domain_sid);
- domain_name[0] = '\0';
-
- switch (info_class) {
-
- case 3:
- if (r.dom.id3.buffer_dom_name != 0) {
- unistr2_to_ascii(domain_name,
- &r.dom.id3.
- uni_domain_name,
- sizeof (fstring) - 1);
- }
-
- if (r.dom.id3.buffer_dom_sid != 0) {
- *domain_sid = r.dom.id3.dom_sid.sid;
- }
-
- break;
-
- case 5:
-
- if (r.dom.id5.buffer_dom_name != 0) {
- unistr2_to_ascii(domain_name, &r.dom.id5.
- uni_domain_name,
- sizeof (fstring) - 1);
- }
-
- if (r.dom.id5.buffer_dom_sid != 0) {
- *domain_sid = r.dom.id5.dom_sid.sid;
- }
-
- break;
-
- default:
- DEBUG(3, ("unknown info class %d\n", info_class));
- break;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/**
- * Enumerate list of trusted domains
- *
- * @param cli client state (cli_state) structure of the connection
- * @param mem_ctx memory context
- * @param pol opened lsa policy handle
- * @param enum_ctx enumeration context ie. index of first returned domain entry
- * @param pref_num_domains preferred max number of entries returned in one response
- * @param num_domains total number of trusted domains returned by response
- * @param domain_names returned trusted domain names
- * @param domain_sids returned trusted domain sids
- *
- * @return nt status code of response
- **/
-
-NTSTATUS cli_lsa_enum_trust_dom(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *pol, uint32 *enum_ctx,
- uint32 *pref_num_domains, uint32 *num_domains,
- char ***domain_names, DOM_SID **domain_sids)
-{
- prs_struct qbuf, rbuf;
- LSA_Q_ENUM_TRUST_DOM q;
- LSA_R_ENUM_TRUST_DOM r;
- NTSTATUS result;
- int i;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_q_enum_trust_dom(&q, pol, *enum_ctx, *pref_num_domains);
-
- if (!lsa_io_q_enum_trust_dom("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, LSA_ENUMTRUSTDOM, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!lsa_io_r_enum_trust_dom("", &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- result = r.status;
-
- if (!NT_STATUS_IS_OK(result) &&
- !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
- !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
-
- /* An actual error ocured */
-
- goto done;
- }
-
- /* Return output parameters */
-
- if (r.num_domains) {
-
- /* Allocate memory for trusted domain names and sids */
-
- *domain_names = (char **)talloc(mem_ctx, sizeof(char *) *
- r.num_domains);
-
- if (!*domain_names) {
- DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- *domain_sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) *
- r.num_domains);
- if (!domain_sids) {
- DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Copy across names and sids */
-
- for (i = 0; i < r.num_domains; i++) {
- fstring tmp;
-
- unistr2_to_ascii(tmp, &r.uni_domain_name[i],
- sizeof(tmp) - 1);
- (*domain_names)[i] = talloc_strdup(mem_ctx, tmp);
- sid_copy(&(*domain_sids)[i], &r.domain_sid[i].sid);
- }
- }
-
- *num_domains = r.num_domains;
- *enum_ctx = r.enum_context;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** Enumerate privileges*/
-
-NTSTATUS cli_lsa_enum_privilege(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *pol, uint32 *enum_context, uint32 pref_max_length,
- uint32 *count, char ***privs_name, uint32 **privs_high, uint32 **privs_low)
-{
- prs_struct qbuf, rbuf;
- LSA_Q_ENUM_PRIVS q;
- LSA_R_ENUM_PRIVS r;
- NTSTATUS result;
- int i;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_q_enum_privs(&q, pol, *enum_context, pref_max_length);
-
- if (!lsa_io_q_enum_privs("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, LSA_ENUM_PRIVS, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!lsa_io_r_enum_privs("", &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- if (!NT_STATUS_IS_OK(result = r.status)) {
- goto done;
- }
-
- /* Return output parameters */
-
- *enum_context = r.enum_context;
- *count = r.count;
-
- if (!((*privs_name = (char **)talloc(mem_ctx, sizeof(char *) * r.count)))) {
- DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- if (!((*privs_high = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.count)))) {
- DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- if (!((*privs_low = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.count)))) {
- DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- for (i = 0; i < r.count; i++) {
- fstring name;
-
- rpcstr_pull_unistr2_fstring( name, &r.privs[i].name);
-
- (*privs_name)[i] = talloc_strdup(mem_ctx, name);
-
- (*privs_high)[i] = r.privs[i].luid_high;
- (*privs_low)[i] = r.privs[i].luid_low;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** Get privilege name */
-
-NTSTATUS cli_lsa_get_dispname(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *pol, char *name, uint16 lang_id, uint16 lang_id_sys,
- fstring description, uint16 *lang_id_desc)
-{
- prs_struct qbuf, rbuf;
- LSA_Q_PRIV_GET_DISPNAME q;
- LSA_R_PRIV_GET_DISPNAME r;
- NTSTATUS result;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_lsa_priv_get_dispname(&q, pol, name, lang_id, lang_id_sys);
-
- if (!lsa_io_q_priv_get_dispname("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, LSA_PRIV_GET_DISPNAME, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!lsa_io_r_priv_get_dispname("", &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- if (!NT_STATUS_IS_OK(result = r.status)) {
- goto done;
- }
-
- /* Return output parameters */
-
- rpcstr_pull_unistr2_fstring(description , &r.desc);
- *lang_id_desc = r.lang_id;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** Enumerate list of SIDs */
-
-NTSTATUS cli_lsa_enum_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *pol, uint32 *enum_ctx, uint32 pref_max_length,
- uint32 *num_sids, DOM_SID **sids)
-{
- prs_struct qbuf, rbuf;
- LSA_Q_ENUM_ACCOUNTS q;
- LSA_R_ENUM_ACCOUNTS r;
- NTSTATUS result;
- int i;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_lsa_q_enum_accounts(&q, pol, *enum_ctx, pref_max_length);
-
- if (!lsa_io_q_enum_accounts("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, LSA_ENUM_ACCOUNTS, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!lsa_io_r_enum_accounts("", &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- result = r.status;
-
- if (!NT_STATUS_IS_OK(result = r.status)) {
- goto done;
- }
-
- if (r.sids.num_entries==0)
- goto done;
-
- /* Return output parameters */
-
- *sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * r.sids.num_entries);
- if (!*sids) {
- DEBUG(0, ("(cli_lsa_enum_sids): out of memory\n"));
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Copy across names and sids */
-
- for (i = 0; i < r.sids.num_entries; i++) {
- sid_copy(&(*sids)[i], &r.sids.sid[i].sid);
- }
-
- *num_sids= r.sids.num_entries;
- *enum_ctx = r.enum_context;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** Open a LSA user handle
- *
- * @param cli Handle on an initialised SMB connection */
-
-NTSTATUS cli_lsa_open_account(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *dom_pol, DOM_SID *sid, uint32 des_access,
- POLICY_HND *user_pol)
-{
- prs_struct qbuf, rbuf;
- LSA_Q_OPENACCOUNT q;
- LSA_R_OPENACCOUNT r;
- NTSTATUS result;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- init_lsa_q_open_account(&q, dom_pol, sid, des_access);
-
- /* Marshall data and send request */
-
- if (!lsa_io_q_open_account("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, LSA_OPENACCOUNT, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!lsa_io_r_open_account("", &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Return output parameters */
-
- if (NT_STATUS_IS_OK(result = r.status)) {
- *user_pol = r.pol;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** Enumerate user privileges
- *
- * @param cli Handle on an initialised SMB connection */
-
-NTSTATUS cli_lsa_enum_privsaccount(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *pol, uint32 *count, LUID_ATTR **set)
-{
- prs_struct qbuf, rbuf;
- LSA_Q_ENUMPRIVSACCOUNT q;
- LSA_R_ENUMPRIVSACCOUNT r;
- NTSTATUS result;
- int i;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- init_lsa_q_enum_privsaccount(&q, pol);
-
- /* Marshall data and send request */
-
- if (!lsa_io_q_enum_privsaccount("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, LSA_ENUMPRIVSACCOUNT, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!lsa_io_r_enum_privsaccount("", &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Return output parameters */
-
- if (!NT_STATUS_IS_OK(result = r.status)) {
- goto done;
- }
-
- if (r.count == 0)
- goto done;
-
- if (!((*set = (LUID_ATTR *)talloc(mem_ctx, sizeof(LUID_ATTR) * r.count)))) {
- DEBUG(0, ("(cli_lsa_enum_privsaccount): out of memory\n"));
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- for (i=0; i<r.count; i++) {
- (*set)[i].luid.low = r.set.set[i].luid.low;
- (*set)[i].luid.high = r.set.set[i].luid.high;
- (*set)[i].attr = r.set.set[i].attr;
- }
-
- *count=r.count;
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** Get a privilege value given its name */
-
-NTSTATUS cli_lsa_lookupprivvalue(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *pol, char *name, LUID *luid)
-{
- prs_struct qbuf, rbuf;
- LSA_Q_LOOKUPPRIVVALUE q;
- LSA_R_LOOKUPPRIVVALUE r;
- NTSTATUS result;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_lsa_q_lookupprivvalue(&q, pol, name);
-
- if (!lsa_io_q_lookupprivvalue("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, LSA_LOOKUPPRIVVALUE, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!lsa_io_r_lookupprivvalue("", &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- if (!NT_STATUS_IS_OK(result = r.status)) {
- goto done;
- }
-
- /* Return output parameters */
-
- (*luid).low=r.luid.low;
- (*luid).high=r.luid.high;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** Query LSA security object */
-
-NTSTATUS cli_lsa_query_secobj(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *pol, uint32 sec_info,
- SEC_DESC_BUF **psdb)
-{
- prs_struct qbuf, rbuf;
- LSA_Q_QUERY_SEC_OBJ q;
- LSA_R_QUERY_SEC_OBJ r;
- NTSTATUS result;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_q_query_sec_obj(&q, pol, sec_info);
-
- if (!lsa_io_q_query_sec_obj("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, LSA_QUERYSECOBJ, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!lsa_io_r_query_sec_obj("", &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- if (!NT_STATUS_IS_OK(result = r.status)) {
- goto done;
- }
-
- /* Return output parameters */
-
- if (psdb)
- *psdb = r.buf;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-#if 0
-
-/** An example of how to use the routines in this file. Fetch a DOMAIN
- sid. Does complete cli setup / teardown anonymously. */
-
-BOOL fetch_domain_sid( char *domain, char *remote_machine, DOM_SID *psid)
-{
- extern pstring global_myname;
- struct cli_state cli;
- NTSTATUS result;
- POLICY_HND lsa_pol;
- BOOL ret = False;
-
- ZERO_STRUCT(cli);
- if(cli_initialise(&cli) == False) {
- DEBUG(0,("fetch_domain_sid: unable to initialize client connection.\n"));
- return False;
- }
-
- if(!resolve_name( remote_machine, &cli.dest_ip, 0x20)) {
- DEBUG(0,("fetch_domain_sid: Can't resolve address for %s\n", remote_machine));
- goto done;
- }
-
- if (!cli_connect(&cli, remote_machine, &cli.dest_ip)) {
- DEBUG(0,("fetch_domain_sid: unable to connect to SMB server on \
-machine %s. Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
- goto done;
- }
-
- if (!attempt_netbios_session_request(&cli, global_myname, remote_machine, &cli.dest_ip)) {
- DEBUG(0,("fetch_domain_sid: machine %s rejected the NetBIOS session request.\n",
- remote_machine));
- goto done;
- }
-
- cli.protocol = PROTOCOL_NT1;
-
- if (!cli_negprot(&cli)) {
- DEBUG(0,("fetch_domain_sid: machine %s rejected the negotiate protocol. \
-Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
- goto done;
- }
-
- if (cli.protocol != PROTOCOL_NT1) {
- DEBUG(0,("fetch_domain_sid: machine %s didn't negotiate NT protocol.\n",
- remote_machine));
- goto done;
- }
-
- /*
- * Do an anonymous session setup.
- */
-
- if (!cli_session_setup(&cli, "", "", 0, "", 0, "")) {
- DEBUG(0,("fetch_domain_sid: machine %s rejected the session setup. \
-Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
- goto done;
- }
-
- if (!(cli.sec_mode & NEGOTIATE_SECURITY_USER_LEVEL)) {
- DEBUG(0,("fetch_domain_sid: machine %s isn't in user level security mode\n",
- remote_machine));
- goto done;
- }
-
- if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) {
- DEBUG(0,("fetch_domain_sid: machine %s rejected the tconX on the IPC$ share. \
-Error was : %s.\n", remote_machine, cli_errstr(&cli) ));
- goto done;
- }
-
- /* Fetch domain sid */
-
- if (!cli_nt_session_open(&cli, PIPE_LSARPC)) {
- DEBUG(0, ("fetch_domain_sid: Error connecting to SAM pipe\n"));
- goto done;
- }
-
- result = cli_lsa_open_policy(&cli, cli.mem_ctx, True, SEC_RIGHTS_QUERY_VALUE, &lsa_pol);
- if (!NT_STATUS_IS_OK(result)) {
- DEBUG(0, ("fetch_domain_sid: Error opening lsa policy handle. %s\n",
- nt_errstr(result) ));
- goto done;
- }
-
- result = cli_lsa_query_info_policy(&cli, cli.mem_ctx, &lsa_pol, 5, domain, psid);
- if (!NT_STATUS_IS_OK(result)) {
- DEBUG(0, ("fetch_domain_sid: Error querying lsa policy handle. %s\n",
- nt_errstr(result) ));
- goto done;
- }
-
- ret = True;
-
- done:
-
- cli_shutdown(&cli);
- return ret;
-}
-
-#endif
-
-/** @} **/
diff --git a/source3/libsmb/cli_netlogon.c b/source3/libsmb/cli_netlogon.c
deleted file mode 100644
index d32e0e77e4..0000000000
--- a/source3/libsmb/cli_netlogon.c
+++ /dev/null
@@ -1,664 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- NT Domain Authentication SMB / MSRPC client
- Copyright (C) Andrew Tridgell 1992-2000
- Copyright (C) Luke Kenneth Casson Leighton 1996-2000
- Copyright (C) Tim Potter 2001
- Copyright (C) Paul Ashton 1997.
- Copyright (C) Jeremy Allison 1998.
- Copyright (C) Andrew Bartlett 2001.
-
- 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 2 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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "includes.h"
-
-/* LSA Request Challenge. Sends our challenge to server, then gets
- server response. These are used to generate the credentials. */
-
-NTSTATUS new_cli_net_req_chal(struct cli_state *cli, DOM_CHAL *clnt_chal,
- DOM_CHAL *srv_chal)
-{
- prs_struct qbuf, rbuf;
- NET_Q_REQ_CHAL q;
- NET_R_REQ_CHAL r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- extern pstring global_myname;
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
-
- /* create and send a MSRPC command with api NET_REQCHAL */
-
- DEBUG(4,("new_cli_net_req_chal: LSA Request Challenge from %s to %s: %s\n",
- global_myname, cli->desthost, credstr(clnt_chal->data)));
-
- /* store the parameters */
- init_q_req_chal(&q, cli->srv_name_slash, global_myname, clnt_chal);
-
- /* Marshall data and send request */
-
- if (!net_io_q_req_chal("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, NET_REQCHAL, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarhall response */
-
- if (!net_io_r_req_chal("", &r, &rbuf, 0)) {
- goto done;
- }
-
- result = r.status;
-
- /* Return result */
-
- if (NT_STATUS_IS_OK(result)) {
- memcpy(srv_chal, r.srv_chal.data, sizeof(srv_chal->data));
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/****************************************************************************
-LSA Authenticate 2
-
-Send the client credential, receive back a server credential.
-Ensure that the server credential returned matches the session key
-encrypt of the server challenge originally received. JRA.
-****************************************************************************/
-
-NTSTATUS new_cli_net_auth2(struct cli_state *cli,
- uint16 sec_chan,
- uint32 neg_flags, DOM_CHAL *srv_chal)
-{
- prs_struct qbuf, rbuf;
- NET_Q_AUTH_2 q;
- NET_R_AUTH_2 r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- extern pstring global_myname;
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
-
- /* create and send a MSRPC command with api NET_AUTH2 */
-
- DEBUG(4,("new_cli_net_auth2: srv:%s acct:%s sc:%x mc: %s chal %s neg: %x\n",
- cli->srv_name_slash, cli->mach_acct, sec_chan, global_myname,
- credstr(cli->clnt_cred.challenge.data), neg_flags));
-
- /* store the parameters */
- init_q_auth_2(&q, cli->srv_name_slash, cli->mach_acct,
- sec_chan, global_myname, &cli->clnt_cred.challenge,
- neg_flags);
-
- /* turn parameters into data stream */
-
- if (!net_io_q_auth_2("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, NET_AUTH2, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!net_io_r_auth_2("", &r, &rbuf, 0)) {
- goto done;
- }
-
- result = r.status;
-
- if (NT_STATUS_IS_OK(result)) {
- UTIME zerotime;
-
- /*
- * Check the returned value using the initial
- * server received challenge.
- */
-
- zerotime.time = 0;
- if (cred_assert( &r.srv_chal, cli->sess_key, srv_chal,
- zerotime) == 0) {
-
- /*
- * Server replied with bad credential. Fail.
- */
- DEBUG(0,("new_cli_net_auth2: server %s replied with bad credential (bad machine \
-password ?).\n", cli->desthost ));
- result = NT_STATUS_ACCESS_DENIED;
- goto done;
- }
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Initialize domain session credentials */
-
-NTSTATUS new_cli_nt_setup_creds(struct cli_state *cli,
- uint16 sec_chan,
- const unsigned char mach_pwd[16])
-{
- DOM_CHAL clnt_chal;
- DOM_CHAL srv_chal;
- UTIME zerotime;
- NTSTATUS result;
-
- /******************* Request Challenge ********************/
-
- generate_random_buffer(clnt_chal.data, 8, False);
-
- /* send a client challenge; receive a server challenge */
- result = new_cli_net_req_chal(cli, &clnt_chal, &srv_chal);
-
- if (!NT_STATUS_IS_OK(result)) {
- DEBUG(0,("new_cli_nt_setup_creds: request challenge failed\n"));
- return result;
- }
-
- /**************** Long-term Session key **************/
-
- /* calculate the session key */
- cred_session_key(&clnt_chal, &srv_chal, mach_pwd,
- cli->sess_key);
- memset((char *)cli->sess_key+8, '\0', 8);
-
- /******************* Authenticate 2 ********************/
-
- /* calculate auth-2 credentials */
- zerotime.time = 0;
- cred_create(cli->sess_key, &clnt_chal, zerotime,
- &cli->clnt_cred.challenge);
-
- /*
- * Send client auth-2 challenge.
- * Receive an auth-2 challenge response and check it.
- */
-
- result = new_cli_net_auth2(cli, sec_chan, 0x000001ff,
- &srv_chal);
- if (!NT_STATUS_IS_OK(result)) {
- DEBUG(1,("cli_nt_setup_creds: auth2 challenge failed %s\n",
- nt_errstr(result)));
- }
-
- return result;
-}
-
-/* Logon Control 2 */
-
-NTSTATUS cli_netlogon_logon_ctrl2(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- uint32 query_level)
-{
- prs_struct qbuf, rbuf;
- NET_Q_LOGON_CTRL2 q;
- NET_R_LOGON_CTRL2 r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- init_net_q_logon_ctrl2(&q, cli->srv_name_slash, query_level);
-
- /* Marshall data and send request */
-
- if (!net_io_q_logon_ctrl2("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, NET_LOGON_CTRL2, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!net_io_r_logon_ctrl2("", &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- result = r.status;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/****************************************************************************
-Generate the next creds to use. Yuck - this is a cut&paste from another
-file. They should be combined at some stage. )-:
-****************************************************************************/
-
-static void gen_next_creds( struct cli_state *cli, DOM_CRED *new_clnt_cred)
-{
- /*
- * Create the new client credentials.
- */
-
- cli->clnt_cred.timestamp.time = time(NULL);
-
- memcpy(new_clnt_cred, &cli->clnt_cred, sizeof(*new_clnt_cred));
-
- /* Calculate the new credentials. */
- cred_create(cli->sess_key, &(cli->clnt_cred.challenge),
- new_clnt_cred->timestamp, &(new_clnt_cred->challenge));
-
-}
-
-/* Sam synchronisation */
-
-NTSTATUS cli_netlogon_sam_sync(struct cli_state *cli, TALLOC_CTX *mem_ctx, DOM_CRED *ret_creds,
- uint32 database_id, uint32 *num_deltas,
- SAM_DELTA_HDR **hdr_deltas,
- SAM_DELTA_CTR **deltas)
-{
- prs_struct qbuf, rbuf;
- NET_Q_SAM_SYNC q;
- NET_R_SAM_SYNC r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- DOM_CRED clnt_creds;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- gen_next_creds(cli, &clnt_creds);
-
- init_net_q_sam_sync(&q, cli->srv_name_slash, cli->clnt_name_slash + 2,
- &clnt_creds, ret_creds, database_id);
-
- /* Marshall data and send request */
-
- if (!net_io_q_sam_sync("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, NET_SAM_SYNC, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!net_io_r_sam_sync("", cli->sess_key, &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Return results */
-
- result = r.status;
- *num_deltas = r.num_deltas2;
- *hdr_deltas = r.hdr_deltas;
- *deltas = r.deltas;
-
- memcpy(ret_creds, &r.srv_creds, sizeof(*ret_creds));
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Sam synchronisation */
-
-NTSTATUS cli_netlogon_sam_deltas(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- uint32 database_id, UINT64_S seqnum,
- uint32 *num_deltas,
- SAM_DELTA_HDR **hdr_deltas,
- SAM_DELTA_CTR **deltas)
-{
- prs_struct qbuf, rbuf;
- NET_Q_SAM_DELTAS q;
- NET_R_SAM_DELTAS r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- DOM_CRED clnt_creds;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- gen_next_creds(cli, &clnt_creds);
-
- init_net_q_sam_deltas(&q, cli->srv_name_slash,
- cli->clnt_name_slash + 2, &clnt_creds,
- database_id, seqnum);
-
- /* Marshall data and send request */
-
- if (!net_io_q_sam_deltas("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, NET_SAM_DELTAS, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!net_io_r_sam_deltas("", cli->sess_key, &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Return results */
-
- result = r.status;
- *num_deltas = r.num_deltas2;
- *hdr_deltas = r.hdr_deltas;
- *deltas = r.deltas;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Logon domain user */
-
-NTSTATUS cli_netlogon_sam_logon(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- char *username, char *password,
- int logon_type)
-{
- prs_struct qbuf, rbuf;
- NET_Q_SAM_LOGON q;
- NET_R_SAM_LOGON r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- DOM_CRED clnt_creds, dummy_rtn_creds;
- extern pstring global_myname;
- NET_ID_INFO_CTR ctr;
- NET_USER_INFO_3 user;
- int validation_level = 3;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- gen_next_creds(cli, &clnt_creds);
-
- q.validation_level = validation_level;
-
- memset(&dummy_rtn_creds, '\0', sizeof(dummy_rtn_creds));
- dummy_rtn_creds.timestamp.time = time(NULL);
-
- ctr.switch_value = logon_type;
-
- switch (logon_type) {
- case INTERACTIVE_LOGON_TYPE: {
- unsigned char lm_owf_user_pwd[16], nt_owf_user_pwd[16];
-
- nt_lm_owf_gen(password, nt_owf_user_pwd, lm_owf_user_pwd);
-
- init_id_info1(&ctr.auth.id1, lp_workgroup(),
- 0, /* param_ctrl */
- 0xdead, 0xbeef, /* LUID? */
- username, cli->clnt_name_slash,
- cli->sess_key, lm_owf_user_pwd,
- nt_owf_user_pwd);
-
- break;
- }
- case NET_LOGON_TYPE: {
- uint8 chal[8];
- unsigned char local_lm_response[24];
- unsigned char local_nt_response[24];
-
- generate_random_buffer(chal, 8, False);
-
- SMBencrypt(password, chal, local_lm_response);
- SMBNTencrypt(password, chal, local_nt_response);
-
- init_id_info2(&ctr.auth.id2, lp_workgroup(),
- 0, /* param_ctrl */
- 0xdead, 0xbeef, /* LUID? */
- username, cli->clnt_name_slash, chal,
- local_lm_response, 24, local_nt_response, 24);
- break;
- }
- default:
- DEBUG(0, ("switch value %d not supported\n",
- ctr.switch_value));
- goto done;
- }
-
- init_sam_info(&q.sam_id, cli->srv_name_slash, global_myname,
- &clnt_creds, &dummy_rtn_creds, logon_type,
- &ctr);
-
- /* Marshall data and send request */
-
- if (!net_io_q_sam_logon("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, NET_SAMLOGON, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarshall response */
-
- r.user = &user;
-
- if (!net_io_r_sam_logon("", &r, &rbuf, 0)) {
- goto done;
- }
-
- /* Return results */
-
- result = r.status;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-
-/**
- * Logon domain user with an 'network' SAM logon
- *
- * @param info3 Pointer to a NET_USER_INFO_3 already allocated by the caller.
- **/
-
-NTSTATUS cli_netlogon_sam_network_logon(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- const char *username, const char *domain, const char *workstation,
- const uint8 chal[8],
- DATA_BLOB lm_response, DATA_BLOB nt_response,
- NET_USER_INFO_3 *info3)
-
-{
- prs_struct qbuf, rbuf;
- NET_Q_SAM_LOGON q;
- NET_R_SAM_LOGON r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- DOM_CRED clnt_creds, dummy_rtn_creds;
- NET_ID_INFO_CTR ctr;
- extern pstring global_myname;
- int validation_level = 3;
- char *workstation_name_slash;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- workstation_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", workstation);
-
- if (!workstation_name_slash) {
- DEBUG(0, ("talloc_asprintf failed!\n"));
- return NT_STATUS_NO_MEMORY;
- }
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- gen_next_creds(cli, &clnt_creds);
-
- q.validation_level = validation_level;
-
- memset(&dummy_rtn_creds, '\0', sizeof(dummy_rtn_creds));
- dummy_rtn_creds.timestamp.time = time(NULL);
-
- ctr.switch_value = NET_LOGON_TYPE;
-
- init_id_info2(&ctr.auth.id2, domain,
- 0, /* param_ctrl */
- 0xdead, 0xbeef, /* LUID? */
- username, workstation_name_slash, (const uchar*)chal,
- lm_response.data, lm_response.length, nt_response.data, nt_response.length);
-
- init_sam_info(&q.sam_id, cli->srv_name_slash, global_myname,
- &clnt_creds, &dummy_rtn_creds, NET_LOGON_TYPE,
- &ctr);
-
- /* Marshall data and send request */
-
- if (!net_io_q_sam_logon("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, NET_SAMLOGON, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarshall response */
-
- r.user = info3;
-
- if (!net_io_r_sam_logon("", &r, &rbuf, 0)) {
- goto done;
- }
-
- /* Return results */
-
- result = r.status;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/***************************************************************************
-LSA Server Password Set.
-****************************************************************************/
-
-NTSTATUS cli_net_srv_pwset(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- char* machine_name, uint8 hashed_mach_pwd[16])
-{
- prs_struct rbuf;
- prs_struct qbuf;
- DOM_CRED new_clnt_cred;
- NET_Q_SRV_PWSET q_s;
- uint16 sec_chan_type = 2;
- NTSTATUS nt_status;
- char *mach_acct;
-
- gen_next_creds( cli, &new_clnt_cred);
-
- prs_init(&qbuf , 1024, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* create and send a MSRPC command with api NET_SRV_PWSET */
-
- mach_acct = talloc_asprintf(mem_ctx, "%s$", machine_name);
-
- if (!mach_acct) {
- DEBUG(0,("talloc_asprintf failed!\n"));
- nt_status = NT_STATUS_NO_MEMORY;
- goto done;
- }
-
- DEBUG(4,("cli_net_srv_pwset: srv:%s acct:%s sc: %d mc: %s clnt %s %x\n",
- cli->srv_name_slash, mach_acct, sec_chan_type, machine_name,
- credstr(new_clnt_cred.challenge.data), new_clnt_cred.timestamp.time));
-
- /* store the parameters */
- init_q_srv_pwset(&q_s, cli->srv_name_slash, cli->sess_key,
- mach_acct, sec_chan_type, machine_name,
- &new_clnt_cred, (char *)hashed_mach_pwd);
-
- /* turn parameters into data stream */
- if(!net_io_q_srv_pwset("", &q_s, &qbuf, 0)) {
- DEBUG(0,("cli_net_srv_pwset: Error : failed to marshall NET_Q_SRV_PWSET struct.\n"));
- nt_status = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* send the data on \PIPE\ */
- if (rpc_api_pipe_req(cli, NET_SRVPWSET, &qbuf, &rbuf))
- {
- NET_R_SRV_PWSET r_s;
-
- if (!net_io_r_srv_pwset("", &r_s, &rbuf, 0)) {
- nt_status = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- nt_status = r_s.status;
-
- if (!NT_STATUS_IS_OK(r_s.status))
- {
- /* report error code */
- DEBUG(0,("cli_net_srv_pwset: %s\n", nt_errstr(nt_status)));
- goto done;
- }
-
- /* Update the credentials. */
- if (!clnt_deal_with_creds(cli->sess_key, &(cli->clnt_cred), &(r_s.srv_cred)))
- {
- /*
- * Server replied with bad credential. Fail.
- */
- DEBUG(0,("cli_net_srv_pwset: server %s replied with bad credential (bad machine \
-password ?).\n", cli->desthost ));
- nt_status = NT_STATUS_UNSUCCESSFUL;
- }
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return nt_status;
-}
-
diff --git a/source3/libsmb/cli_pipe_util.c b/source3/libsmb/cli_pipe_util.c
deleted file mode 100644
index de1c832e44..0000000000
--- a/source3/libsmb/cli_pipe_util.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- RPC pipe client utility functions
- Copyright (C) Tim Potter 2001,
-
- 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 2 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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "includes.h"
-
-/** \defgroup rpc_client RPC Client routines
- */
-
-/* Opens a SMB connection to a named pipe */
-
-struct cli_state *cli_pipe_initialise(struct cli_state *cli, char *system_name,
- char *pipe_name,
- struct ntuser_creds *creds)
-{
- struct in_addr dest_ip;
- struct nmb_name calling, called;
- fstring dest_host;
- extern pstring global_myname;
- struct ntuser_creds anon;
-
- /* Initialise cli_state information */
-
- if (!cli_initialise(cli)) {
- return NULL;
- }
-
- if (!creds) {
- ZERO_STRUCT(anon);
- anon.pwd.null_pwd = 1;
- creds = &anon;
- }
-
- cli_init_creds(cli, creds);
-
- /* Establish a SMB connection */
-
- if (!resolve_srv_name(system_name, dest_host, &dest_ip)) {
- return NULL;
- }
-
- make_nmb_name(&called, dns_to_netbios_name(dest_host), 0x20);
- make_nmb_name(&calling, dns_to_netbios_name(global_myname), 0);
-
- if (!cli_establish_connection(cli, dest_host, &dest_ip, &calling,
- &called, "IPC$", "IPC", False, True)) {
- return NULL;
- }
-
- /* Open a NT session thingy */
-
- if (!cli_nt_session_open(cli, pipe_name)) {
- cli_shutdown(cli);
- return NULL;
- }
-
- return cli;
-}
-
-/* Shut down a SMB connection to the SAMR pipe */
-
-void cli_pipe_shutdown(struct cli_state *cli)
-{
- if (cli->fd != -1) cli_ulogoff(cli);
- cli_shutdown(cli);
-}
diff --git a/source3/libsmb/cli_reg.c b/source3/libsmb/cli_reg.c
deleted file mode 100644
index aaf18882f7..0000000000
--- a/source3/libsmb/cli_reg.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- RPC Pipe client
-
- Copyright (C) Andrew Tridgell 1992-1998,
- Copyright (C) Luke Kenneth Casson Leighton 1996-1998,
- Copyright (C) Paul Ashton 1997-1998.
- Copyright (C) Jeremy Allison 1999.
- Copyright (C) Simo Sorce 2001
-
- 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 2 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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "includes.h"
-
-/* Shutdown a server */
-
-NTSTATUS cli_reg_shutdown(struct cli_state * cli, TALLOC_CTX *mem_ctx,
- const char *msg, uint32 timeout, uint16 flags)
-{
- prs_struct qbuf;
- prs_struct rbuf;
- REG_Q_SHUTDOWN q_s;
- REG_R_SHUTDOWN r_s;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- if (msg == NULL) return NT_STATUS_INVALID_PARAMETER;
-
- ZERO_STRUCT (q_s);
- ZERO_STRUCT (r_s);
-
- prs_init(&qbuf , MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_reg_q_shutdown(&q_s, msg, timeout, flags);
-
- if (!reg_io_q_shutdown("", &q_s, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, REG_SHUTDOWN, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if(reg_io_r_shutdown("", &r_s, &rbuf, 0))
- result = r_s.status;
-
-done:
- prs_mem_free(&rbuf);
- prs_mem_free(&qbuf);
-
- return result;
-}
-
-
-/* Abort a server shutdown */
-
-NTSTATUS cli_reg_abort_shutdown(struct cli_state * cli, TALLOC_CTX *mem_ctx)
-{
- prs_struct rbuf;
- prs_struct qbuf;
- REG_Q_ABORT_SHUTDOWN q_s;
- REG_R_ABORT_SHUTDOWN r_s;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT (q_s);
- ZERO_STRUCT (r_s);
-
- prs_init(&qbuf , MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_reg_q_abort_shutdown(&q_s);
-
- if (!reg_io_q_abort_shutdown("", &q_s, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, REG_ABORT_SHUTDOWN, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (reg_io_r_abort_shutdown("", &r_s, &rbuf, 0))
- result = r_s.status;
-
-done:
- prs_mem_free(&rbuf);
- prs_mem_free(&qbuf );
-
- return result;
-}
diff --git a/source3/libsmb/cli_samr.c b/source3/libsmb/cli_samr.c
deleted file mode 100644
index 91577b3325..0000000000
--- a/source3/libsmb/cli_samr.c
+++ /dev/null
@@ -1,1294 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- RPC pipe client
- Copyright (C) Tim Potter 2000-2001,
- Copyright (C) Andrew Tridgell 1992-1997,2000,
- Copyright (C) Luke Kenneth Casson Leighton 1996-1997,2000,
- Copyright (C) Paul Ashton 1997,2000,
- Copyright (C) Elrond 2000.
-
- 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 2 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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "includes.h"
-
-/* Connect to SAMR database */
-
-NTSTATUS cli_samr_connect(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- uint32 access_mask, POLICY_HND *connect_pol)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_CONNECT q;
- SAMR_R_CONNECT r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_connect(&q, cli->desthost, access_mask);
-
- if (!samr_io_q_connect("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_CONNECT, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!samr_io_r_connect("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- if (NT_STATUS_IS_OK(result = r.status)) {
- *connect_pol = r.connect_pol;
-#ifdef __INSURE__
- connect_pol->marker = malloc(1);
-#endif
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Close SAMR handle */
-
-NTSTATUS cli_samr_close(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *connect_pol)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_CLOSE_HND q;
- SAMR_R_CLOSE_HND r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_close_hnd(&q, connect_pol);
-
- if (!samr_io_q_close_hnd("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_CLOSE_HND, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!samr_io_r_close_hnd("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- if (NT_STATUS_IS_OK(result = r.status)) {
-#ifdef __INSURE__
- SAFE_FREE(connect_pol->marker);
-#endif
- *connect_pol = r.pol;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Open handle on a domain */
-
-NTSTATUS cli_samr_open_domain(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *connect_pol, uint32 access_mask,
- const DOM_SID *domain_sid, POLICY_HND *domain_pol)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_OPEN_DOMAIN q;
- SAMR_R_OPEN_DOMAIN r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_open_domain(&q, connect_pol, access_mask, domain_sid);
-
- if (!samr_io_q_open_domain("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_OPEN_DOMAIN, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!samr_io_r_open_domain("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- if (NT_STATUS_IS_OK(result = r.status)) {
- *domain_pol = r.domain_pol;
-#ifdef __INSURE__
- domain_pol->marker = malloc(1);
-#endif
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Open handle on a user */
-
-NTSTATUS cli_samr_open_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *domain_pol, uint32 access_mask,
- uint32 user_rid, POLICY_HND *user_pol)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_OPEN_USER q;
- SAMR_R_OPEN_USER r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_open_user(&q, domain_pol, access_mask, user_rid);
-
- if (!samr_io_q_open_user("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_OPEN_USER, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!samr_io_r_open_user("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- if (NT_STATUS_IS_OK(result = r.status)) {
- *user_pol = r.user_pol;
-#ifdef __INSURE__
- user_pol->marker = malloc(1);
-#endif
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Open handle on a group */
-
-NTSTATUS cli_samr_open_group(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *domain_pol, uint32 access_mask,
- uint32 group_rid, POLICY_HND *group_pol)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_OPEN_GROUP q;
- SAMR_R_OPEN_GROUP r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_open_group(&q, domain_pol, access_mask, group_rid);
-
- if (!samr_io_q_open_group("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_OPEN_GROUP, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!samr_io_r_open_group("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- if (NT_STATUS_IS_OK(result = r.status)) {
- *group_pol = r.pol;
-#ifdef __INSURE__
- group_pol->marker = malloc(1);
-#endif
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Query user info */
-
-NTSTATUS cli_samr_query_userinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *user_pol, uint16 switch_value,
- SAM_USERINFO_CTR **ctr)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_QUERY_USERINFO q;
- SAMR_R_QUERY_USERINFO r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_query_userinfo(&q, user_pol, switch_value);
-
- if (!samr_io_q_query_userinfo("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_QUERY_USERINFO, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!samr_io_r_query_userinfo("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
- *ctr = r.ctr;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Query group info */
-
-NTSTATUS cli_samr_query_groupinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *group_pol, uint32 info_level,
- GROUP_INFO_CTR *ctr)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_QUERY_GROUPINFO q;
- SAMR_R_QUERY_GROUPINFO r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_query_groupinfo(&q, group_pol, info_level);
-
- if (!samr_io_q_query_groupinfo("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_QUERY_GROUPINFO, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- r.ctr = ctr;
-
- if (!samr_io_r_query_groupinfo("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Query user groups */
-
-NTSTATUS cli_samr_query_usergroups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *user_pol, uint32 *num_groups,
- DOM_GID **gid)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_QUERY_USERGROUPS q;
- SAMR_R_QUERY_USERGROUPS r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_query_usergroups(&q, user_pol);
-
- if (!samr_io_q_query_usergroups("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_QUERY_USERGROUPS, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!samr_io_r_query_usergroups("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- if (NT_STATUS_IS_OK(result = r.status)) {
- *num_groups = r.num_entries;
- *gid = r.gid;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Query user aliases */
-
-NTSTATUS cli_samr_query_useraliases(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *user_pol, uint32 num_sids, DOM_SID2 *sid,
- uint32 *num_aliases, uint32 **als_rids)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_QUERY_USERALIASES q;
- SAMR_R_QUERY_USERALIASES r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- unsigned int ptr=1;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_query_useraliases(&q, user_pol, num_sids, &ptr, sid);
-
- if (!samr_io_q_query_useraliases("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_QUERY_USERALIASES, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!samr_io_r_query_useraliases("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- if (NT_STATUS_IS_OK(result = r.status)) {
- *num_aliases = r.num_entries;
- *als_rids = r.rid;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Query user groups */
-
-NTSTATUS cli_samr_query_groupmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *group_pol, uint32 *num_mem,
- uint32 **rid, uint32 **attr)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_QUERY_GROUPMEM q;
- SAMR_R_QUERY_GROUPMEM r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_query_groupmem(&q, group_pol);
-
- if (!samr_io_q_query_groupmem("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_QUERY_GROUPMEM, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!samr_io_r_query_groupmem("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- if (NT_STATUS_IS_OK(result = r.status)) {
- *num_mem = r.num_entries;
- *rid = r.rid;
- *attr = r.attr;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Enumerate domain groups */
-
-NTSTATUS cli_samr_enum_dom_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *pol, uint32 *start_idx,
- uint32 size, struct acct_info **dom_groups,
- uint32 *num_dom_groups)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_ENUM_DOM_GROUPS q;
- SAMR_R_ENUM_DOM_GROUPS r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- uint32 name_idx, i;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_enum_dom_groups(&q, pol, *start_idx, size);
-
- if (!samr_io_q_enum_dom_groups("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_ENUM_DOM_GROUPS, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!samr_io_r_enum_dom_groups("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- if (!NT_STATUS_IS_OK(result) &&
- NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES))
- goto done;
-
- *num_dom_groups = r.num_entries2;
-
- if (!((*dom_groups) = (struct acct_info *)
- talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_groups))) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- memset(*dom_groups, 0, sizeof(struct acct_info) * *num_dom_groups);
-
- name_idx = 0;
-
- for (i = 0; i < *num_dom_groups; i++) {
-
- (*dom_groups)[i].rid = r.sam[i].rid;
-
- if (r.sam[i].hdr_name.buffer) {
- unistr2_to_ascii((*dom_groups)[i].acct_name,
- &r.uni_grp_name[name_idx],
- sizeof(fstring) - 1);
- name_idx++;
- }
-
- *start_idx = r.next_idx;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Enumerate domain groups */
-
-NTSTATUS cli_samr_enum_als_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *pol, uint32 *start_idx,
- uint32 size, struct acct_info **dom_groups,
- uint32 *num_dom_groups)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_ENUM_DOM_ALIASES q;
- SAMR_R_ENUM_DOM_ALIASES r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- uint32 name_idx, i;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_enum_dom_aliases(&q, pol, *start_idx, size);
-
- if (!samr_io_q_enum_dom_aliases("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_ENUM_DOM_ALIASES, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!samr_io_r_enum_dom_aliases("", &r, &rbuf, 0)) {
- goto done;
- }
-
- /* Return output parameters */
-
- result = r.status;
-
- if (!NT_STATUS_IS_OK(result) &&
- NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
- goto done;
- }
-
- *num_dom_groups = r.num_entries2;
-
- if (!((*dom_groups) = (struct acct_info *)
- talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_groups))) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- memset(*dom_groups, 0, sizeof(struct acct_info) * *num_dom_groups);
-
- name_idx = 0;
-
- for (i = 0; i < *num_dom_groups; i++) {
-
- (*dom_groups)[i].rid = r.sam[i].rid;
-
- if (r.sam[i].hdr_name.buffer) {
- unistr2_to_ascii((*dom_groups)[i].acct_name,
- &r.uni_grp_name[name_idx],
- sizeof(fstring) - 1);
- name_idx++;
- }
-
- *start_idx = r.next_idx;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Query alias members */
-
-NTSTATUS cli_samr_query_aliasmem(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *alias_pol, uint32 *num_mem,
- DOM_SID **sids)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_QUERY_ALIASMEM q;
- SAMR_R_QUERY_ALIASMEM r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- uint32 i;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_query_aliasmem(&q, alias_pol);
-
- if (!samr_io_q_query_aliasmem("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_QUERY_ALIASMEM, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!samr_io_r_query_aliasmem("", &r, &rbuf, 0)) {
- goto done;
- }
-
- /* Return output parameters */
-
- if (!NT_STATUS_IS_OK(result = r.status)) {
- goto done;
- }
-
- *num_mem = r.num_sids;
-
- if (!(*sids = talloc(mem_ctx, sizeof(DOM_SID) * *num_mem))) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- for (i = 0; i < *num_mem; i++) {
- (*sids)[i] = r.sid[i].sid;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Open handle on an alias */
-
-NTSTATUS cli_samr_open_alias(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *domain_pol, uint32 access_mask,
- uint32 alias_rid, POLICY_HND *alias_pol)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_OPEN_ALIAS q;
- SAMR_R_OPEN_ALIAS r;
- NTSTATUS result;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_open_alias(&q, domain_pol, access_mask, alias_rid);
-
- if (!samr_io_q_open_alias("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_OPEN_ALIAS, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!samr_io_r_open_alias("", &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Return output parameters */
-
- if (NT_STATUS_IS_OK(result = r.status)) {
- *alias_pol = r.pol;
-#ifdef __INSURE__
- alias_pol->marker = malloc(1);
-#endif
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Query domain info */
-
-NTSTATUS cli_samr_query_dom_info(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *domain_pol, uint16 switch_value,
- SAM_UNK_CTR *ctr)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_QUERY_DOMAIN_INFO q;
- SAMR_R_QUERY_DOMAIN_INFO r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_query_dom_info(&q, domain_pol, switch_value);
-
- if (!samr_io_q_query_dom_info("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_QUERY_DOMAIN_INFO, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarshall response */
-
- r.ctr = ctr;
-
- if (!samr_io_r_query_dom_info("", &r, &rbuf, 0)) {
- goto done;
- }
-
- /* Return output parameters */
-
- if (!NT_STATUS_IS_OK(result = r.status)) {
- goto done;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Query display info */
-
-NTSTATUS cli_samr_query_dispinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *domain_pol, uint32 *start_idx,
- uint16 switch_value, uint32 *num_entries,
- uint32 max_entries, SAM_DISPINFO_CTR *ctr)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_QUERY_DISPINFO q;
- SAMR_R_QUERY_DISPINFO r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_query_dispinfo(&q, domain_pol, switch_value,
- *start_idx, max_entries);
-
- if (!samr_io_q_query_dispinfo("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_QUERY_DISPINFO, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarshall response */
-
- r.ctr = ctr;
-
- if (!samr_io_r_query_dispinfo("", &r, &rbuf, 0)) {
- goto done;
- }
-
- /* Return output parameters */
-
- result = r.status;
-
- if (!NT_STATUS_IS_OK(result) &&
- NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
- goto done;
- }
-
- *num_entries = r.num_entries;
- *start_idx += r.num_entries; /* No next_idx in this structure! */
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Lookup rids. Note that NT4 seems to crash if more than ~1000 rids are
- looked up in one packet. */
-
-NTSTATUS cli_samr_lookup_rids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *domain_pol, uint32 flags,
- uint32 num_rids, uint32 *rids,
- uint32 *num_names, char ***names,
- uint32 **name_types)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_LOOKUP_RIDS q;
- SAMR_R_LOOKUP_RIDS r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- uint32 i;
-
- if (num_rids > 1000) {
- DEBUG(2, ("cli_samr_lookup_rids: warning: NT4 can crash if "
- "more than ~1000 rids are looked up at once.\n"));
- }
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_lookup_rids(mem_ctx, &q, domain_pol, flags,
- num_rids, rids);
-
- if (!samr_io_q_lookup_rids("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_LOOKUP_RIDS, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!samr_io_r_lookup_rids("", &r, &rbuf, 0)) {
- goto done;
- }
-
- /* Return output parameters */
-
- if (!NT_STATUS_IS_OK(result = r.status)) {
- goto done;
- }
-
- if (r.num_names1 == 0) {
- *num_names = 0;
- *names = NULL;
- goto done;
- }
-
- *num_names = r.num_names1;
- *names = talloc(mem_ctx, sizeof(char *) * r.num_names1);
- *name_types = talloc(mem_ctx, sizeof(uint32) * r.num_names1);
-
- for (i = 0; i < r.num_names1; i++) {
- fstring tmp;
-
- unistr2_to_ascii(tmp, &r.uni_name[i], sizeof(tmp) - 1);
- (*names)[i] = talloc_strdup(mem_ctx, tmp);
- (*name_types)[i] = r.type[i];
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Lookup names */
-
-NTSTATUS cli_samr_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *domain_pol, uint32 flags,
- uint32 num_names, const char **names,
- uint32 *num_rids, uint32 **rids,
- uint32 **rid_types)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_LOOKUP_NAMES q;
- SAMR_R_LOOKUP_NAMES r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- uint32 i;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_lookup_names(mem_ctx, &q, domain_pol, flags,
- num_names, names);
-
- if (!samr_io_q_lookup_names("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_LOOKUP_NAMES, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!samr_io_r_lookup_names("", &r, &rbuf, 0)) {
- goto done;
- }
-
- /* Return output parameters */
-
- if (!NT_STATUS_IS_OK(result = r.status)) {
- goto done;
- }
-
- if (r.num_rids1 == 0) {
- *num_rids = 0;
- goto done;
- }
-
- *num_rids = r.num_rids1;
- *rids = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
- *rid_types = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
-
- for (i = 0; i < r.num_rids1; i++) {
- (*rids)[i] = r.rids[i];
- (*rid_types)[i] = r.types[i];
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Create a domain user */
-
-NTSTATUS cli_samr_create_dom_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *domain_pol, const char *acct_name,
- uint32 acb_info, uint32 unknown,
- POLICY_HND *user_pol, uint32 *rid)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_CREATE_USER q;
- SAMR_R_CREATE_USER r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_create_user(&q, domain_pol, acct_name, acb_info, unknown);
-
- if (!samr_io_q_create_user("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_CREATE_USER, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!samr_io_r_create_user("", &r, &rbuf, 0)) {
- goto done;
- }
-
- /* Return output parameters */
-
- if (!NT_STATUS_IS_OK(result = r.status)) {
- goto done;
- }
-
- if (user_pol)
- *user_pol = r.user_pol;
-
- if (rid)
- *rid = r.user_rid;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Set userinfo */
-
-NTSTATUS cli_samr_set_userinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *user_pol, uint16 switch_value,
- uchar sess_key[16], SAM_USERINFO_CTR *ctr)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_SET_USERINFO q;
- SAMR_R_SET_USERINFO r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- q.ctr = ctr;
-
- init_samr_q_set_userinfo(&q, user_pol, sess_key, switch_value,
- ctr->info.id);
-
- if (!samr_io_q_set_userinfo("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_SET_USERINFO, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!samr_io_r_set_userinfo("", &r, &rbuf, 0)) {
- goto done;
- }
-
- /* Return output parameters */
-
- if (!NT_STATUS_IS_OK(result = r.status)) {
- goto done;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Set userinfo2 */
-
-NTSTATUS cli_samr_set_userinfo2(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *user_pol, uint16 switch_value,
- uchar sess_key[16], SAM_USERINFO_CTR *ctr)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_SET_USERINFO2 q;
- SAMR_R_SET_USERINFO2 r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_set_userinfo2(&q, user_pol, sess_key, switch_value, ctr);
-
- if (!samr_io_q_set_userinfo2("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_SET_USERINFO2, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!samr_io_r_set_userinfo2("", &r, &rbuf, 0)) {
- goto done;
- }
-
- /* Return output parameters */
-
- if (!NT_STATUS_IS_OK(result = r.status)) {
- goto done;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Delete domain user */
-
-NTSTATUS cli_samr_delete_dom_user(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *user_pol)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_DELETE_DOM_USER q;
- SAMR_R_DELETE_DOM_USER r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_delete_dom_user(&q, user_pol);
-
- if (!samr_io_q_delete_dom_user("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_DELETE_DOM_USER, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!samr_io_r_delete_dom_user("", &r, &rbuf, 0)) {
- goto done;
- }
-
- /* Return output parameters */
-
- result = r.status;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Query user security object */
-
-NTSTATUS cli_samr_query_sec_obj(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *user_pol, uint16 switch_value,
- TALLOC_CTX *ctx, SEC_DESC_BUF **sec_desc_buf)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_QUERY_SEC_OBJ q;
- SAMR_R_QUERY_SEC_OBJ r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_query_sec_obj(&q, user_pol, switch_value);
-
- if (!samr_io_q_query_sec_obj("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_QUERY_SEC_OBJECT, &qbuf, &rbuf)) {
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!samr_io_r_query_sec_obj("", &r, &rbuf, 0)) {
- goto done;
- }
-
- /* Return output parameters */
-
- result = r.status;
- *sec_desc_buf=dup_sec_desc_buf(ctx, r.buf);
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Get domain password info */
-
-NTSTATUS cli_samr_get_dom_pwinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- uint16 *unk_0, uint16 *unk_1, uint16 *unk_2)
-{
- prs_struct qbuf, rbuf;
- SAMR_Q_GET_DOM_PWINFO q;
- SAMR_R_GET_DOM_PWINFO r;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
-
- init_samr_q_get_dom_pwinfo(&q, cli->desthost);
-
- if (!samr_io_q_get_dom_pwinfo("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SAMR_GET_DOM_PWINFO, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!samr_io_r_get_dom_pwinfo("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- if (NT_STATUS_IS_OK(result)) {
- if (unk_0)
- *unk_0 = r.unk_0;
- if (unk_1)
- *unk_1 = r.unk_1;
- if (unk_2)
- *unk_2 = r.unk_2;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
diff --git a/source3/libsmb/cli_spoolss.c b/source3/libsmb/cli_spoolss.c
deleted file mode 100644
index 18e17758d6..0000000000
--- a/source3/libsmb/cli_spoolss.c
+++ /dev/null
@@ -1,2156 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- RPC pipe client
-
- Copyright (C) Gerald Carter 2001-2002,
- Copyright (C) Tim Potter 2000-2002,
- Copyright (C) Andrew Tridgell 1994-2000,
- Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
- Copyright (C) Jean-Francois Micouleau 1999-2000.
-
- 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 2 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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "includes.h"
-
-/** @defgroup spoolss SPOOLSS - NT printing routines
- * @ingroup rpc_client
- *
- * @{
- **/
-
-/**********************************************************************
- Initialize a new spoolss buff for use by a client rpc
-**********************************************************************/
-static void init_buffer(NEW_BUFFER *buffer, uint32 size, TALLOC_CTX *ctx)
-{
- buffer->ptr = (size != 0);
- buffer->size = size;
- buffer->string_at_end = size;
- prs_init(&buffer->prs, size, ctx, MARSHALL);
- buffer->struct_start = prs_offset(&buffer->prs);
-}
-
-/*********************************************************************
- Decode various spoolss rpc's and info levels
- ********************************************************************/
-
-/**********************************************************************
-**********************************************************************/
-static void decode_printer_info_0(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
- uint32 returned, PRINTER_INFO_0 **info)
-{
- uint32 i;
- PRINTER_INFO_0 *inf;
-
- inf=(PRINTER_INFO_0 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_0));
-
- buffer->prs.data_offset=0;
-
- for (i=0; i<returned; i++) {
- smb_io_printer_info_0("", buffer, &inf[i], 0);
- }
-
- *info=inf;
-}
-
-/**********************************************************************
-**********************************************************************/
-static void decode_printer_info_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
- uint32 returned, PRINTER_INFO_1 **info)
-{
- uint32 i;
- PRINTER_INFO_1 *inf;
-
- inf=(PRINTER_INFO_1 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_1));
-
- buffer->prs.data_offset=0;
-
- for (i=0; i<returned; i++) {
- smb_io_printer_info_1("", buffer, &inf[i], 0);
- }
-
- *info=inf;
-}
-
-/**********************************************************************
-**********************************************************************/
-static void decode_printer_info_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
- uint32 returned, PRINTER_INFO_2 **info)
-{
- uint32 i;
- PRINTER_INFO_2 *inf;
-
- inf=(PRINTER_INFO_2 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_2));
-
- buffer->prs.data_offset=0;
-
- for (i=0; i<returned; i++) {
- /* a little initialization as we go */
- inf[i].secdesc = NULL;
- smb_io_printer_info_2("", buffer, &inf[i], 0);
- }
-
- *info=inf;
-}
-
-/**********************************************************************
-**********************************************************************/
-static void decode_printer_info_3(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
- uint32 returned, PRINTER_INFO_3 **info)
-{
- uint32 i;
- PRINTER_INFO_3 *inf;
-
- inf=(PRINTER_INFO_3 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_3));
-
- buffer->prs.data_offset=0;
-
- for (i=0; i<returned; i++) {
- inf[i].secdesc = NULL;
- smb_io_printer_info_3("", buffer, &inf[i], 0);
- }
-
- *info=inf;
-}
-
-/**********************************************************************
-**********************************************************************/
-static void decode_port_info_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
- uint32 returned, PORT_INFO_1 **info)
-{
- uint32 i;
- PORT_INFO_1 *inf;
-
- inf=(PORT_INFO_1*)talloc(mem_ctx, returned*sizeof(PORT_INFO_1));
-
- prs_set_offset(&buffer->prs, 0);
-
- for (i=0; i<returned; i++) {
- smb_io_port_info_1("", buffer, &(inf[i]), 0);
- }
-
- *info=inf;
-}
-
-/**********************************************************************
-**********************************************************************/
-static void decode_port_info_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
- uint32 returned, PORT_INFO_2 **info)
-{
- uint32 i;
- PORT_INFO_2 *inf;
-
- inf=(PORT_INFO_2*)talloc(mem_ctx, returned*sizeof(PORT_INFO_2));
-
- prs_set_offset(&buffer->prs, 0);
-
- for (i=0; i<returned; i++) {
- smb_io_port_info_2("", buffer, &(inf[i]), 0);
- }
-
- *info=inf;
-}
-
-/**********************************************************************
-**********************************************************************/
-static void decode_printer_driver_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
- uint32 returned, DRIVER_INFO_1 **info)
-{
- uint32 i;
- DRIVER_INFO_1 *inf;
-
- inf=(DRIVER_INFO_1 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_1));
-
- buffer->prs.data_offset=0;
-
- for (i=0; i<returned; i++) {
- smb_io_printer_driver_info_1("", buffer, &(inf[i]), 0);
- }
-
- *info=inf;
-}
-
-/**********************************************************************
-**********************************************************************/
-static void decode_printer_driver_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
- uint32 returned, DRIVER_INFO_2 **info)
-{
- uint32 i;
- DRIVER_INFO_2 *inf;
-
- inf=(DRIVER_INFO_2 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_2));
-
- buffer->prs.data_offset=0;
-
- for (i=0; i<returned; i++) {
- smb_io_printer_driver_info_2("", buffer, &(inf[i]), 0);
- }
-
- *info=inf;
-}
-
-/**********************************************************************
-**********************************************************************/
-static void decode_printer_driver_3(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
- uint32 returned, DRIVER_INFO_3 **info)
-{
- uint32 i;
- DRIVER_INFO_3 *inf;
-
- inf=(DRIVER_INFO_3 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_3));
-
- buffer->prs.data_offset=0;
-
- for (i=0; i<returned; i++) {
- smb_io_printer_driver_info_3("", buffer, &(inf[i]), 0);
- }
-
- *info=inf;
-}
-
-/**********************************************************************
-**********************************************************************/
-static void decode_printerdriverdir_1 (TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
- uint32 returned, DRIVER_DIRECTORY_1 **info
-)
-{
- DRIVER_DIRECTORY_1 *inf;
-
- inf=(DRIVER_DIRECTORY_1 *)talloc(mem_ctx, sizeof(DRIVER_DIRECTORY_1));
-
- prs_set_offset(&buffer->prs, 0);
-
- smb_io_driverdir_1("", buffer, inf, 0);
-
- *info=inf;
-}
-
-/** Return a handle to the specified printer or print server.
- *
- * @param cli Pointer to client state structure which is open
- * on the SPOOLSS pipe.
- *
- * @param mem_ctx Pointer to an initialised talloc context.
- *
- * @param printername The name of the printer or print server to be
- * opened in UNC format.
- *
- * @param datatype Specifies the default data type for the printer.
- *
- * @param access_required The access rights requested on the printer or
- * print server.
- *
- * @param station The UNC name of the requesting workstation.
- *
- * @param username The name of the user requesting the open.
- *
- * @param pol Returned policy handle.
- */
-
-/*********************************************************************************
- Win32 API - OpenPrinter()
- ********************************************************************************/
-
-WERROR cli_spoolss_open_printer_ex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- char *printername, char *datatype, uint32 access_required,
- char *station, char *username, POLICY_HND *pol)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_OPEN_PRINTER_EX q;
- SPOOL_R_OPEN_PRINTER_EX r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_open_printer_ex(&q, printername, datatype,
- access_required, station, username);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_open_printer_ex("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_OPENPRINTEREX, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_open_printer_ex("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- if (W_ERROR_IS_OK(result))
- *pol = r.handle;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** Close a printer handle
- *
- * @param cli Pointer to client state structure which is open
- * on the SPOOLSS pipe.
- *
- * @param mem_ctx Pointer to an initialised talloc context.
- *
- * @param pol Policy handle of printer or print server to close.
- */
-/*********************************************************************************
- Win32 API - ClosePrinter()
- ********************************************************************************/
-
-WERROR cli_spoolss_close_printer(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *pol)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_CLOSEPRINTER q;
- SPOOL_R_CLOSEPRINTER r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_closeprinter(&q, pol);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_closeprinter("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_CLOSEPRINTER, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_closeprinter("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- if (W_ERROR_IS_OK(result))
- *pol = r.handle;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** Enumerate printers on a print server.
- *
- * @param cli Pointer to client state structure which is open
- * on the SPOOLSS pipe.
- * @param mem_ctx Pointer to an initialised talloc context.
- *
- * @param offered Buffer size offered in the request.
- * @param needed Number of bytes needed to complete the request.
- * may be NULL.
- *
- * @param flags Selected from PRINTER_ENUM_* flags.
- * @param level Request information level.
- *
- * @param num_printers Pointer to number of printers returned. May be
- * NULL.
- * @param ctr Return structure for printer information. May
- * be NULL.
- */
-/*********************************************************************************
- Win32 API - EnumPrinters()
- ********************************************************************************/
-
-WERROR cli_spoolss_enum_printers(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- uint32 offered, uint32 *needed,
- uint32 flags, uint32 level,
- uint32 *num_printers, PRINTER_INFO_CTR *ctr)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_ENUMPRINTERS q;
- SPOOL_R_ENUMPRINTERS r;
- NEW_BUFFER buffer;
- WERROR result = W_ERROR(ERRgeneral);
- fstring server;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
- strupper (server);
-
- /* Initialise input parameters */
-
- init_buffer(&buffer, offered, mem_ctx);
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- make_spoolss_q_enumprinters(&q, flags, server, level, &buffer,
- offered);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_enumprinters("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_ENUMPRINTERS, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (spoolss_io_r_enumprinters("", &r, &rbuf, 0)) {
- if (needed)
- *needed = r.needed;
- }
-
- result = r.status;
-
- /* Return output parameters */
-
- if (!W_ERROR_IS_OK(r.status))
- goto done;
-
- if (num_printers)
- *num_printers = r.returned;
-
- if (!ctr)
- goto done;
-
- switch (level) {
- case 0:
- decode_printer_info_0(mem_ctx, r.buffer, r.returned,
- &ctr->printers_0);
- break;
- case 1:
- decode_printer_info_1(mem_ctx, r.buffer, r.returned,
- &ctr->printers_1);
- break;
- case 2:
- decode_printer_info_2(mem_ctx, r.buffer, r.returned,
- &ctr->printers_2);
- break;
- case 3:
- decode_printer_info_3(mem_ctx, r.buffer, r.returned,
- &ctr->printers_3);
- break;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/*********************************************************************************
- Win32 API - EnumPorts()
- ********************************************************************************/
-/** Enumerate printer ports on a print server.
- *
- * @param cli Pointer to client state structure which is open
- * on the SPOOLSS pipe.
- * @param mem_ctx Pointer to an initialised talloc context.
- *
- * @param offered Buffer size offered in the request.
- * @param needed Number of bytes needed to complete the request.
- * May be NULL.
- *
- * @param level Requested information level.
- *
- * @param num_ports Pointer to number of ports returned. May be NULL.
- * @param ctr Pointer to structure holding port information.
- * May be NULL.
- */
-
-WERROR cli_spoolss_enum_ports(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- uint32 offered, uint32 *needed,
- uint32 level, int *num_ports, PORT_INFO_CTR *ctr)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_ENUMPORTS q;
- SPOOL_R_ENUMPORTS r;
- NEW_BUFFER buffer;
- WERROR result = W_ERROR(ERRgeneral);
- fstring server;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
- strupper (server);
-
- /* Initialise input parameters */
-
- init_buffer(&buffer, offered, mem_ctx);
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- make_spoolss_q_enumports(&q, server, level, &buffer, offered);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_enumports("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_ENUMPORTS, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (spoolss_io_r_enumports("", &r, &rbuf, 0)) {
- if (needed)
- *needed = r.needed;
- }
-
- result = r.status;
-
- /* Return output parameters */
-
- if (!W_ERROR_IS_OK(result))
- goto done;
-
- if (num_ports)
- *num_ports = r.returned;
-
- if (!ctr)
- goto done;
-
- switch (level) {
- case 1:
- decode_port_info_1(mem_ctx, r.buffer, r.returned,
- &ctr->port.info_1);
- break;
- case 2:
- decode_port_info_2(mem_ctx, r.buffer, r.returned,
- &ctr->port.info_2);
- break;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/*********************************************************************************
- Win32 API - GetPrinter()
- ********************************************************************************/
-
-WERROR cli_spoolss_getprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- uint32 offered, uint32 *needed,
- POLICY_HND *pol, uint32 level,
- PRINTER_INFO_CTR *ctr)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_GETPRINTER q;
- SPOOL_R_GETPRINTER r;
- NEW_BUFFER buffer;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise input parameters */
-
- init_buffer(&buffer, offered, mem_ctx);
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- make_spoolss_q_getprinter(mem_ctx, &q, pol, level, &buffer, offered);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_getprinter("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTER, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_getprinter("", &r, &rbuf, 0))
- goto done;
-
- if (needed)
- *needed = r.needed;
-
- /* Return output parameters */
-
- result = r.status;
-
- if (W_ERROR_IS_OK(result)) {
- switch (level) {
- case 0:
- decode_printer_info_0(mem_ctx, r.buffer, 1, &ctr->printers_0);
- break;
- case 1:
- decode_printer_info_1(mem_ctx, r.buffer, 1, &ctr->printers_1);
- break;
- case 2:
- decode_printer_info_2(mem_ctx, r.buffer, 1, &ctr->printers_2);
- break;
- case 3:
- decode_printer_info_3(mem_ctx, r.buffer, 1, &ctr->printers_3);
- break;
- }
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/*********************************************************************************
- Win32 API - SetPrinter()
- ********************************************************************************/
-/** Set printer info
- *
- * @param cli Pointer to client state structure which is open
- * on the SPOOLSS pipe.
- * @param mem_ctx Pointer to an initialised talloc context.
- *
- * @param pol Policy handle on printer to set info.
- * @param level Information level to set.
- * @param ctr Pointer to structure holding printer information.
- * @param command Specifies the action performed. See
- * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_13ua.asp
- * for details.
- *
- */
-
-WERROR cli_spoolss_setprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *pol, uint32 level,
- PRINTER_INFO_CTR *ctr, uint32 command)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_SETPRINTER q;
- SPOOL_R_SETPRINTER r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise input parameters */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- make_spoolss_q_setprinter(mem_ctx, &q, pol, level, ctr, command);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_setprinter("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_SETPRINTER, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_setprinter("", &r, &rbuf, 0))
- goto done;
-
- result = r.status;
-
-done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/*********************************************************************************
- Win32 API - GetPrinterDriver()
- ********************************************************************************/
-/** Get installed printer drivers for a given printer
- *
- * @param cli Pointer to client state structure which is open
- * on the SPOOLSS pipe.
- *
- * @param mem_ctx Pointer to an initialised talloc context.
- *
- * @param offered Buffer size offered in the request.
- * @param needed Number of bytes needed to complete the request.
- * may be NULL.
- *
- * @param pol Pointer to an open policy handle for the printer
- * opened with cli_spoolss_open_printer_ex().
- * @param level Requested information level.
- * @param env The print environment or archictecture. This is
- * "Windows NT x86" for NT4.
- * @param ctr Returned printer driver information.
- */
-
-WERROR cli_spoolss_getprinterdriver(struct cli_state *cli,
- TALLOC_CTX *mem_ctx,
- uint32 offered, uint32 *needed,
- POLICY_HND *pol, uint32 level,
- char *env, PRINTER_DRIVER_CTR *ctr)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_GETPRINTERDRIVER2 q;
- SPOOL_R_GETPRINTERDRIVER2 r;
- NEW_BUFFER buffer;
- WERROR result = W_ERROR(ERRgeneral);
- fstring server;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- fstrcpy (server, cli->desthost);
- strupper (server);
-
- /* Initialise input parameters */
-
- init_buffer(&buffer, offered, mem_ctx);
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- make_spoolss_q_getprinterdriver2(&q, pol, env, level, 2, 2,
- &buffer, offered);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_getprinterdriver2 ("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req (cli, SPOOLSS_GETPRINTERDRIVER2, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (spoolss_io_r_getprinterdriver2 ("", &r, &rbuf, 0)) {
- if (needed)
- *needed = r.needed;
- }
-
- result = r.status;
-
- /* Return output parameters */
-
- if (!W_ERROR_IS_OK(result))
- goto done;
-
- if (!ctr)
- goto done;
-
- switch (level) {
- case 1:
- decode_printer_driver_1(mem_ctx, r.buffer, 1, &ctr->info1);
- break;
- case 2:
- decode_printer_driver_2(mem_ctx, r.buffer, 1, &ctr->info2);
- break;
- case 3:
- decode_printer_driver_3(mem_ctx, r.buffer, 1, &ctr->info3);
- break;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/*********************************************************************************
- Win32 API - EnumPrinterDrivers()
- ********************************************************************************/
-/**********************************************************************
- * Get installed printer drivers for a given printer
- */
-WERROR cli_spoolss_enumprinterdrivers (struct cli_state *cli,
- TALLOC_CTX *mem_ctx,
- uint32 offered, uint32 *needed,
- uint32 level, char *env,
- uint32 *num_drivers,
- PRINTER_DRIVER_CTR *ctr)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_ENUMPRINTERDRIVERS q;
- SPOOL_R_ENUMPRINTERDRIVERS r;
- NEW_BUFFER buffer;
- WERROR result = W_ERROR(ERRgeneral);
- fstring server;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
- strupper (server);
-
- /* Initialise input parameters */
-
- init_buffer(&buffer, offered, mem_ctx);
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Write the request */
-
- make_spoolss_q_enumprinterdrivers(&q, server, env, level, &buffer,
- offered);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_enumprinterdrivers ("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req (cli, SPOOLSS_ENUMPRINTERDRIVERS, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_enumprinterdrivers ("", &r, &rbuf, 0))
- goto done;
-
- if (needed)
- *needed = r.needed;
-
- if (num_drivers)
- *num_drivers = r.returned;
-
- result = r.status;
-
- /* Return output parameters */
-
- if (W_ERROR_IS_OK(result) && (r.returned != 0)) {
- *num_drivers = r.returned;
-
- switch (level) {
- case 1:
- decode_printer_driver_1(mem_ctx, r.buffer, r.returned, &ctr->info1);
- break;
- case 2:
- decode_printer_driver_2(mem_ctx, r.buffer, r.returned, &ctr->info2);
- break;
- case 3:
- decode_printer_driver_3(mem_ctx, r.buffer, r.returned, &ctr->info3);
- break;
- }
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-
-/*********************************************************************************
- Win32 API - GetPrinterDriverDirectory()
- ********************************************************************************/
-/**********************************************************************
- * Get installed printer drivers for a given printer
- */
-WERROR cli_spoolss_getprinterdriverdir (struct cli_state *cli,
- TALLOC_CTX *mem_ctx,
- uint32 offered, uint32 *needed,
- uint32 level, char *env,
- DRIVER_DIRECTORY_CTR *ctr)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_GETPRINTERDRIVERDIR q;
- SPOOL_R_GETPRINTERDRIVERDIR r;
- NEW_BUFFER buffer;
- WERROR result = W_ERROR(ERRgeneral);
- fstring server;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
- strupper (server);
-
- /* Initialise input parameters */
-
- init_buffer(&buffer, offered, mem_ctx);
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Write the request */
-
- make_spoolss_q_getprinterdriverdir(&q, server, env, level, &buffer,
- offered);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_getprinterdriverdir ("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req (cli, SPOOLSS_GETPRINTERDRIVERDIRECTORY,
- &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (spoolss_io_r_getprinterdriverdir ("", &r, &rbuf, 0)) {
- if (needed)
- *needed = r.needed;
- }
-
- /* Return output parameters */
-
- result = r.status;
-
- if (W_ERROR_IS_OK(result)) {
- switch (level) {
- case 1:
- decode_printerdriverdir_1(mem_ctx, r.buffer, 1,
- &ctr->info1);
- break;
- }
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/*********************************************************************************
- Win32 API - AddPrinterDriver()
- ********************************************************************************/
-/**********************************************************************
- * Install a printer driver
- */
-WERROR cli_spoolss_addprinterdriver (struct cli_state *cli,
- TALLOC_CTX *mem_ctx, uint32 level,
- PRINTER_DRIVER_CTR *ctr)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_ADDPRINTERDRIVER q;
- SPOOL_R_ADDPRINTERDRIVER r;
- WERROR result = W_ERROR(ERRgeneral);
- fstring server;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
- strupper (server);
-
- /* Initialise input parameters */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Write the request */
-
- make_spoolss_q_addprinterdriver (mem_ctx, &q, server, level, ctr);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_addprinterdriver ("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req (cli, SPOOLSS_ADDPRINTERDRIVER, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_addprinterdriver ("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
-done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/*********************************************************************************
- Win32 API - AddPrinter()
- ********************************************************************************/
-/**********************************************************************
- * Install a printer
- */
-WERROR cli_spoolss_addprinterex (struct cli_state *cli, TALLOC_CTX *mem_ctx,
- uint32 level, PRINTER_INFO_CTR*ctr)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_ADDPRINTEREX q;
- SPOOL_R_ADDPRINTEREX r;
- WERROR result = W_ERROR(ERRgeneral);
- fstring server,
- client,
- user;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- slprintf (client, sizeof(fstring)-1, "\\\\%s", cli->desthost);
- strupper (client);
- slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
- strupper (server);
- fstrcpy (user, cli->user_name);
-
- /* Initialise input parameters */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Write the request */
-
- make_spoolss_q_addprinterex (mem_ctx, &q, server, client, user,
- level, ctr);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_addprinterex ("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req (cli, SPOOLSS_ADDPRINTEREX, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_addprinterex ("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/*********************************************************************************
- Win32 API - DeltePrinterDriver()
- ********************************************************************************/
-/**********************************************************************
- * Delete a Printer Driver from the server (does not remove
- * the driver files
- */
-WERROR cli_spoolss_deleteprinterdriver (struct cli_state *cli,
- TALLOC_CTX *mem_ctx, char *arch,
- char *driver)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_DELETEPRINTERDRIVER q;
- SPOOL_R_DELETEPRINTERDRIVER r;
- WERROR result = W_ERROR(ERRgeneral);
- fstring server;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
-
- /* Initialise input parameters */
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
- strupper (server);
-
- /* Write the request */
-
- make_spoolss_q_deleteprinterdriver(mem_ctx, &q, server, arch, driver);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_deleteprinterdriver ("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req (cli,SPOOLSS_DELETEPRINTERDRIVER , &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_deleteprinterdriver ("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/*********************************************************************************
- Win32 API - GetPrinterProcessorDirectory()
- ********************************************************************************/
-
-WERROR cli_spoolss_getprintprocessordirectory(struct cli_state *cli,
- TALLOC_CTX *mem_ctx,
- uint32 offered, uint32 *needed,
- char *name, char *environment,
- fstring procdir)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_GETPRINTPROCESSORDIRECTORY q;
- SPOOL_R_GETPRINTPROCESSORDIRECTORY r;
- int level = 1;
- WERROR result = W_ERROR(ERRgeneral);
- NEW_BUFFER buffer;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- init_buffer(&buffer, offered, mem_ctx);
-
- make_spoolss_q_getprintprocessordirectory(
- &q, name, environment, level, &buffer, offered);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_getprintprocessordirectory("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTPROCESSORDIRECTORY,
- &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_getprintprocessordirectory("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- if (needed)
- *needed = r.needed;
-
- if (W_ERROR_IS_OK(result))
- fstrcpy(procdir, "Not implemented!");
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** Add a form to a printer.
- *
- * @param cli Pointer to client state structure which is open
- * on the SPOOLSS pipe.
- * @param mem_ctx Pointer to an initialised talloc context.
- *
- * @param handle Policy handle opened with cli_spoolss_open_printer_ex
- * or cli_spoolss_addprinterex.
- * @param level Form info level to add - should always be 1.
- * @param form A pointer to the form to be added.
- *
- */
-
-WERROR cli_spoolss_addform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *handle, uint32 level, FORM *form)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_ADDFORM q;
- SPOOL_R_ADDFORM r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_addform(&q, handle, level, form);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_addform("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_ADDFORM, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_addform("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** Set a form on a printer.
- *
- * @param cli Pointer to client state structure which is open
- * on the SPOOLSS pipe.
- * @param mem_ctx Pointer to an initialised talloc context.
- *
- * @param handle Policy handle opened with cli_spoolss_open_printer_ex
- * or cli_spoolss_addprinterex.
- * @param level Form info level to set - should always be 1.
- * @param form A pointer to the form to be set.
- *
- */
-
-WERROR cli_spoolss_setform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *handle, uint32 level, char *form_name,
- FORM *form)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_SETFORM q;
- SPOOL_R_SETFORM r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_setform(&q, handle, level, form_name, form);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_setform("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_SETFORM, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_setform("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- if (!W_ERROR_IS_OK(result))
- goto done;
-
-
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** Get a form on a printer.
- *
- * @param cli Pointer to client state structure which is open
- * on the SPOOLSS pipe.
- * @param mem_ctx Pointer to an initialised talloc context.
- *
- * @param handle Policy handle opened with cli_spoolss_open_printer_ex
- * or cli_spoolss_addprinterex.
- * @param formname Name of the form to get
- * @param level Form info level to get - should always be 1.
- *
- */
-
-WERROR cli_spoolss_getform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- uint32 offered, uint32 *needed,
- POLICY_HND *handle, char *formname, uint32 level,
- FORM_1 *form)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_GETFORM q;
- SPOOL_R_GETFORM r;
- WERROR result = W_ERROR(ERRgeneral);
- NEW_BUFFER buffer;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- init_buffer(&buffer, offered, mem_ctx);
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_getform(&q, handle, formname, level, &buffer, offered);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_getform("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_GETFORM, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_getform("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- if (needed)
- *needed = r.needed;
-
- if (W_ERROR_IS_OK(result))
- smb_io_form_1("", r.buffer, form, 0);
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** Delete a form on a printer.
- *
- * @param cli Pointer to client state structure which is open
- * on the SPOOLSS pipe.
- * @param mem_ctx Pointer to an initialised talloc context.
- *
- * @param handle Policy handle opened with cli_spoolss_open_printer_ex
- * or cli_spoolss_addprinterex.
- * @param form The name of the form to delete.
- *
- */
-
-WERROR cli_spoolss_deleteform(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *handle, char *form_name)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_DELETEFORM q;
- SPOOL_R_DELETEFORM r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_deleteform(&q, handle, form_name);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_deleteform("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_DELETEFORM, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_deleteform("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-static void decode_forms_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
- uint32 num_forms, FORM_1 **forms)
-{
- int i;
-
- *forms = (FORM_1 *)talloc(mem_ctx, num_forms * sizeof(FORM_1));
- buffer->prs.data_offset = 0;
-
- for (i = 0; i < num_forms; i++)
- smb_io_form_1("", buffer, &((*forms)[i]), 0);
-}
-
-/** Enumerate forms
- *
- * @param cli Pointer to client state structure which is open
- * on the SPOOLSS pipe.
- * @param mem_ctx Pointer to an initialised talloc context.
- *
- * @param offered Buffer size offered in the request.
- * @param needed Number of bytes needed to complete the request.
- * may be NULL.
- * or cli_spoolss_addprinterex.
- * @param level Form info level to get - should always be 1.
- * @param handle Open policy handle
- *
- */
-
-WERROR cli_spoolss_enumforms(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- uint32 offered, uint32 *needed,
- POLICY_HND *handle, int level, uint32 *num_forms,
- FORM_1 **forms)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_ENUMFORMS q;
- SPOOL_R_ENUMFORMS r;
- WERROR result = W_ERROR(ERRgeneral);
- NEW_BUFFER buffer;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- init_buffer(&buffer, offered, mem_ctx);
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_enumforms(&q, handle, level, &buffer, offered);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_enumforms("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_ENUMFORMS, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_enumforms("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- if (needed)
- *needed = r.needed;
-
- if (num_forms)
- *num_forms = r.numofforms;
-
- decode_forms_1(mem_ctx, r.buffer, *num_forms, forms);
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-static void decode_jobs_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
- uint32 num_jobs, JOB_INFO_1 **jobs)
-{
- uint32 i;
-
- *jobs = (JOB_INFO_1 *)talloc(mem_ctx, num_jobs * sizeof(JOB_INFO_1));
- buffer->prs.data_offset = 0;
-
- for (i = 0; i < num_jobs; i++)
- smb_io_job_info_1("", buffer, &((*jobs)[i]), 0);
-}
-
-static void decode_jobs_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
- uint32 num_jobs, JOB_INFO_2 **jobs)
-{
- uint32 i;
-
- *jobs = (JOB_INFO_2 *)talloc(mem_ctx, num_jobs * sizeof(JOB_INFO_2));
- buffer->prs.data_offset = 0;
-
- for (i = 0; i < num_jobs; i++)
- smb_io_job_info_2("", buffer, &((*jobs)[i]), 0);
-}
-
-/* Enumerate jobs */
-
-WERROR cli_spoolss_enumjobs(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- uint32 offered, uint32 *needed,
- POLICY_HND *hnd, uint32 level, uint32 firstjob,
- uint32 num_jobs, uint32 *returned, JOB_INFO_CTR *ctr)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_ENUMJOBS q;
- SPOOL_R_ENUMJOBS r;
- WERROR result = W_ERROR(ERRgeneral);
- NEW_BUFFER buffer;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- init_buffer(&buffer, offered, mem_ctx);
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_enumjobs(&q, hnd, firstjob, num_jobs, level, &buffer,
- offered);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_enumjobs("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_ENUMJOBS, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_enumjobs("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- if (needed)
- *needed = r.needed;
-
- if (!W_ERROR_IS_OK(r.status))
- goto done;
-
- *returned = r.returned;
-
- switch(level) {
- case 1:
- decode_jobs_1(mem_ctx, r.buffer, r.returned,
- ctr->job.job_info_1);
- break;
- case 2:
- decode_jobs_2(mem_ctx, r.buffer, r.returned,
- ctr->job.job_info_2);
- break;
- default:
- DEBUG(3, ("unsupported info level %d", level));
- break;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Set job */
-
-WERROR cli_spoolss_setjob(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *hnd, uint32 jobid, uint32 level,
- uint32 command)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_SETJOB q;
- SPOOL_R_SETJOB r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_setjob(&q, hnd, jobid, level, command);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_setjob("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_SETJOB, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_setjob("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Get job */
-
-WERROR cli_spoolss_getjob(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- uint32 offered, uint32 *needed,
- POLICY_HND *hnd, uint32 jobid, uint32 level,
- JOB_INFO_CTR *ctr)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_GETJOB q;
- SPOOL_R_GETJOB r;
- WERROR result = W_ERROR(ERRgeneral);
- NEW_BUFFER buffer;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- init_buffer(&buffer, offered, mem_ctx);
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_getjob(&q, hnd, jobid, level, &buffer, offered);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_getjob("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_GETJOB, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_getjob("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- if (needed)
- *needed = r.needed;
-
- if (!W_ERROR_IS_OK(r.status))
- goto done;
-
- switch(level) {
- case 1:
- decode_jobs_1(mem_ctx, r.buffer, 1, ctr->job.job_info_1);
- break;
- case 2:
- decode_jobs_2(mem_ctx, r.buffer, 1, ctr->job.job_info_2);
- break;
- default:
- DEBUG(3, ("unsupported info level %d", level));
- break;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Startpageprinter. Sent to notify the spooler when a page is about to be
- sent to a printer. */
-
-WERROR cli_spoolss_startpageprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *hnd)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_STARTPAGEPRINTER q;
- SPOOL_R_STARTPAGEPRINTER r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_startpageprinter(&q, hnd);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_startpageprinter("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_STARTPAGEPRINTER, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_startpageprinter("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Endpageprinter. Sent to notify the spooler when a page has finished
- being sent to a printer. */
-
-WERROR cli_spoolss_endpageprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *hnd)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_ENDPAGEPRINTER q;
- SPOOL_R_ENDPAGEPRINTER r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_endpageprinter(&q, hnd);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_endpageprinter("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_ENDPAGEPRINTER, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_endpageprinter("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Startdocprinter. Sent to notify the spooler that a document is about
- to be spooled for printing. */
-
-WERROR cli_spoolss_startdocprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *hnd, char *docname,
- char *outputfile, char *datatype,
- uint32 *jobid)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_STARTDOCPRINTER q;
- SPOOL_R_STARTDOCPRINTER r;
- WERROR result = W_ERROR(ERRgeneral);
- uint32 level = 1;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_startdocprinter(&q, hnd, level, docname, outputfile,
- datatype);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_startdocprinter("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_STARTDOCPRINTER, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_startdocprinter("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- if (W_ERROR_IS_OK(result))
- *jobid = r.jobid;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Enddocprinter. Sent to notify the spooler that a document has finished
- being spooled. */
-
-WERROR cli_spoolss_enddocprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *hnd)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_ENDDOCPRINTER q;
- SPOOL_R_ENDDOCPRINTER r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_enddocprinter(&q, hnd);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_enddocprinter("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_ENDDOCPRINTER, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_enddocprinter("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Get printer data */
-
-WERROR cli_spoolss_getprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- uint32 offered, uint32 *needed,
- POLICY_HND *hnd, char *valuename,
- uint32 *data_type, char **data,
- uint32 *data_size)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_GETPRINTERDATA q;
- SPOOL_R_GETPRINTERDATA r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_getprinterdata(&q, hnd, valuename, offered);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_getprinterdata("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTERDATA, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_getprinterdata("", &r, &rbuf, 0))
- goto done;
-
- result = r.status;
-
- if (needed)
- *needed = r.needed;
-
- if (!W_ERROR_IS_OK(r.status))
- goto done;
-
- /* Return output parameters */
-
- if (data_type)
- *data_type = r.type;
-
- if (data) {
- *data = (char *)talloc(mem_ctx, r.needed);
- memcpy(*data, r.data, r.needed);
- }
-
- if (data_size)
- *data_size = r.needed;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Set printer data */
-
-WERROR cli_spoolss_setprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *hnd, char *value,
- uint32 data_type, char *data,
- uint32 data_size)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_SETPRINTERDATA q;
- SPOOL_R_SETPRINTERDATA r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_setprinterdata(&q, hnd, value, data, data_size);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_setprinterdata("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_SETPRINTERDATA, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_setprinterdata("", &r, &rbuf, 0))
- goto done;
-
- result = r.status;
-
- if (!W_ERROR_IS_OK(r.status))
- goto done;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Enum printer data */
-
-WERROR cli_spoolss_enumprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *hnd, uint32 ndx,
- uint32 value_offered, uint32 data_offered,
- uint32 *value_needed, uint32 *data_needed,
- char **value, uint32 *data_type, char **data,
- uint32 *data_size)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_ENUMPRINTERDATA q;
- SPOOL_R_ENUMPRINTERDATA r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_enumprinterdata(&q, hnd, ndx, value_offered, data_offered);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_enumprinterdata("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_ENUMPRINTERDATA, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_enumprinterdata("", &r, &rbuf, 0))
- goto done;
-
- result = r.status;
-
- if (!W_ERROR_IS_OK(r.status))
- goto done;
-
- /* Return data */
-
- if (value_needed)
- *value_needed = r.realvaluesize;
-
- if (data_needed)
- *data_needed = r.realdatasize;
-
- if (data_type)
- *data_type = r.type;
-
- if (value) {
- fstring the_value;
-
- rpcstr_pull(the_value, r.value, sizeof(the_value), -1,
- STR_TERMINATE);
-
- *value = talloc_strdup(mem_ctx, the_value);
- }
-
- if (data)
- *data = talloc_memdup(mem_ctx, r.data, r.realdatasize);
-
- if (data_size)
- *data_size = r.realdatasize;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Write data to printer */
-
-WERROR cli_spoolss_writeprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *hnd, uint32 data_size, char *data,
- uint32 *num_written)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_WRITEPRINTER q;
- SPOOL_R_WRITEPRINTER r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_writeprinter(&q, hnd, data_size, data);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_writeprinter("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_WRITEPRINTER, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_writeprinter("", &r, &rbuf, 0))
- goto done;
-
- result = r.status;
-
- if (!W_ERROR_IS_OK(r.status))
- goto done;
-
- if (num_written)
- *num_written = r.buffer_written;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Delete printer data */
-
-WERROR cli_spoolss_deleteprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *hnd, char *valuename)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_DELETEPRINTERDATA q;
- SPOOL_R_DELETEPRINTERDATA r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_deleteprinterdata(&q, hnd, valuename);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_deleteprinterdata("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_DELETEPRINTERDATA, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_deleteprinterdata("", &r, &rbuf, 0))
- goto done;
-
- result = r.status;
-
- if (!W_ERROR_IS_OK(r.status))
- goto done;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** @} **/
diff --git a/source3/libsmb/cli_spoolss_notify.c b/source3/libsmb/cli_spoolss_notify.c
deleted file mode 100644
index 922b0fbb1d..0000000000
--- a/source3/libsmb/cli_spoolss_notify.c
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- RPC pipe client
-
- Copyright (C) Gerald Carter 2001-2002,
- Copyright (C) Tim Potter 2000-2002,
- Copyright (C) Andrew Tridgell 1994-2000,
- Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
- Copyright (C) Jean-Francois Micouleau 1999-2000.
-
- 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 2 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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "includes.h"
-
-/*
- * SPOOLSS Client RPC's used by servers as the notification
- * back channel.
- */
-
-/* Send a ReplyOpenPrinter request. This rpc is made by the printer
- server to the printer client in response to a rffpcnex request.
- The rrfpcnex request names a printer and a handle (the printerlocal
- value) and this rpc establishes a back-channel over which printer
- notifications are performed. */
-
-WERROR cli_spoolss_reply_open_printer(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- char *printer, uint32 printerlocal, uint32 type,
- POLICY_HND *handle)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_REPLYOPENPRINTER q;
- SPOOL_R_REPLYOPENPRINTER r;
- WERROR result = W_ERROR(ERRgeneral);
-
- /* Initialise input parameters */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- make_spoolss_q_replyopenprinter(&q, printer, printerlocal, type);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_replyopenprinter("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req (cli, SPOOLSS_REPLYOPENPRINTER, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_replyopenprinter("", &r, &rbuf, 0))
- goto done;
-
- /* Return result */
-
- memcpy(handle, &r.handle, sizeof(r.handle));
- result = r.status;
-
-done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Close a back-channel notification connection */
-
-WERROR cli_spoolss_reply_close_printer(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *handle)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_REPLYCLOSEPRINTER q;
- SPOOL_R_REPLYCLOSEPRINTER r;
- WERROR result = W_ERROR(ERRgeneral);
-
- /* Initialise input parameters */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- make_spoolss_q_reply_closeprinter(&q, handle);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_replycloseprinter("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req (cli, SPOOLSS_REPLYCLOSEPRINTER, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_replycloseprinter("", &r, &rbuf, 0))
- goto done;
-
- /* Return result */
-
- result = r.status;
-
-done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/*********************************************************************
- This SPOOLSS_ROUTERREPLYPRINTER function is used to send a change
- notification event when the registration **did not** use
- SPOOL_NOTIFY_OPTION_TYPE structure to specify the events to monitor.
- Also see cli_spolss_reply_rrpcn()
- *********************************************************************/
-
-WERROR cli_spoolss_routerreplyprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *pol, uint32 condition, uint32 change_id)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_ROUTERREPLYPRINTER q;
- SPOOL_R_ROUTERREPLYPRINTER r;
- WERROR result = W_ERROR(ERRgeneral);
-
- /* Initialise input parameters */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- make_spoolss_q_routerreplyprinter(&q, pol, condition, change_id);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_routerreplyprinter("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req (cli, SPOOLSS_ROUTERREPLYPRINTER, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_routerreplyprinter("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
-done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/*********************************************************************
- This SPOOLSS_REPLY_RRPCN function is used to send a change
- notification event when the registration **did** use
- SPOOL_NOTIFY_OPTION_TYPE structure to specify the events to monitor
- Also see cli_spoolss_routereplyprinter()
- *********************************************************************/
-
-WERROR cli_spoolss_rrpcn(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *pol, uint32 notify_data_len,
- SPOOL_NOTIFY_INFO_DATA *notify_data,
- uint32 change_low, uint32 change_high)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_REPLY_RRPCN q;
- SPOOL_R_REPLY_RRPCN r;
- WERROR result = W_ERROR(ERRgeneral);
- SPOOL_NOTIFY_INFO notify_info;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- ZERO_STRUCT(notify_info);
-
- /* Initialise input parameters */
-
- notify_info.version = 0x2;
- notify_info.flags = 0x00020000; /* ?? */
- notify_info.count = notify_data_len;
- notify_info.data = notify_data;
-
- /* create and send a MSRPC command with api */
- /* store the parameters */
-
- make_spoolss_q_reply_rrpcn(&q, pol, change_low, change_high,
- &notify_info);
-
- /* Marshall data and send request */
-
- if(!spoolss_io_q_reply_rrpcn("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_RRPCN, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if(!spoolss_io_r_reply_rrpcn("", &r, &rbuf, 0))
- goto done;
-
- if (r.unknown0 == 0x00080000)
- DEBUG(8,("cli_spoolss_reply_rrpcn: I think the spooler resonded that the notification was ignored.\n"));
-
- result = r.status;
-
-done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
diff --git a/source3/libsmb/cli_srvsvc.c b/source3/libsmb/cli_srvsvc.c
deleted file mode 100644
index 2dc12d726c..0000000000
--- a/source3/libsmb/cli_srvsvc.c
+++ /dev/null
@@ -1,442 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- NT Domain Authentication SMB / MSRPC client
- Copyright (C) Andrew Tridgell 1994-2000
- Copyright (C) Luke Kenneth Casson Leighton 1996-2000
- Copyright (C) Tim Potter 2001
- Copyright (C) Jim McDonough 2002
-
- 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 2 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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "includes.h"
-
-NTSTATUS cli_srvsvc_net_srv_get_info(struct cli_state *cli,
- TALLOC_CTX *mem_ctx,
- uint32 switch_value, SRV_INFO_CTR *ctr)
-{
- prs_struct qbuf, rbuf;
- SRV_Q_NET_SRV_GET_INFO q;
- SRV_R_NET_SRV_GET_INFO r;
- NTSTATUS result;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- init_srv_q_net_srv_get_info(&q, cli->srv_name_slash, switch_value);
-
- /* Marshall data and send request */
-
- if (!srv_io_q_net_srv_get_info("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SRV_NET_SRV_GET_INFO, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- r.ctr = ctr;
-
- if (!srv_io_r_net_srv_get_info("", &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- result = werror_to_ntstatus(r.status);
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-WERROR cli_srvsvc_net_share_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- uint32 info_level, SRV_SHARE_INFO_CTR *ctr,
- int preferred_len, ENUM_HND *hnd)
-{
- prs_struct qbuf, rbuf;
- SRV_Q_NET_SHARE_ENUM q;
- SRV_R_NET_SHARE_ENUM r;
- WERROR result = W_ERROR(ERRgeneral);
- int i;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- init_srv_q_net_share_enum(
- &q, cli->srv_name_slash, info_level, preferred_len, hnd);
-
- /* Marshall data and send request */
-
- if (!srv_io_q_net_share_enum("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SRV_NET_SHARE_ENUM_ALL, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!srv_io_r_net_share_enum("", &r, &rbuf, 0))
- goto done;
-
- result = r.status;
-
- if (!W_ERROR_IS_OK(result))
- goto done;
-
- /* Oh yuck yuck yuck - we have to copy all the info out of the
- SRV_SHARE_INFO_CTR in the SRV_R_NET_SHARE_ENUM as when we do a
- prs_mem_free() it will all be invalidated. The various share
- info structures suck badly too. This really is gross. */
-
- ZERO_STRUCTP(ctr);
-
- ctr->info_level = info_level;
- ctr->num_entries = r.ctr.num_entries;
-
- switch(info_level) {
- case 1:
- ctr->share.info1 = (SRV_SHARE_INFO_1 *)talloc(
- mem_ctx, sizeof(SRV_SHARE_INFO_1) * ctr->num_entries);
-
- memset(ctr->share.info1, 0, sizeof(SRV_SHARE_INFO_1));
-
- for (i = 0; i < ctr->num_entries; i++) {
- SRV_SHARE_INFO_1 *info1 = &ctr->share.info1[i];
- char *s;
-
- /* Copy pointer crap */
-
- memcpy(&info1->info_1, &r.ctr.share.info1[i].info_1,
- sizeof(SH_INFO_1));
-
- /* Duplicate strings */
-
- s = unistr2_tdup(mem_ctx, &r.ctr.share.info1[i].info_1_str.uni_netname);
- if (s)
- init_unistr2(&info1->info_1_str.uni_netname, s, strlen(s) + 1);
-
- s = unistr2_tdup(mem_ctx, &r.ctr.share.info1[i].info_1_str.uni_remark);
- if (s)
- init_unistr2(&info1->info_1_str.uni_remark, s, strlen(s) + 1);
-
- }
-
- break;
- case 2:
- ctr->share.info2 = (SRV_SHARE_INFO_2 *)talloc(
- mem_ctx, sizeof(SRV_SHARE_INFO_2) * ctr->num_entries);
-
- memset(ctr->share.info2, 0, sizeof(SRV_SHARE_INFO_2));
-
- for (i = 0; i < ctr->num_entries; i++) {
- SRV_SHARE_INFO_2 *info2 = &ctr->share.info2[i];
- char *s;
-
- /* Copy pointer crap */
-
- memcpy(&info2->info_2, &r.ctr.share.info2[i].info_2,
- sizeof(SH_INFO_2));
-
- /* Duplicate strings */
-
- s = unistr2_tdup(mem_ctx, &r.ctr.share.info2[i].info_2_str.uni_netname);
- if (s)
- init_unistr2(&info2->info_2_str.uni_netname, s, strlen(s) + 1);
-
- s = unistr2_tdup(mem_ctx, &r.ctr.share.info2[i].info_2_str.uni_remark);
- if (s)
- init_unistr2(&info2->info_2_str.uni_remark, s, strlen(s) + 1);
-
- s = unistr2_tdup(mem_ctx, &r.ctr.share.info2[i].info_2_str.uni_path);
- if (s)
- init_unistr2(&info2->info_2_str.uni_path, s, strlen(s) + 1);
-
- s = unistr2_tdup(mem_ctx, &r.ctr.share.info2[i].info_2_str.uni_passwd);
- if (s)
- init_unistr2(&info2->info_2_str.uni_passwd, s, strlen(s) + 1);
- }
- break;
- }
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-WERROR cli_srvsvc_net_share_del(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- const char *sharename)
-{
- prs_struct qbuf, rbuf;
- SRV_Q_NET_SHARE_DEL q;
- SRV_R_NET_SHARE_DEL r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- init_srv_q_net_share_del(&q, cli->srv_name_slash, sharename);
-
- /* Marshall data and send request */
-
- if (!srv_io_q_net_share_del("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SRV_NET_SHARE_DEL, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!srv_io_r_net_share_del("", &r, &rbuf, 0))
- goto done;
-
- result = r.status;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-WERROR cli_srvsvc_net_share_add(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- char *netname, uint32 type, char *remark,
- uint32 perms, uint32 max_uses, uint32 num_uses,
- char *path, char *passwd)
-{
- prs_struct qbuf, rbuf;
- SRV_Q_NET_SHARE_ADD q;
- SRV_R_NET_SHARE_ADD r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- init_srv_q_net_share_add(&q,cli->srv_name_slash, netname, type, remark,
- perms, max_uses, num_uses, path, passwd);
-
- /* Marshall data and send request */
-
- if (!srv_io_q_net_share_add("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SRV_NET_SHARE_ADD, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!srv_io_r_net_share_add("", &r, &rbuf, 0))
- goto done;
-
- result = r.status;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-WERROR cli_srvsvc_net_remote_tod(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- char *server, TIME_OF_DAY_INFO *tod)
-{
- prs_struct qbuf, rbuf;
- SRV_Q_NET_REMOTE_TOD q;
- SRV_R_NET_REMOTE_TOD r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- init_srv_q_net_remote_tod(&q, cli->srv_name_slash);
-
- /* Marshall data and send request */
-
- if (!srv_io_q_net_remote_tod("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SRV_NET_REMOTE_TOD, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- r.tod = tod;
-
- if (!srv_io_r_net_remote_tod("", &r, &rbuf, 0))
- goto done;
-
- result = r.status;
-
- if (!W_ERROR_IS_OK(result))
- goto done;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-WERROR cli_srvsvc_net_file_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- uint32 file_level, char *user_name,
- SRV_FILE_INFO_CTR *ctr, int preferred_len,
- ENUM_HND *hnd)
-{
- prs_struct qbuf, rbuf;
- SRV_Q_NET_FILE_ENUM q;
- SRV_R_NET_FILE_ENUM r;
- WERROR result = W_ERROR(ERRgeneral);
- int i;
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- init_srv_q_net_file_enum(&q, cli->srv_name_slash, NULL, user_name,
- file_level, ctr, preferred_len, hnd);
-
- /* Marshall data and send request */
-
- if (!srv_io_q_net_file_enum("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SRV_NET_FILE_ENUM, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!srv_io_r_net_file_enum("", &r, &rbuf, 0))
- goto done;
-
- result = r.status;
-
- if (!W_ERROR_IS_OK(result))
- goto done;
-
- /* copy the data over to the ctr */
-
- ZERO_STRUCTP(ctr);
-
- ctr->switch_value = file_level;
-
- ctr->num_entries = ctr->num_entries2 = r.ctr.num_entries;
-
- switch(file_level) {
- case 3:
- ctr->file.info3 = (SRV_FILE_INFO_3 *)talloc(
- mem_ctx, sizeof(SRV_FILE_INFO_3) * ctr->num_entries);
-
- memset(ctr->file.info3, 0,
- sizeof(SRV_FILE_INFO_3) * ctr->num_entries);
-
- for (i = 0; i < r.ctr.num_entries; i++) {
- SRV_FILE_INFO_3 *info3 = &ctr->file.info3[i];
- char *s;
-
- /* Copy pointer crap */
-
- memcpy(&info3->info_3, &r.ctr.file.info3[i].info_3,
- sizeof(FILE_INFO_3));
-
- /* Duplicate strings */
-
- s = unistr2_tdup(mem_ctx, &r.ctr.file.info3[i].info_3_str.uni_path_name);
- if (s)
- init_unistr2(&info3->info_3_str.uni_path_name, s, strlen(s) + 1);
-
- s = unistr2_tdup(mem_ctx, &r.ctr.file.info3[i].info_3_str.uni_user_name);
- if (s)
- init_unistr2(&info3->info_3_str.uni_user_name, s, strlen(s) + 1);
-
- }
-
- break;
- }
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-WERROR cli_srvsvc_net_file_close(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- uint32 file_id)
-{
- prs_struct qbuf, rbuf;
- SRV_Q_NET_FILE_CLOSE q;
- SRV_R_NET_FILE_CLOSE r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- init_srv_q_net_file_close(&q, cli->srv_name_slash, file_id);
-
- /* Marshall data and send request */
-
- if (!srv_io_q_net_file_close("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SRV_NET_FILE_CLOSE, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!srv_io_r_net_file_close("", &r, &rbuf, 0))
- goto done;
-
- result = r.status;
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
- return result;
-}
diff --git a/source3/libsmb/cli_wkssvc.c b/source3/libsmb/cli_wkssvc.c
deleted file mode 100644
index 97b948bf62..0000000000
--- a/source3/libsmb/cli_wkssvc.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- NT Domain Authentication SMB / MSRPC client
- Copyright (C) Andrew Tridgell 1994-2000
- Copyright (C) Luke Kenneth Casson Leighton 1996-2000
- Copyright (C) Tim Potter 2001
- Copytight (C) Rafal Szczesniak 2002
-
- 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 2 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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "includes.h"
-
-/**
- * WksQueryInfo rpc call (like query for server's capabilities)
- *
- * @param initialised client structure with \PIPE\wkssvc opened
- * @param mem_ctx memory context assigned to this rpc binding
- * @param wks100 WksQueryInfo structure
- *
- * @return NTSTATUS of rpc call
- */
-
-NTSTATUS cli_wks_query_info(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- WKS_INFO_100 *wks100)
-{
- prs_struct buf;
- prs_struct rbuf;
- WKS_Q_QUERY_INFO q_o;
- WKS_R_QUERY_INFO r_o;
-
- if (cli == NULL || wks100 == NULL)
- return NT_STATUS_UNSUCCESSFUL;
-
- /* init rpc parse structures */
- prs_init(&buf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- DEBUG(4, ("WksQueryInfo\n"));
-
- /* init query structure with rpc call arguments */
- init_wks_q_query_info(&q_o, cli->desthost, 100);
-
- /* marshall data */
- if (!wks_io_q_query_info("", &q_o, &buf, 0)) {
- prs_mem_free(&buf);
- prs_mem_free(&rbuf);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- /* actual rpc call over \PIPE\wkssvc */
- if (!rpc_api_pipe_req(cli, WKS_QUERY_INFO, &buf, &rbuf)) {
- prs_mem_free(&buf);
- prs_mem_free(&rbuf);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- prs_mem_free(&buf);
-
- r_o.wks100 = wks100;
-
- /* get call results from response buffer */
- if (!wks_io_r_query_info("", &r_o, &rbuf, 0)) {
- prs_mem_free(&rbuf);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- /* check returnet status code */
- if (NT_STATUS_IS_ERR(r_o.status)) {
- /* report the error */
- DEBUG(0,("WKS_R_QUERY_INFO: %s\n", nt_errstr(r_o.status)));
- prs_mem_free(&rbuf);
- return r_o.status;
- }
-
- /* do clean up */
- prs_mem_free(&rbuf);
-
- return NT_STATUS_OK;
-}
-
diff --git a/source3/nsswitch/winbindd_proto.h b/source3/nsswitch/winbindd_proto.h
deleted file mode 100644
index 4d4dbbb06b..0000000000
--- a/source3/nsswitch/winbindd_proto.h
+++ /dev/null
@@ -1,143 +0,0 @@
-#ifndef _WINBINDD_PROTO_H_
-#define _WINBINDD_PROTO_H_
-
-/* This file is automatically generated with "make proto". DO NOT EDIT */
-
-
-/* The following definitions come from nsswitch/winbindd.c */
-
-void winbind_process_packet(struct winbindd_cli_state *state);
-void winbind_client_read(struct winbindd_cli_state *state);
-int winbind_setup_common(void);
-
-/* The following definitions come from nsswitch/winbindd_ads.c */
-
-ADS_STATUS ads_do_search_retry(ADS_STRUCT *ads, const char *bind_path, int scope,
- const char *exp,
- const char **attrs, void **res);
-ADS_STATUS ads_search_retry(ADS_STRUCT *ads, void **res,
- const char *exp,
- const char **attrs);
-ADS_STATUS ads_search_retry_dn(ADS_STRUCT *ads, void **res,
- const char *dn,
- const char **attrs);
-
-/* The following definitions come from nsswitch/winbindd_cache.c */
-
-void wcache_flush_cache(void);
-void winbindd_check_cache_size(time_t t);
-struct cache_entry *centry_start(struct winbindd_domain *domain, NTSTATUS status);
-
-/* The following definitions come from nsswitch/winbindd_cm.c */
-
-CLI_POLICY_HND *cm_get_lsa_handle(char *domain);
-CLI_POLICY_HND *cm_get_sam_handle(char *domain);
-CLI_POLICY_HND *cm_get_sam_dom_handle(char *domain, DOM_SID *domain_sid);
-CLI_POLICY_HND *cm_get_sam_user_handle(char *domain, DOM_SID *domain_sid,
- uint32 user_rid);
-CLI_POLICY_HND *cm_get_sam_group_handle(char *domain, DOM_SID *domain_sid,
- uint32 group_rid);
-NTSTATUS cm_get_netlogon_cli(char *domain, unsigned char *trust_passwd,
- struct cli_state **cli);
-void winbindd_cm_status(void);
-
-/* The following definitions come from nsswitch/winbindd_dual.c */
-
-int dual_select_setup(fd_set *fds, int maxfd);
-void dual_select(fd_set *fds);
-void dual_send_request(struct winbindd_cli_state *state);
-void do_dual_daemon(void);
-
-/* The following definitions come from nsswitch/winbindd_group.c */
-
-enum winbindd_result winbindd_getgrnam(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_getgrgid(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_setgrent(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_endgrent(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_list_groups(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_getgroups(struct winbindd_cli_state *state);
-
-/* The following definitions come from nsswitch/winbindd_idmap.c */
-
-BOOL winbindd_idmap_get_uid_from_sid(DOM_SID *sid, uid_t *uid);
-BOOL winbindd_idmap_get_gid_from_sid(DOM_SID *sid, gid_t *gid);
-BOOL winbindd_idmap_get_uid_from_rid(const char *dom_name, uint32 rid, uid_t *uid);
-BOOL winbindd_idmap_get_gid_from_rid(const char *dom_name, uint32 rid, gid_t *gid);
-BOOL get_sid_from_id(int id, DOM_SID *sid, BOOL isgroup);
-BOOL winbindd_idmap_get_sid_from_uid(uid_t uid, DOM_SID *sid);
-BOOL winbindd_idmap_get_sid_from_gid(gid_t gid, DOM_SID *sid);
-BOOL winbindd_idmap_get_rid_from_uid(uid_t uid, uint32 *user_rid,
- struct winbindd_domain **domain);
-BOOL winbindd_idmap_get_rid_from_gid(gid_t gid, uint32 *group_rid,
- struct winbindd_domain **domain);
-BOOL winbindd_idmap_init(void);
-BOOL winbindd_idmap_close(void);
-void winbindd_idmap_status(void);
-
-/* The following definitions come from nsswitch/winbindd_misc.c */
-
-enum winbindd_result winbindd_check_machine_acct(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_list_trusted_domains(struct winbindd_cli_state
- *state);
-enum winbindd_result winbindd_show_sequence(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_ping(struct winbindd_cli_state
- *state);
-enum winbindd_result winbindd_info(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_interface_version(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_domain_name(struct winbindd_cli_state *state);
-
-/* The following definitions come from nsswitch/winbindd_pam.c */
-
-enum winbindd_result winbindd_pam_auth(struct winbindd_cli_state *state) ;
-enum winbindd_result winbindd_pam_auth_crap(struct winbindd_cli_state *state) ;
-enum winbindd_result winbindd_pam_chauthtok(struct winbindd_cli_state *state);
-
-/* The following definitions come from nsswitch/winbindd_rpc.c */
-
-
-/* The following definitions come from nsswitch/winbindd_sid.c */
-
-enum winbindd_result winbindd_lookupsid(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_lookupname(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_sid_to_uid(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_sid_to_gid(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_uid_to_sid(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_gid_to_sid(struct winbindd_cli_state *state);
-
-/* The following definitions come from nsswitch/winbindd_user.c */
-
-enum winbindd_result winbindd_getpwnam(struct winbindd_cli_state *state) ;
-enum winbindd_result winbindd_getpwuid(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_setpwent(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_endpwent(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_getpwent(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_list_users(struct winbindd_cli_state *state);
-
-/* The following definitions come from nsswitch/winbindd_util.c */
-
-struct winbindd_domain *domain_list(void);
-void free_domain_list(void);
-void rescan_trusted_domains(void);
-BOOL init_domain_list(void);
-struct winbindd_domain *find_domain_from_name(const char *domain_name);
-struct winbindd_domain *find_domain_from_sid(DOM_SID *sid);
-BOOL winbindd_lookup_sid_by_name(struct winbindd_domain *domain,
- const char *name, DOM_SID *sid,
- enum SID_NAME_USE *type);
-BOOL winbindd_lookup_name_by_sid(DOM_SID *sid,
- fstring dom_name,
- fstring name,
- enum SID_NAME_USE *type);
-void free_getent_state(struct getent_state *state);
-BOOL winbindd_param_init(void);
-BOOL check_domain_env(char *domain_env, char *domain);
-BOOL parse_domain_user(const char *domuser, fstring domain, fstring user);
-void fill_domain_username(fstring name, const char *domain, const char *user);
-
-/* The following definitions come from nsswitch/winbindd_wins.c */
-
-enum winbindd_result winbindd_wins_byip(struct winbindd_cli_state *state);
-enum winbindd_result winbindd_wins_byname(struct winbindd_cli_state *state);
-
-#endif /* _WINBINDD_PROTO_H_ */
diff --git a/source3/passdb/passgrp.c b/source3/passdb/passgrp.c
deleted file mode 100644
index f73591793f..0000000000
--- a/source3/passdb/passgrp.c
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- Password and authentication handling
- Copyright (C) Jeremy Allison 1996-1998
- Copyright (C) Luke Kenneth Casson Leighton 1996-1998
-
- 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 2 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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "includes.h"
-
-#undef DBGC_CLASS
-#define DBGC_CLASS DBGC_PASSDB
-
-/*
- * NOTE. All these functions are abstracted into a structure
- * that points to the correct function for the selected database. JRA.
- *
- * the API does NOT fill in the gaps if you set an API function
- * to NULL: it will deliberately attempt to call the NULL function.
- *
- */
-
-static struct passgrp_ops *pwgrp_ops;
-
-/***************************************************************
- Initialise the passgrp operations.
-***************************************************************/
-
-BOOL initialise_passgrp_db(void)
-{
- if (pwgrp_ops)
- {
- return True;
- }
-
-#ifdef WITH_NISPLUS
- pwgrp_ops = nisplus_initialise_password_grp();
-#elif defined(WITH_LDAP)
- pwgrp_ops = ldap_initialize_password_grp();
-#else
- pwgrp_ops = file_initialise_password_grp();
-#endif
-
- return (pwgrp_ops != NULL);
-}
-
-/*
- * Functions that return/manipulate a struct smb_passwd.
- */
-
-/************************************************************************
- Utility function to search smb passwd by rid.
-*************************************************************************/
-
-struct smb_passwd *iterate_getsmbgrprid(uint32 user_rid,
- uint32 **grps, int *num_grps,
- uint32 **alss, int *num_alss)
-{
- return iterate_getsmbgrpuid(pwdb_user_rid_to_uid(user_rid),
- grps, num_grps, alss, num_alss);
-}
-
-/************************************************************************
- Utility function to search smb passwd by uid. use this if your database
- does not have search facilities.
-*************************************************************************/
-
-struct smb_passwd *iterate_getsmbgrpuid(uid_t smb_userid,
- uint32 **grps, int *num_grps,
- uint32 **alss, int *num_alss)
-{
- struct smb_passwd *pwd = NULL;
- void *fp = NULL;
-
- DEBUG(10, ("search by smb_userid: %x\n", (int)smb_userid));
-
- /* Open the smb password database - not for update. */
- fp = startsmbgrpent(False);
-
- if (fp == NULL)
- {
- DEBUG(0, ("unable to open smb passgrp database.\n"));
- return NULL;
- }
-
- while ((pwd = getsmbgrpent(fp, grps, num_grps, alss, num_alss)) != NULL && pwd->smb_userid != smb_userid)
- ;
-
- if (pwd != NULL)
- {
- DEBUG(10, ("found by smb_userid: %x\n", (int)smb_userid));
- }
-
- endsmbgrpent(fp);
- return pwd;
-}
-
-/************************************************************************
- Utility function to search smb passwd by name. use this if your database
- does not have search facilities.
-*************************************************************************/
-
-struct smb_passwd *iterate_getsmbgrpnam(char *name,
- uint32 **grps, int *num_grps,
- uint32 **alss, int *num_alss)
-{
- struct smb_passwd *pwd = NULL;
- void *fp = NULL;
-
- DEBUG(10, ("search by name: %s\n", name));
-
- /* Open the passgrp file - not for update. */
- fp = startsmbgrpent(False);
-
- if (fp == NULL)
- {
- DEBUG(0, ("unable to open smb passgrp database.\n"));
- return NULL;
- }
-
- while ((pwd = getsmbgrpent(fp, grps, num_grps, alss, num_alss)) != NULL && !strequal(pwd->smb_name, name))
- ;
-
- if (pwd != NULL)
- {
- DEBUG(10, ("found by name: %s\n", name));
- }
-
- endsmbgrpent(fp);
- return pwd;
-}
-
-/***************************************************************
- Start to enumerate the smb or sam passwd list. Returns a void pointer
- to ensure no modification outside this module.
-
- Note that currently it is being assumed that a pointer returned
- from this function may be used to enumerate struct sam_passwd
- entries as well as struct smb_passwd entries. This may need
- to change. JRA.
-
-****************************************************************/
-
-void *startsmbgrpent(BOOL update)
-{
- return pwgrp_ops->startsmbgrpent(update);
-}
-
-/***************************************************************
- End enumeration of the smb or sam passwd list.
-
- Note that currently it is being assumed that a pointer returned
- from this function may be used to enumerate struct sam_passwd
- entries as well as struct smb_passwd entries. This may need
- to change. JRA.
-
-****************************************************************/
-
-void endsmbgrpent(void *vp)
-{
- pwgrp_ops->endsmbgrpent(vp);
-}
-
-/*************************************************************************
- Routine to return the next entry in the smb passwd list.
- *************************************************************************/
-
-struct smb_passwd *getsmbgrpent(void *vp,
- uint32 **grps, int *num_grps,
- uint32 **alss, int *num_alss)
-{
- return pwgrp_ops->getsmbgrpent(vp, grps, num_grps, alss, num_alss);
-}
-
-/************************************************************************
- Routine to search smb passwd by name.
-*************************************************************************/
-
-struct smb_passwd *getsmbgrpnam(char *name,
- uint32 **grps, int *num_grps,
- uint32 **alss, int *num_alss)
-{
- return pwgrp_ops->getsmbgrpnam(name, grps, num_grps, alss, num_alss);
-}
-
-/************************************************************************
- Routine to search smb passwd by user rid.
-*************************************************************************/
-
-struct smb_passwd *getsmbgrprid(uint32 user_rid,
- uint32 **grps, int *num_grps,
- uint32 **alss, int *num_alss)
-{
- return pwgrp_ops->getsmbgrprid(user_rid, grps, num_grps, alss, num_alss);
-}
-
-/************************************************************************
- Routine to search smb passwd by uid.
-*************************************************************************/
-
-struct smb_passwd *getsmbgrpuid(uid_t smb_userid,
- uint32 **grps, int *num_grps,
- uint32 **alss, int *num_alss)
-{
- return pwgrp_ops->getsmbgrpuid(smb_userid, grps, num_grps, alss, num_alss);
-}
diff --git a/source3/rpc_client/cli_login.c b/source3/rpc_client/cli_login.c
deleted file mode 100644
index 7b5bf90c5d..0000000000
--- a/source3/rpc_client/cli_login.c
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- NT Domain Authentication SMB / MSRPC client
- Copyright (C) Andrew Tridgell 1994-1997
- Copyright (C) Luke Kenneth Casson Leighton 1996-1997
- Copyright (C) Jeremy Allison 1999.
-
- 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 2 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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "includes.h"
-
-extern fstring global_myworkgroup;
-extern pstring global_myname;
-
-/****************************************************************************
-Initialize domain session credentials.
-****************************************************************************/
-
-NTSTATUS cli_nt_setup_creds(struct cli_state *cli, unsigned char mach_pwd[16])
-{
- NTSTATUS result;
- DOM_CHAL clnt_chal;
- DOM_CHAL srv_chal;
-
- UTIME zerotime;
-
- /******************* Request Challenge ********************/
-
- generate_random_buffer( clnt_chal.data, 8, False);
-
- /* send a client challenge; receive a server challenge */
- if (!cli_net_req_chal(cli, &clnt_chal, &srv_chal))
- {
- DEBUG(0,("cli_nt_setup_creds: request challenge failed\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- /**************** Long-term Session key **************/
-
- /* calculate the session key */
- cred_session_key(&clnt_chal, &srv_chal, (char *)mach_pwd, cli->sess_key);
- memset((char *)cli->sess_key+8, '\0', 8);
-
- /******************* Authenticate 2 ********************/
-
- /* calculate auth-2 credentials */
- zerotime.time = 0;
- cred_create(cli->sess_key, &clnt_chal, zerotime, &(cli->clnt_cred.challenge));
-
- /*
- * Send client auth-2 challenge.
- * Receive an auth-2 challenge response and check it.
- */
-
- result = cli_net_auth2(cli, (lp_server_role() == ROLE_DOMAIN_MEMBER) ?
- SEC_CHAN_WKSTA : SEC_CHAN_BDC, 0x000001ff, &srv_chal);
-
- if (!NT_STATUS_IS_OK(result))
- {
- DEBUG(0,("cli_nt_setup_creds: auth2 challenge failed\n"));
- return result;
- }
-
- return NT_STATUS_OK;
-}
-
-/****************************************************************************
-NT login - interactive.
-*NEVER* use this code. This method of doing a logon (sending the cleartext
-password equivalents, protected by the session key) is inherently insecure
-given the current design of the NT Domain system. JRA.
- ****************************************************************************/
-NTSTATUS cli_nt_login_interactive(struct cli_state *cli, char *domain, char *username,
- uint32 smb_userid_low, char *password,
- NET_ID_INFO_CTR *ctr, NET_USER_INFO_3 *user_info3)
-{
- uchar lm_owf_user_pwd[16];
- uchar nt_owf_user_pwd[16];
- NTSTATUS ret;
-
- DEBUG(5,("cli_nt_login_interactive: %d\n", __LINE__));
-
- nt_lm_owf_gen(password, nt_owf_user_pwd, lm_owf_user_pwd);
-
-#ifdef DEBUG_PASSWORD
-
- DEBUG(100,("nt owf of user password: "));
- dump_data(100, (char *)lm_owf_user_pwd, 16);
-
- DEBUG(100,("nt owf of user password: "));
- dump_data(100, (char *)nt_owf_user_pwd, 16);
-
-#endif
-
- DEBUG(5,("cli_nt_login_interactive: %d\n", __LINE__));
-
- /* indicate an "interactive" login */
- ctr->switch_value = INTERACTIVE_LOGON_TYPE;
-
- /* Create the structure needed for SAM logon. */
- init_id_info1(&ctr->auth.id1, domain, 0,
- smb_userid_low, 0,
- username, cli->clnt_name_slash,
- (char *)cli->sess_key, lm_owf_user_pwd, nt_owf_user_pwd);
-
- /* Ensure we overwrite all the plaintext password
- equivalents. */
- memset(lm_owf_user_pwd, '\0', sizeof(lm_owf_user_pwd));
- memset(nt_owf_user_pwd, '\0', sizeof(nt_owf_user_pwd));
-
- /* Send client sam-logon request - update credentials on success. */
- ret = cli_net_sam_logon(cli, ctr, user_info3);
-
- memset(ctr->auth.id1.lm_owf.data, '\0', sizeof(lm_owf_user_pwd));
- memset(ctr->auth.id1.nt_owf.data, '\0', sizeof(nt_owf_user_pwd));
-
- return ret;
-}
-
-/****************************************************************************
-NT login - network.
-*ALWAYS* use this call to validate a user as it does not expose plaintext
-password equivalents over the network. JRA.
-****************************************************************************/
-
-NTSTATUS cli_nt_login_network(struct cli_state *cli,
- const auth_usersupplied_info *user_info,
- uchar chal[8],
- uint32 smb_userid_low, NET_ID_INFO_CTR *ctr,
- NET_USER_INFO_3 *user_info3)
-{
- DEBUG(5,("cli_nt_login_network: %d\n", __LINE__));
- /* indicate a "network" login */
- ctr->switch_value = NET_LOGON_TYPE;
-
- /* Create the structure needed for SAM logon. */
- init_id_info2(&ctr->auth.id2, user_info->domain.str, 0, smb_userid_low, 0,
- user_info->smb_name.str,
- /* Send our cleint's workstaion name if we have it, otherwise ours */
- ((user_info->wksta_name.len > 0) ?
- user_info->wksta_name.str :
- cli->clnt_name_slash),
- chal,
- user_info->lm_resp.data, user_info->lm_resp.length,
- user_info->nt_resp.data, user_info->nt_resp.length);
-
- /* Send client sam-logon request - update credentials on success. */
- return cli_net_sam_logon(cli, ctr, user_info3);
-}
-
-/****************************************************************************
-NT Logoff.
-****************************************************************************/
-BOOL cli_nt_logoff(struct cli_state *cli, NET_ID_INFO_CTR *ctr)
-{
- DEBUG(5,("cli_nt_logoff: %d\n", __LINE__));
-
- /* Send client sam-logoff request - update credentials on success. */
- return cli_net_sam_logoff(cli, ctr);
-}
diff --git a/source3/rpc_client/msrpc_spoolss.c b/source3/rpc_client/msrpc_spoolss.c
deleted file mode 100644
index 56c70730ba..0000000000
--- a/source3/rpc_client/msrpc_spoolss.c
+++ /dev/null
@@ -1,812 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- NT Domain Authentication SMB / MSRPC client
- Copyright (C) Andrew Tridgell 1994-2000
- Copyright (C) Luke Kenneth Casson Leighton 1996-2000
- Copyright (C) Jean-Francois Micouleau 1999-2000
-
- 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 2 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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "includes.h"
-#include "nterr.h"
-#include "rpc_parse.h"
-#include "rpcclient.h"
-
-#undef DBGC_CLASS
-#define DBGC_CLASS DBGC_RPC_CLI
-
-#define DEBUG_TESTING
-
-extern FILE* out_hnd;
-
-extern struct user_creds *usr_creds;
-
-/********************************************************************
-initialize a spoolss NEW_BUFFER.
-********************************************************************/
-void init_buffer(NEW_BUFFER *buffer, uint32 size, TALLOC_CTX *ctx)
-{
- buffer->ptr = (size!=0)? 1:0;
- buffer->size=size;
- buffer->string_at_end=size;
- prs_init(&buffer->prs, size, ctx, MARSHALL);
- buffer->struct_start = prs_offset(&buffer->prs);
-}
-
-static void decode_printer_info_0(NEW_BUFFER *buffer, uint32 returned,
- PRINTER_INFO_0 **info)
-{
- uint32 i;
- PRINTER_INFO_0 *inf;
-
- inf=(PRINTER_INFO_0 *)malloc(returned*sizeof(PRINTER_INFO_0));
-
- buffer->prs.data_offset=0;
-
- for (i=0; i<returned; i++) {
- new_smb_io_printer_info_0("", buffer, &(inf[i]), 0);
- }
-
- *info=inf;
-}
-
-static void decode_printer_info_1(NEW_BUFFER *buffer, uint32 returned,
- PRINTER_INFO_1 **info)
-{
- uint32 i;
- PRINTER_INFO_1 *inf;
-
- inf=(PRINTER_INFO_1 *)malloc(returned*sizeof(PRINTER_INFO_1));
-
- buffer->prs.data_offset=0;
-
- for (i=0; i<returned; i++) {
- new_smb_io_printer_info_1("", buffer, &(inf[i]), 0);
- }
-
- *info=inf;
-}
-
-static void decode_printer_info_2(NEW_BUFFER *buffer, uint32 returned,
- PRINTER_INFO_2 **info)
-{
- uint32 i;
- PRINTER_INFO_2 *inf;
-
- inf=(PRINTER_INFO_2 *)malloc(returned*sizeof(PRINTER_INFO_2));
-
- buffer->prs.data_offset=0;
-
- for (i=0; i<returned; i++) {
- /* a little initialization as we go */
- inf[i].secdesc = NULL;
- new_smb_io_printer_info_2("", buffer, &(inf[i]), 0);
- }
-
- *info=inf;
-}
-
-static void decode_printer_info_3(NEW_BUFFER *buffer, uint32 returned,
- PRINTER_INFO_3 **info)
-{
- uint32 i;
- PRINTER_INFO_3 *inf;
-
- inf=(PRINTER_INFO_3 *)malloc(returned*sizeof(PRINTER_INFO_3));
-
- buffer->prs.data_offset=0;
-
- for (i=0; i<returned; i++) {
- new_smb_io_printer_info_3("", buffer, &(inf[i]), 0);
- }
-
- *info=inf;
-}
-
-static void decode_printer_driver_1(NEW_BUFFER *buffer, uint32 returned,
- DRIVER_INFO_1 **info)
-{
- uint32 i;
- DRIVER_INFO_1 *inf;
-
- inf=(DRIVER_INFO_1 *)malloc(returned*sizeof(DRIVER_INFO_1));
-
- buffer->prs.data_offset=0;
-
- for (i=0; i<returned; i++) {
- new_smb_io_printer_driver_info_1("", buffer, &(inf[i]), 0);
- }
-
- *info=inf;
-}
-
-static void decode_printer_driver_2(NEW_BUFFER *buffer, uint32 returned,
- DRIVER_INFO_2 **info)
-{
- uint32 i;
- DRIVER_INFO_2 *inf;
-
- inf=(DRIVER_INFO_2 *)malloc(returned*sizeof(DRIVER_INFO_2));
-
- buffer->prs.data_offset=0;
-
- for (i=0; i<returned; i++) {
- new_smb_io_printer_driver_info_2("", buffer, &(inf[i]), 0);
- }
-
- *info=inf;
-}
-
-static void decode_printer_driver_3(NEW_BUFFER *buffer, uint32 returned,
- DRIVER_INFO_3 **info)
-{
- uint32 i;
- DRIVER_INFO_3 *inf;
-
- inf=(DRIVER_INFO_3 *)malloc(returned*sizeof(DRIVER_INFO_3));
-
- buffer->prs.data_offset=0;
-
- for (i=0; i<returned; i++) {
- new_smb_io_printer_driver_info_3("", buffer, &(inf[i]), 0);
- }
-
- *info=inf;
-}
-
-static void decode_printerdriverdir_info_1(NEW_BUFFER *buffer, DRIVER_DIRECTORY_1 *info)
-{
-/* DRIVER_DIRECTORY_1 *inf;
-
- inf=(DRIVER_DIRECTORY_1 *)malloc(returned*sizeof(DRIVER_DIRECTORY_1));
-*/
- prs_set_offset(&buffer->prs, 0);
-
- new_smb_io_driverdir_1("", buffer, info, 0);
-
-/* *info=inf;*/
-}
-
-/**********************************************************************
- Decode a PORT_INFO_1 struct from a NEW_BUFFER
-**********************************************************************/
-void decode_port_info_1(NEW_BUFFER *buffer, uint32 returned,
- PORT_INFO_1 **info)
-{
- uint32 i;
- PORT_INFO_1 *inf;
-
- inf=(PORT_INFO_1*)malloc(returned*sizeof(PORT_INFO_1));
-
- prs_set_offset(&buffer->prs, 0);
-
- for (i=0; i<returned; i++) {
- new_smb_io_port_info_1("", buffer, &(inf[i]), 0);
- }
-
- *info=inf;
-}
-
-/**********************************************************************
- Decode a PORT_INFO_2 struct from a NEW_BUFFER
-**********************************************************************/
-void decode_port_info_2(NEW_BUFFER *buffer, uint32 returned,
- PORT_INFO_2 **info)
-{
- uint32 i;
- PORT_INFO_2 *inf;
-
- inf=(PORT_INFO_2*)malloc(returned*sizeof(PORT_INFO_2));
-
- prs_set_offset(&buffer->prs, 0);
-
- for (i=0; i<returned; i++) {
- new_smb_io_port_info_2("", buffer, &(inf[i]), 0);
- }
-
- *info=inf;
-}
-
-
-/****************************************************************************
-nt spoolss query
-****************************************************************************/
-BOOL msrpc_spoolss_enum_printers(char* srv_name, uint32 flags,
- uint32 level, PRINTER_INFO_CTR ctr)
-{
- NTSTATUS status;
- NEW_BUFFER buffer;
- uint32 needed;
- uint32 returned;
- TALLOC_CTX *mem_ctx = NULL;
-
- if ((mem_ctx=talloc_init()) == NULL)
- {
- DEBUG(0,("msrpc_spoolss_enum_printers: talloc_init failed!\n"));
- return False;
- }
- init_buffer(&buffer, 0, mem_ctx);
-
- /* send a NULL buffer first */
- status=spoolss_enum_printers(flags, srv_name, level, &buffer, 0,
- &needed, &returned);
-
- if (status==ERROR_INSUFFICIENT_BUFFER) {
- init_buffer(&buffer, needed, mem_ctx);
- status=spoolss_enum_printers(flags, srv_name, level, &buffer,
- needed, &needed, &returned);
- }
-
- if (status!=NT_STATUS_OK)
- {
- DEBUG(0,("spoolss_enum_printers: %s\n", nt_errstr(status)));
- if (mem_ctx)
- talloc_destroy(mem_ctx);
- return False;
- }
-
- /* is there anything to process? */
- if (returned != 0)
- {
- switch (level) {
- case 1:
- decode_printer_info_1(&buffer, returned, &(ctr.printers_1));
- break;
- case 2:
- decode_printer_info_2(&buffer, returned, &(ctr.printers_2));
- break;
- case 3:
- decode_printer_info_3(&buffer, returned, &(ctr.printers_3));
- break;
- }
-
- display_printer_info_ctr(out_hnd, ACTION_HEADER , level, returned, ctr);
- display_printer_info_ctr(out_hnd, ACTION_ENUMERATE, level, returned, ctr);
- display_printer_info_ctr(out_hnd, ACTION_FOOTER , level, returned, ctr);
- }
-
- if (mem_ctx)
- talloc_destroy(mem_ctx);
-
- return True;
-}
-
-/****************************************************************************
-nt spoolss query
-****************************************************************************/
-BOOL msrpc_spoolss_enum_ports(char* srv_name,
- uint32 level, PORT_INFO_CTR *ctr)
-{
- NTSTATUS status;
- NEW_BUFFER buffer;
- uint32 needed;
- uint32 returned;
- TALLOC_CTX *mem_ctx = NULL;
-
- if ((mem_ctx=talloc_init()) == NULL)
- {
- DEBUG(0,("msrpc_spoolss_enum_ports: talloc_init failed!\n"));
- return False;
- }
-
- init_buffer(&buffer, 0, mem_ctx);
-
- /* send a NULL buffer first */
- status=spoolss_enum_ports(srv_name, level, &buffer, 0,
- &needed, &returned);
-
- if (status==ERROR_INSUFFICIENT_BUFFER) {
- init_buffer(&buffer, needed, mem_ctx);
- status=spoolss_enum_ports(srv_name, level, &buffer,
- needed, &needed, &returned);
- }
-
- report(out_hnd, "\tstatus:[%d (%x)]\n", status, status);
-
- if (status!=NT_STATUS_OK)
- {
- if (mem_ctx)
- talloc_destroy(mem_ctx);
- return False;
- }
-
- /* is there anything to process? */
- if (returned != 0)
- {
- switch (level) {
- case 1:
- decode_port_info_1(&buffer, returned, &ctr->port.info_1);
- break;
- case 2:
- decode_port_info_2(&buffer, returned, &ctr->port.info_2);
- break;
- default:
- DEBUG(0,("Unable to decode unknown PORT_INFO_%d\n", level));
- break;
- }
-
- display_port_info_ctr(out_hnd, ACTION_HEADER , level, returned, ctr);
- display_port_info_ctr(out_hnd, ACTION_ENUMERATE, level, returned, ctr);
- display_port_info_ctr(out_hnd, ACTION_FOOTER , level, returned, ctr);
- }
- if (mem_ctx)
- talloc_destroy(mem_ctx);
-
-
-
- return True;
-}
-
-/****************************************************************************
-nt spoolss query
-****************************************************************************/
-uint32 msrpc_spoolss_getprinterdata( const char* printer_name,
- const char* station,
- const char* user_name,
- const char* value_name,
- uint32 *type,
- NEW_BUFFER *buffer,
- void *fn)
-{
- POLICY_HND hnd;
- NTSTATUS status;
- uint32 needed;
- uint32 size;
- char *data;
- UNISTR2 uni_val_name;
- TALLOC_CTX *mem_ctx = NULL;
-
- DEBUG(4,("spoolgetdata - printer: %s server: %s user: %s value: %s\n",
- printer_name, station, user_name, value_name));
-
- if(!spoolss_open_printer_ex( printer_name, 0, 0, station, user_name,
- &hnd))
- {
- return NT_STATUS_ACCESS_DENIED;
- }
-
- init_unistr2(&uni_val_name, value_name, 0);
- size = 0;
- data = NULL;
-
- if ((mem_ctx=talloc_init()) == NULL)
- {
- DEBUG(0,("msrpc_spoolss_getprinterdata: talloc_init failed!\n"));
- return False;
- }
- init_buffer(buffer, size, mem_ctx);
-
- status = spoolss_getprinterdata(&hnd, &uni_val_name, size, type, &size,
- (unsigned char *)data, &needed);
-
- if (status == ERROR_INSUFFICIENT_BUFFER)
- {
- size = needed;
- init_buffer(buffer, size, mem_ctx);
- data = prs_data_p(&buffer->prs);
- status = spoolss_getprinterdata(&hnd, &uni_val_name,
- size, type, &size,
- (unsigned char *)data, &needed);
- }
-
- if (mem_ctx)
- talloc_destroy(mem_ctx);
-
- if (status != NT_STATUS_OK)
- {
- if (!spoolss_closeprinter(&hnd))
- return NT_STATUS_ACCESS_DENIED;
- return status;
- }
-
-#if 0
- if (fn != NULL)
- fn(printer_name, station, level, returned, *ctr);
-#endif
-
- return status;
-}
-
-/****************************************************************************
-nt spoolss query
-****************************************************************************/
-BOOL msrpc_spoolss_enum_jobs( const char* printer_name,
- const char* station, const char* user_name,
- uint32 level,
- void ***ctr, JOB_INFO_FN(fn))
-{
- POLICY_HND hnd;
- NTSTATUS status;
- NEW_BUFFER buffer;
- uint32 needed;
- uint32 returned;
- uint32 firstjob=0;
- uint32 numofjobs=0xffff;
- TALLOC_CTX *mem_ctx = NULL;
-
- DEBUG(4,("spoolopen - printer: %s server: %s user: %s\n",
- printer_name, station, user_name));
-
- if(!spoolss_open_printer_ex( printer_name, 0, 0, station, user_name, &hnd))
- return False;
-
- if ((mem_ctx=talloc_init()) == NULL)
- {
- DEBUG(0,("msrpc_spoolss_enum_jobs: talloc_init failed!\n"));
- return False;
- }
- init_buffer(&buffer, 0, mem_ctx);
- status = spoolss_enum_jobs(&hnd, firstjob, numofjobs, level,
- &buffer, 0, &needed, &returned);
-
- if (status == ERROR_INSUFFICIENT_BUFFER)
- {
- init_buffer(&buffer, needed, mem_ctx);
- status = spoolss_enum_jobs( &hnd, firstjob, numofjobs, level,
- &buffer, needed, &needed, &returned);
- }
-
- if (mem_ctx)
- talloc_destroy(mem_ctx);
-
- if (status!=NT_STATUS_OK) {
- if (!spoolss_closeprinter(&hnd))
- return False;
- return False;
- }
-
- if (fn != NULL)
- fn(printer_name, station, level, returned, *ctr);
-
- return True;
-}
-
-
-/****************************************************************************
-nt spoolss query
-****************************************************************************/
-BOOL msrpc_spoolss_enum_printerdata( const char* printer_name,
- const char* station, const char* user_name )
-{
- POLICY_HND hnd;
- NTSTATUS status;
- uint32 idx;
- uint32 valuelen;
- uint16 *value;
- uint32 rvaluelen;
- uint32 type;
- uint32 datalen;
- uint8 *data;
- uint32 rdatalen;
- uint32 maxvaluelen;
- uint32 maxdatalen;
-
- DEBUG(4,("msrpc_spoolss_enum_printerdata - printer: %s\n", printer_name));
-
- if(!spoolss_open_printer_ex( printer_name, 0, 0, station, user_name, &hnd))
- return False;
-
-
- idx=0;
- valuelen=0;
- rvaluelen=0;
- type=0;
- datalen=0;
- rdatalen=0;
-
- status = spoolss_enum_printerdata(&hnd, idx, &valuelen, value,
- &rvaluelen, &type, &datalen,
- data, &rdatalen);
-
- DEBUG(4,("spoolenum_printerdata - got size: biggest value:[%d], biggest data:[%d]\n", rvaluelen, rdatalen));
-
- maxvaluelen=valuelen=rvaluelen;
- maxdatalen=datalen=rdatalen;
-
- value=(uint16 *)malloc(valuelen*sizeof(uint16));
- data=(uint8 *)malloc(datalen*sizeof(uint8));
-
- display_printer_enumdata(out_hnd, ACTION_HEADER, idx, valuelen,
- value, rvaluelen, type, datalen, data, rdatalen);
-
- do {
- valuelen=maxvaluelen;
- datalen=maxdatalen;
-
- status = spoolss_enum_printerdata(&hnd, idx, &valuelen,
- value, &rvaluelen, &type,
- &datalen, data, &rdatalen);
- display_printer_enumdata(out_hnd, ACTION_ENUMERATE, idx,
- valuelen, value, rvaluelen, type,
- datalen, data, rdatalen);
- idx++;
-
- } while (status != 0x0103); /* NO_MORE_ITEMS */
-
- display_printer_enumdata(out_hnd, ACTION_FOOTER, idx, valuelen,
- value, rvaluelen, type, datalen, data, rdatalen);
-
-
- if (status!=NT_STATUS_OK) {
- /*
- * the check on this if statement is redundant
- * since is the status is bad we're going to
- * return False anyways. The caller will be
- * unable to determine if there really was a problem
- * with the spoolss_closeprinter() call --jerry
- */
- spoolss_closeprinter(&hnd);
- return False;
- }
-
- return True;
-}
-
-/****************************************************************************
-nt spoolss query
-****************************************************************************/
-BOOL msrpc_spoolss_getprinter( const char* printer_name, const uint32 level,
- const char* station, const char* user_name,
- PRINTER_INFO_CTR ctr)
-{
- POLICY_HND hnd;
- NTSTATUS status=0;
- NEW_BUFFER buffer;
- uint32 needed=1000;
- TALLOC_CTX *mem_ctx = NULL;
-
- DEBUG(4,("spoolenum_getprinter - printer: %s\n", printer_name));
-
- if(!spoolss_open_printer_ex( printer_name, "", PRINTER_ALL_ACCESS, station, user_name, &hnd))
- return False;
-
- if ((mem_ctx=talloc_init()) == NULL)
- {
- DEBUG(0,("msrpc_spoolss_getprinter: talloc_init failed!\n"));
- return False;
- }
- init_buffer(&buffer, needed, mem_ctx);
-
- status = spoolss_getprinter(&hnd, level, &buffer, needed, &needed);
-
- if (status==ERROR_INSUFFICIENT_BUFFER) {
- init_buffer(&buffer, needed, mem_ctx);
- status = spoolss_getprinter(&hnd, level, &buffer, needed, &needed);
- }
-
- report(out_hnd, "\tstatus:[%d (%x)]\n", status, status);
-
- if (status!=NT_STATUS_OK)
- {
- if (mem_ctx)
- talloc_destroy(mem_ctx);
- return False;
- }
-
- switch (level) {
- case 0:
- decode_printer_info_0(&buffer, 1, &(ctr.printers_0));
- break;
- case 1:
- decode_printer_info_1(&buffer, 1, &(ctr.printers_1));
- break;
- case 2:
- decode_printer_info_2(&buffer, 1, &(ctr.printers_2));
- break;
- case 3:
- decode_printer_info_3(&buffer, 1, &(ctr.printers_3));
- break;
- }
-
- display_printer_info_ctr(out_hnd, ACTION_HEADER , level, 1, ctr);
- display_printer_info_ctr(out_hnd, ACTION_ENUMERATE, level, 1, ctr);
- display_printer_info_ctr(out_hnd, ACTION_FOOTER , level, 1, ctr);
-
- if (mem_ctx)
- talloc_destroy(mem_ctx);
-
- if (status!=NT_STATUS_OK) {
- if (!spoolss_closeprinter(&hnd))
- return False;
- return False;
- }
-
- return True;
-}
-
-/****************************************************************************
-nt spoolss query
-****************************************************************************/
-BOOL msrpc_spoolss_getprinterdriver( const char* printer_name,
- const char *environment, const uint32 level,
- const char* station, const char* user_name,
- PRINTER_DRIVER_CTR ctr)
-{
- POLICY_HND hnd;
- NTSTATUS status=0;
- NEW_BUFFER buffer;
- uint32 needed;
- TALLOC_CTX *mem_ctx = NULL;
-
- DEBUG(4,("msrpc_spoolss_enum_getprinterdriver - printer: %s\n", printer_name));
-
- if(!spoolss_open_printer_ex( printer_name, "", PRINTER_ALL_ACCESS, station, user_name, &hnd))
- return False;
-
- if ((mem_ctx=talloc_init()) == NULL)
- {
- DEBUG(0,("msrpc_spoolss_getprinterdriver: talloc_init failed!\n"));
- return False;
- }
- init_buffer(&buffer, 0, mem_ctx);
-
- status = spoolss_getprinterdriver(&hnd, environment, level, &buffer, 0, &needed);
-
- if (status==ERROR_INSUFFICIENT_BUFFER) {
- init_buffer(&buffer, needed, mem_ctx);
- status = spoolss_getprinterdriver(&hnd, environment, level, &buffer, needed, &needed);
- }
-
- /* report(out_hnd, "\tstatus:[%d (%x)]\n", status, status); */
-
- if (status!=NT_STATUS_OK)
- {
- if (mem_ctx)
- talloc_destroy(mem_ctx);
- return False;
- }
-
- switch (level) {
- case 1:
- decode_printer_driver_1(&buffer, 1, &(ctr.info1));
- break;
- case 2:
- decode_printer_driver_2(&buffer, 1, &(ctr.info2));
- break;
- case 3:
- decode_printer_driver_3(&buffer, 1, &(ctr.info3));
- break;
- }
-
- display_printer_driver_ctr(out_hnd, ACTION_HEADER , level, 1, ctr);
- display_printer_driver_ctr(out_hnd, ACTION_ENUMERATE, level, 1, ctr);
- display_printer_driver_ctr(out_hnd, ACTION_FOOTER , level, 1, ctr);
-
- if (mem_ctx)
- talloc_destroy(mem_ctx);
-
- if (status!=NT_STATUS_OK) {
- if (!spoolss_closeprinter(&hnd))
- return False;
- return False;
- }
-
- return True;
-}
-
-/****************************************************************************
-nt spoolss query
-****************************************************************************/
-BOOL msrpc_spoolss_enumprinterdrivers( const char* srv_name,
- const char *environment, const uint32 level,
- PRINTER_DRIVER_CTR ctr)
-{
- NTSTATUS status=0;
- NEW_BUFFER buffer;
- uint32 needed;
- uint32 returned;
- TALLOC_CTX *mem_ctx = NULL;
-
- DEBUG(4,("msrpc_spoolss_enum_enumprinterdrivers - server: %s\n", srv_name));
-
- if ((mem_ctx=talloc_init()) == NULL)
- {
- DEBUG(0,("msrpc_spoolss_enumprinterdrivers: talloc_init failed!\n"));
- return False;
- }
- init_buffer(&buffer, 0, mem_ctx);
-
- status = spoolss_enum_printerdrivers(srv_name, environment,
- level, &buffer, 0, &needed, &returned);
-
- if (status == ERROR_INSUFFICIENT_BUFFER)
- {
- init_buffer(&buffer, needed, mem_ctx);
- status = spoolss_enum_printerdrivers( srv_name, environment,
- level, &buffer, needed, &needed, &returned);
- }
-
- report(out_hnd, "\tstatus:[%d (%x)]\n", status, status);
-
- if (status!=NT_STATUS_OK)
- {
- if (mem_ctx)
- talloc_destroy(mem_ctx);
- return False;
- }
-
- switch (level)
- {
- case 1:
- decode_printer_driver_1(&buffer, returned, &(ctr.info1));
- break;
- case 2:
- decode_printer_driver_2(&buffer, returned, &(ctr.info2));
- break;
- case 3:
- decode_printer_driver_3(&buffer, returned, &(ctr.info3));
- break;
- }
-
- display_printer_driver_ctr(out_hnd, ACTION_HEADER , level, returned, ctr);
- display_printer_driver_ctr(out_hnd, ACTION_ENUMERATE, level, returned, ctr);
- display_printer_driver_ctr(out_hnd, ACTION_FOOTER , level, returned, ctr);
-
- if (mem_ctx)
- talloc_destroy(mem_ctx);
-
- return True;
-}
-
-/****************************************************************************
-nt spoolss query
-****************************************************************************/
-BOOL msrpc_spoolss_getprinterdriverdir(char* srv_name, char* env_name, uint32 level, DRIVER_DIRECTORY_CTR ctr)
-{
- NTSTATUS status;
- NEW_BUFFER buffer;
- uint32 needed;
- TALLOC_CTX *mem_ctx = NULL;
-
- if ((mem_ctx=talloc_init()) == NULL)
- {
- DEBUG(0,("msrpc_spoolss_getprinterdriverdir: talloc_init failed!\n"));
- return False;
- }
- init_buffer(&buffer, 0, mem_ctx);
-
- /* send a NULL buffer first */
- status=spoolss_getprinterdriverdir(srv_name, env_name, level, &buffer, 0, &needed);
-
- if (status==ERROR_INSUFFICIENT_BUFFER) {
- init_buffer(&buffer, needed, mem_ctx);
- status=spoolss_getprinterdriverdir(srv_name, env_name, level, &buffer, needed, &needed);
- }
-
- report(out_hnd, "\tstatus:[%d (%x)]\n", status, status);
-
- if (status!=NT_STATUS_OK)
- {
- if (mem_ctx)
- talloc_destroy(mem_ctx);
- return False;
- }
-
- switch (level) {
- case 1:
- decode_printerdriverdir_info_1(&buffer, &(ctr.driver.info_1));
- break;
- }
-
- display_printerdriverdir_info_ctr(out_hnd, ACTION_HEADER , level, ctr);
- display_printerdriverdir_info_ctr(out_hnd, ACTION_ENUMERATE, level, ctr);
- display_printerdriverdir_info_ctr(out_hnd, ACTION_FOOTER , level, ctr);
-
- if (mem_ctx)
- talloc_destroy(mem_ctx);
-
- return True;
-}
diff --git a/source3/rpc_client/ntclienttrust.c b/source3/rpc_client/ntclienttrust.c
deleted file mode 100644
index 284fd491f8..0000000000
--- a/source3/rpc_client/ntclienttrust.c
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- NT Domain Authentication SMB / MSRPC client
- Copyright (C) Andrew Tridgell 1994-1997
- Copyright (C) Luke Kenneth Casson Leighton 1996-1997
-
- 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 2 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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#include "includes.h"
-
-
-/************************************************************************
- check workstation trust account status
- ************************************************************************/
-BOOL trust_account_check(struct in_addr dest_ip, char *dest_host,
- char *hostname, char *domain, fstring mach_acct,
- fstring new_mach_pwd)
-{
- pstring tmp;
- fstring mach_pwd;
- struct cli_state cli_trust;
- uchar lm_owf_mach_pwd[16];
- uchar nt_owf_mach_pwd[16];
- uchar lm_sess_pwd[24];
- uchar nt_sess_pwd[24];
-
- BOOL right_error_code = False;
- uint8 err_cls;
- uint32 err_num;
-
- char *start_mach_pwd;
- char *change_mach_pwd;
-
- /* initial machine password */
- fstrcpy(mach_pwd, hostname);
- strlower(mach_pwd);
-
- slprintf(tmp, sizeof(tmp) - 1,"Enter Workstation Trust Account password for [%s].\nDefault is [%s].\nPassword:",
- mach_acct, mach_pwd);
-
- start_mach_pwd = (char*)getpass(tmp);
-
- if (start_mach_pwd[0] != 0)
- {
- fstrcpy(mach_pwd, start_mach_pwd);
- }
-
- slprintf(tmp, sizeof(tmp)-1, "Enter new Workstation Trust Account password for [%s]\nPress Return to leave at old value.\nNew Password:",
- mach_acct);
-
- change_mach_pwd = (char*)getpass(tmp);
-
- if (change_mach_pwd[0] != 0)
- {
- fstrcpy(new_mach_pwd, change_mach_pwd);
- }
- else
- {
- DEBUG(1,("trust_account_check: password change not requested\n"));
- change_mach_pwd[0] = 0;
- }
-
- DEBUG(1,("initialise cli_trust connection\n"));
-
- if (!cli_initialise(&cli_trust))
- {
- DEBUG(1,("cli_initialise failed for cli_trust\n"));
- return False;
- }
-
- DEBUG(1,("server connect for cli_trust\n"));
-
- if (!server_connect_init(&cli_trust, hostname, dest_ip, dest_host))
- {
- cli_error(&cli_trust, &err_cls, &err_num, NULL);
- DEBUG(1,("server_connect_init failed (%s)\n", cli_errstr(&cli_trust)));
-
- cli_shutdown(&cli_trust);
- return False;
- }
-
- DEBUG(1,("server connect cli_trust succeeded\n"));
-
- nt_lm_owf_gen(mach_pwd, nt_owf_mach_pwd, lm_owf_mach_pwd);
-
- DEBUG(5,("generating nt owf from initial machine pwd: %s\n", mach_pwd));
-
-#ifdef DEBUG_PASSWORD
- DEBUG(100,("client cryptkey: "));
- dump_data(100, cli_trust.cryptkey, sizeof(cli_trust.cryptkey));
-#endif
-
- SMBencrypt(nt_owf_mach_pwd, cli_trust.cryptkey, nt_sess_pwd);
-
-#ifdef DEBUG_PASSWORD
- DEBUG(100,("nt_owf_mach_pwd: "));
- dump_data(100, nt_owf_mach_pwd, sizeof(lm_owf_mach_pwd));
- DEBUG(100,("nt_sess_pwd: "));
- dump_data(100, nt_sess_pwd, sizeof(nt_sess_pwd));
-#endif
-
- SMBencrypt(lm_owf_mach_pwd, cli_trust.cryptkey, lm_sess_pwd);
-
-#ifdef DEBUG_PASSWORD
- DEBUG(100,("lm_owf_mach_pwd: "));
- dump_data(100, lm_owf_mach_pwd, sizeof(lm_owf_mach_pwd));
- DEBUG(100,("lm_sess_pwd: "));
- dump_data(100, lm_sess_pwd, sizeof(lm_sess_pwd));
-#endif
-
- right_error_code = False;
-
- if (cli_session_setup(&cli_trust, mach_acct,
- nt_owf_mach_pwd, sizeof(nt_owf_mach_pwd),
- nt_owf_mach_pwd, sizeof(nt_owf_mach_pwd), domain))
- {
- DEBUG(0,("cli_session_setup: NO ERROR! AAAGH! BUG IN SERVER DETECTED!!!\n"));
- cli_shutdown(&cli_trust);
-
- return False;
- }
-
- cli_error(&cli_trust, &err_cls, &err_num, NULL);
-
- if (err_num == (0xC0000000 | NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT))
- {
- DEBUG(1,("cli_send_tconX: valid workstation trust account exists\n"));
- right_error_code = True;
- }
-
- if (err_num == (0xC0000000 | NT_STATUS_NO_SUCH_USER))
- {
- DEBUG(1,("cli_send_tconX: workstation trust account does not exist\n"));
- right_error_code = False;
- }
-
- if (!right_error_code)
- {
- DEBUG(1,("server_validate failed (%s)\n", cli_errstr(&cli_trust)));
- }
-
- cli_shutdown(&cli_trust);
- return right_error_code;
-}
diff --git a/source3/smbd/ssl.c b/source3/smbd/ssl.c
deleted file mode 100644
index 7fcb48a954..0000000000
--- a/source3/smbd/ssl.c
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- SSLeay utility functions
- Copyright (C) Christian Starkjohann <cs@obdev.at> 1998
-
- 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 2 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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-/*
- * since includes.h pulls in config.h which is were WITH_SSL will be
- * defined, we want to include includes.h before testing for WITH_SSL
- * RJS 26-Jan-1999
- */
-
-#include "includes.h"
-
-#ifdef WITH_SSL /* should always be defined if this module is compiled */
-
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-
-BOOL sslEnabled;
-SSL *ssl = NULL;
-int sslFd = -1;
-static SSL_CTX *sslContext = NULL;
-extern int DEBUGLEVEL;
-
-static int ssl_verify_cb(int ok, X509_STORE_CTX *ctx)
-{
-char buffer[256];
-
- X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),
- buffer, sizeof(buffer));
- if(ok){
- DEBUG(0, ("SSL: Certificate OK: %s\n", buffer));
- }else{
- switch (ctx->error){
- case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
- DEBUG(0, ("SSL: Cert error: CA not known: %s\n", buffer));
- break;
- case X509_V_ERR_CERT_NOT_YET_VALID:
- DEBUG(0, ("SSL: Cert error: Cert not yet valid: %s\n", buffer));
- break;
- case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
- DEBUG(0, ("SSL: Cert error: illegal \'not before\' field: %s\n",
- buffer));
- break;
- case X509_V_ERR_CERT_HAS_EXPIRED:
- DEBUG(0, ("SSL: Cert error: Cert expired: %s\n", buffer));
- break;
- case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
- DEBUG(0, ("SSL: Cert error: invalid \'not after\' field: %s\n",
- buffer));
- break;
- default:
- DEBUG(0, ("SSL: Cert error: unknown error %d in %s\n", ctx->error,
- buffer));
- break;
- }
- }
- return ok;
-}
-
-static RSA *ssl_temp_rsa_cb(SSL *ssl, int is_export, int keylength)
-{
-static RSA *rsa = NULL;
-
- if(rsa == NULL)
- rsa = RSA_generate_key(keylength, RSA_F4, NULL, NULL);
- return rsa;
-}
-
-/* This is called before we fork. It should ask the user for the pass phrase
- * if necessary. Error output can still go to stderr because the process
- * has a terminal.
- */
-int sslutil_init(int isServer)
-{
-int err, entropybytes;
-char *certfile, *keyfile, *ciphers, *cacertDir, *cacertFile;
-char *egdsocket, *entropyfile;
-
- SSL_load_error_strings();
- SSLeay_add_ssl_algorithms();
- egdsocket = lp_ssl_egdsocket();
- if (egdsocket != NULL && *egdsocket != 0)
- RAND_egd(egdsocket);
- entropyfile = lp_ssl_entropyfile();
- entropybytes = lp_ssl_entropybytes();
- if (entropyfile != NULL && *entropyfile != 0)
- RAND_load_file(entropyfile, entropybytes);
- switch(lp_ssl_version()){
- case SMB_SSL_V2: sslContext = SSL_CTX_new(SSLv2_method()); break;
- case SMB_SSL_V3: sslContext = SSL_CTX_new(SSLv3_method()); break;
- default:
- case SMB_SSL_V23: sslContext = SSL_CTX_new(SSLv23_method()); break;
- case SMB_SSL_TLS1: sslContext = SSL_CTX_new(TLSv1_method()); break;
- }
- if(sslContext == NULL){
- err = ERR_get_error();
- fprintf(stderr, "SSL: Error allocating context: %s\n",
- ERR_error_string(err, NULL));
- exit(1);
- }
- if(lp_ssl_compatibility()){
- SSL_CTX_set_options(sslContext, SSL_OP_ALL);
- }
- certfile = isServer ? lp_ssl_server_cert() : lp_ssl_client_cert();
- if((certfile == NULL || *certfile == 0) && isServer){
- fprintf(stderr, "SSL: No cert file specified in config file!\n");
- fprintf(stderr, "The server MUST have a certificate!\n");
- exit(1);
- }
- keyfile = isServer ? lp_ssl_server_privkey() : lp_ssl_client_privkey();
- if(keyfile == NULL || *keyfile == 0)
- keyfile = certfile;
- if(certfile != NULL && *certfile != 0){
- if(!SSL_CTX_use_certificate_chain_file(sslContext, certfile)){
- err = ERR_get_error();
- fprintf(stderr, "SSL: error reading certificate from file %s: %s\n",
- certfile, ERR_error_string(err, NULL));
- exit(1);
- }
- if(!SSL_CTX_use_PrivateKey_file(sslContext, keyfile, SSL_FILETYPE_PEM)){
- err = ERR_get_error();
- fprintf(stderr, "SSL: error reading private key from file %s: %s\n",
- keyfile, ERR_error_string(err, NULL));
- exit(1);
- }
- if(!SSL_CTX_check_private_key(sslContext)){
- err = ERR_get_error();
- fprintf(stderr, "SSL: Private key does not match public key in cert!\n");
- exit(1);
- }
- }
- cacertDir = lp_ssl_cacertdir();
- cacertFile = lp_ssl_cacertfile();
- if(cacertDir != NULL && *cacertDir == 0)
- cacertDir = NULL;
- if(cacertFile != NULL && *cacertFile == 0)
- cacertFile = NULL;
- if(!SSL_CTX_load_verify_locations(sslContext, cacertFile, cacertDir)){
- err = ERR_get_error();
- if (cacertFile || cacertDir) {
- fprintf(stderr, "SSL: Error error setting CA cert locations: %s\n",
- ERR_error_string(err, NULL));
- fprintf(stderr, "trying default locations.\n");
- }
- cacertFile = cacertDir = NULL;
- if(!SSL_CTX_set_default_verify_paths(sslContext)){
- err = ERR_get_error();
- fprintf(stderr, "SSL: Error error setting default CA cert location: %s\n",
- ERR_error_string(err, NULL));
- exit(1);
- }
- }
- SSL_CTX_set_tmp_rsa_callback(sslContext, ssl_temp_rsa_cb);
- if((ciphers = lp_ssl_ciphers()) != NULL && *ciphers != 0)
- SSL_CTX_set_cipher_list(sslContext, ciphers);
- if((isServer && lp_ssl_reqClientCert()) || (!isServer && lp_ssl_reqServerCert())){
- SSL_CTX_set_verify(sslContext,
- SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, ssl_verify_cb);
- }else{
- SSL_CTX_set_verify(sslContext, SSL_VERIFY_NONE, ssl_verify_cb);
- }
-#if 1 /* don't know what this is good for, but s_server in SSLeay does it, too */
- if(isServer){
- SSL_CTX_set_client_CA_list(sslContext, SSL_load_client_CA_file(certfile));
- }
-#endif
- return 0;
-}
-
-int sslutil_accept(int fd)
-{
-int err;
-
- if(ssl != NULL){
- DEBUG(0, ("SSL: internal error: more than one SSL connection (server)\n"));
- return -1;
- }
- if((ssl = SSL_new(sslContext)) == NULL){
- err = ERR_get_error();
- DEBUG(0, ("SSL: Error allocating handle: %s\n",
- ERR_error_string(err, NULL)));
- return -1;
- }
- SSL_set_fd(ssl, fd);
- sslFd = fd;
- if(SSL_accept(ssl) <= 0){
- err = ERR_get_error();
- DEBUG(0, ("SSL: Error accepting on socket: %s\n",
- ERR_error_string(err, NULL)));
- return -1;
- }
- DEBUG(0, ("SSL: negotiated cipher: %s\n", SSL_get_cipher(ssl)));
- return 0;
-}
-
-int sslutil_fd_is_ssl(int fd)
-{
- return fd == sslFd;
-}
-
-int sslutil_connect(int fd)
-{
-int err;
-
- if(ssl != NULL){
- DEBUG(0, ("SSL: internal error: more than one SSL connection (client)\n"));
- return -1;
- }
- if((ssl = SSL_new(sslContext)) == NULL){
- err = ERR_get_error();
- DEBUG(0, ("SSL: Error allocating handle: %s\n",
- ERR_error_string(err, NULL)));
- return -1;
- }
- SSL_set_fd(ssl, fd);
- sslFd = fd;
- if(SSL_connect(ssl) <= 0){
- err = ERR_get_error();
- DEBUG(0, ("SSL: Error conencting socket: %s\n",
- ERR_error_string(err, NULL)));
- return -1;
- }
- DEBUG(0, ("SSL: negotiated cipher: %s\n", SSL_get_cipher(ssl)));
- return 0;
-}
-
-int sslutil_disconnect(int fd)
-{
- if(fd == sslFd && ssl != NULL){
- SSL_free(ssl);
- ssl = NULL;
- sslFd = -1;
- }
- return 0;
-}
-
-int sslutil_negotiate_ssl(int fd, int msg_type)
-{
-unsigned char buf[5] = {0x83, 0, 0, 1, 0x81};
-char *reqHosts, *resignHosts;
-
- reqHosts = lp_ssl_hosts();
- resignHosts = lp_ssl_hosts_resign();
- if(!allow_access(resignHosts, reqHosts, get_socket_name(fd), get_socket_addr(fd))){
- sslEnabled = False;
- return 0;
- }
- if(msg_type != 0x81){ /* first packet must be a session request */
- DEBUG( 0, ( "Client %s did not use session setup; access denied\n",
- client_addr() ) );
- if (!send_smb(fd, (char *)buf))
- DEBUG(0, ("sslutil_negotiate_ssl: send_smb failed.\n"));
- return -1;
- }
- buf[4] = 0x8e; /* negative session response: use SSL */
- if (!send_smb(fd, (char *)buf)) {
- DEBUG(0,("sslutil_negotiate_ssl: send_smb failed.\n"));
- return -1;
- }
- if(sslutil_accept(fd) != 0){
- DEBUG( 0, ( "Client %s failed SSL negotiation!\n", client_addr() ) );
- return -1;
- }
- return 1;
-}
-
-#else /* WITH_SSL */
- void ssl_dummy(void);
- void ssl_dummy(void) {;} /* So some compilers don't complain. */
-#endif /* WITH_SSL */