s4-netlogon: implement dcesrv_netr_DsRAddressToSitenamesExW
[Samba/aatanasov.git] / source3 / smbd / signing.c
blob9b5e3452f9d32c5eda7eb73b51498aca6bdf7f6d
1 /*
2 Unix SMB/CIFS implementation.
3 SMB Signing Code
4 Copyright (C) Jeremy Allison 2003.
5 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2002-2003
6 Copyright (C) Stefan Metzmacher 2009
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "smbd/globals.h"
26 /***********************************************************
27 Called to validate an incoming packet from the client.
28 ************************************************************/
30 bool srv_check_sign_mac(struct smbd_server_connection *conn,
31 const char *inbuf, uint32_t *seqnum)
33 /* Check if it's a non-session message. */
34 if(CVAL(inbuf,0)) {
35 return true;
38 *seqnum = smb_signing_next_seqnum(conn->smb1.signing_state, false);
39 return smb_signing_check_pdu(conn->smb1.signing_state,
40 (const uint8_t *)inbuf,
41 *seqnum);
44 /***********************************************************
45 Called to sign an outgoing packet to the client.
46 ************************************************************/
48 void srv_calculate_sign_mac(struct smbd_server_connection *conn,
49 char *outbuf, uint32_t seqnum)
51 /* Check if it's a non-session message. */
52 if(CVAL(outbuf,0)) {
53 return;
56 smb_signing_sign_pdu(conn->smb1.signing_state, (uint8_t *)outbuf, seqnum);
60 /***********************************************************
61 Called to indicate a oneway request
62 ************************************************************/
63 void srv_cancel_sign_response(struct smbd_server_connection *conn)
65 smb_signing_cancel_reply(conn->smb1.signing_state, true);
68 /***********************************************************
69 Called by server negprot when signing has been negotiated.
70 ************************************************************/
72 bool srv_init_signing(struct smbd_server_connection *conn)
74 bool allowed = true;
75 bool mandatory = false;
77 switch (lp_server_signing()) {
78 case Required:
79 mandatory = true;
80 break;
81 case Auto:
82 break;
83 case True:
84 break;
85 case False:
86 allowed = false;
87 break;
90 conn->smb1.signing_state = smb_signing_init(smbd_event_context(),
91 allowed, mandatory);
92 if (!conn->smb1.signing_state) {
93 return false;
96 return true;
99 void srv_set_signing_negotiated(struct smbd_server_connection *conn)
101 smb_signing_set_negotiated(conn->smb1.signing_state);
104 /***********************************************************
105 Returns whether signing is active. We can't use sendfile or raw
106 reads/writes if it is.
107 ************************************************************/
109 bool srv_is_signing_active(struct smbd_server_connection *conn)
111 return smb_signing_is_active(conn->smb1.signing_state);
115 /***********************************************************
116 Returns whether signing is negotiated. We can't use it unless it was
117 in the negprot.
118 ************************************************************/
120 bool srv_is_signing_negotiated(struct smbd_server_connection *conn)
122 return smb_signing_is_negotiated(conn->smb1.signing_state);
125 /***********************************************************
126 Turn on signing from this packet onwards.
127 ************************************************************/
129 void srv_set_signing(struct smbd_server_connection *conn,
130 const DATA_BLOB user_session_key,
131 const DATA_BLOB response)
133 bool negotiated;
134 bool mandatory;
136 if (!user_session_key.length)
137 return;
139 negotiated = smb_signing_is_negotiated(conn->smb1.signing_state);
140 mandatory = smb_signing_is_mandatory(conn->smb1.signing_state);
142 if (!negotiated && !mandatory) {
143 DEBUG(5,("srv_set_signing: signing negotiated = %u, "
144 "mandatory_signing = %u. Not allowing smb signing.\n",
145 negotiated, mandatory));
146 return;
149 if (!smb_signing_activate(conn->smb1.signing_state,
150 user_session_key, response)) {
151 return;
154 DEBUG(3,("srv_set_signing: turning on SMB signing: "
155 "signing negotiated = %u, mandatory_signing = %u.\n",
156 negotiated, mandatory));