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
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
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.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
-#include "auth/auth.h"
#include "auth/ntlmssp/ntlmssp.h"
#include "auth/ntlmssp/msrpc_parse.h"
#include "librpc/gen_ndr/ndr_dcerpc.h"
+#include "auth/credentials/credentials.h"
+#include "auth/gensec/gensec.h"
+#include "auth/auth.h"
/**
* Callbacks for NTLMSSP - for both client and server operating modes
static const struct ntlmssp_callbacks {
enum ntlmssp_role role;
- enum ntlmssp_message_type ntlmssp_command;
- NTSTATUS (*fn)(struct gensec_security *gensec_security,
- TALLOC_CTX *out_mem_ctx,
- DATA_BLOB in, DATA_BLOB *out);
+ enum ntlmssp_message_type command;
+ NTSTATUS (*sync_fn)(struct gensec_security *gensec_security,
+ TALLOC_CTX *out_mem_ctx,
+ DATA_BLOB in, DATA_BLOB *out);
} ntlmssp_callbacks[] = {
- {NTLMSSP_CLIENT, NTLMSSP_INITIAL, ntlmssp_client_initial},
- {NTLMSSP_SERVER, NTLMSSP_NEGOTIATE, ntlmssp_server_negotiate},
- {NTLMSSP_CLIENT, NTLMSSP_CHALLENGE, ntlmssp_client_challenge},
- {NTLMSSP_SERVER, NTLMSSP_AUTH, ntlmssp_server_auth},
+ {
+ .role = NTLMSSP_CLIENT,
+ .command = NTLMSSP_INITIAL,
+ .sync_fn = ntlmssp_client_initial,
+ },{
+ .role = NTLMSSP_SERVER,
+ .command = NTLMSSP_NEGOTIATE,
+ .sync_fn = ntlmssp_server_negotiate,
+ },{
+ .role = NTLMSSP_CLIENT,
+ .command = NTLMSSP_CHALLENGE,
+ .sync_fn = ntlmssp_client_challenge,
+ },{
+ .role = NTLMSSP_SERVER,
+ .command = NTLMSSP_AUTH,
+ .sync_fn = ntlmssp_server_auth,
+ }
};
}
}
-/**
- * Next state function for the wrapped NTLMSSP state machine
- *
- * @param gensec_security GENSEC state, initialised to NTLMSSP
- * @param out_mem_ctx The TALLOC_CTX for *out to be allocated on
- * @param in The request, as a DATA_BLOB
- * @param out The reply, as an talloc()ed DATA_BLOB, on *out_mem_ctx
- * @return Error, MORE_PROCESSING_REQUIRED if a reply is sent,
- * or NT_STATUS_OK if the user is authenticated.
- */
-
-static NTSTATUS gensec_ntlmssp_update(struct gensec_security *gensec_security,
- TALLOC_CTX *out_mem_ctx,
- const DATA_BLOB input, DATA_BLOB *out)
+static NTSTATUS gensec_ntlmssp_update_find(struct gensec_ntlmssp_state *gensec_ntlmssp_state,
+ const DATA_BLOB input, uint32_t *idx)
{
- struct gensec_ntlmssp_state *gensec_ntlmssp_state = gensec_security->private_data;
- NTSTATUS status;
-
+ struct gensec_security *gensec_security = gensec_ntlmssp_state->gensec_security;
uint32_t ntlmssp_command;
- int i;
-
- *out = data_blob(NULL, 0);
+ uint32_t i;
if (gensec_ntlmssp_state->expected_state == NTLMSSP_DONE) {
/* We are strict here because other modules, which we
return NT_STATUS_INVALID_PARAMETER;
}
- if (!out_mem_ctx) {
- /* if the caller doesn't want to manage/own the memory,
- we can put it on our context */
- out_mem_ctx = gensec_ntlmssp_state;
- }
-
if (!input.length) {
switch (gensec_ntlmssp_state->role) {
case NTLMSSP_CLIENT:
}
for (i=0; i < ARRAY_SIZE(ntlmssp_callbacks); i++) {
- if (ntlmssp_callbacks[i].role == gensec_ntlmssp_state->role
- && ntlmssp_callbacks[i].ntlmssp_command == ntlmssp_command) {
- status = ntlmssp_callbacks[i].fn(gensec_security, out_mem_ctx, input, out);
- break;
+ if (ntlmssp_callbacks[i].role == gensec_ntlmssp_state->role &&
+ ntlmssp_callbacks[i].command == ntlmssp_command) {
+ *idx = i;
+ return NT_STATUS_OK;
}
}
- if (i == ARRAY_SIZE(ntlmssp_callbacks)) {
-
- DEBUG(1, ("failed to find NTLMSSP callback for NTLMSSP mode %u, command %u\n",
- gensec_ntlmssp_state->role, ntlmssp_command));
+ DEBUG(1, ("failed to find NTLMSSP callback for NTLMSSP mode %u, command %u\n",
+ gensec_ntlmssp_state->role, ntlmssp_command));
- return NT_STATUS_INVALID_PARAMETER;
- }
+ return NT_STATUS_INVALID_PARAMETER;
+}
- if (!NT_STATUS_IS_OK(status)) {
- /* error or more processing required */
- return status;
+/**
+ * Next state function for the wrapped NTLMSSP state machine
+ *
+ * @param gensec_security GENSEC state, initialised to NTLMSSP
+ * @param out_mem_ctx The TALLOC_CTX for *out to be allocated on
+ * @param in The request, as a DATA_BLOB
+ * @param out The reply, as an talloc()ed DATA_BLOB, on *out_mem_ctx
+ * @return Error, MORE_PROCESSING_REQUIRED if a reply is sent,
+ * or NT_STATUS_OK if the user is authenticated.
+ */
+
+static NTSTATUS gensec_ntlmssp_update(struct gensec_security *gensec_security,
+ TALLOC_CTX *out_mem_ctx,
+ const DATA_BLOB input, DATA_BLOB *out)
+{
+ struct gensec_ntlmssp_state *gensec_ntlmssp_state = gensec_security->private_data;
+ NTSTATUS status;
+ uint32_t i;
+
+ *out = data_blob(NULL, 0);
+
+ if (!out_mem_ctx) {
+ /* if the caller doesn't want to manage/own the memory,
+ we can put it on our context */
+ out_mem_ctx = gensec_ntlmssp_state;
}
+
+ status = gensec_ntlmssp_update_find(gensec_ntlmssp_state, input, &i);
+ NT_STATUS_NOT_OK_RETURN(status);
+
+ status = ntlmssp_callbacks[i].sync_fn(gensec_security, out_mem_ctx, input, out);
+ NT_STATUS_NOT_OK_RETURN(status);
- return status;
+ return NT_STATUS_OK;
}
/**
gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_LM_KEY;
}
- if (neg_flags & NTLMSSP_NEGOTIATE_ALWAYS_SIGN) {
- gensec_ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_ALWAYS_SIGN;
+ if (!(neg_flags & NTLMSSP_NEGOTIATE_ALWAYS_SIGN)) {
+ gensec_ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_ALWAYS_SIGN;
}
if (!(neg_flags & NTLMSSP_NEGOTIATE_SIGN)) {
.session_key = gensec_ntlmssp_session_key,
.session_info = gensec_ntlmssp_session_info,
.have_feature = gensec_ntlmssp_have_feature,
- .enabled = True
+ .enabled = True,
+ .priority = GENSEC_NTLMSSP
};