LCOV - code coverage report
Current view: top level - source4/auth/ntlm - auth_developer.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 5 89 5.6 %
Date: 2024-04-21 15:09:00 Functions: 1 5 20.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    Generic authentication types
       4             :    Copyright (C) Andrew Bartlett         2001-2002
       5             :    Copyright (C) Jelmer Vernooij              2002
       6             :    Copyright (C) Stefan Metzmacher            2005
       7             :    
       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.
      12             :    
      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.
      17             :    
      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/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include <tevent.h>
      24             : #include "auth/auth.h"
      25             : #include "auth/ntlm/auth_proto.h"
      26             : #include "libcli/security/security.h"
      27             : #include "lib/util/tevent_ntstatus.h"
      28             : 
      29             : #undef DBGC_CLASS
      30             : #define DBGC_CLASS DBGC_AUTH
      31             : 
      32             : #undef strncasecmp
      33             : 
      34             : _PUBLIC_ NTSTATUS auth4_developer_init(TALLOC_CTX *);
      35             : 
      36           0 : static NTSTATUS name_to_ntstatus_want_check(struct auth_method_context *ctx,
      37             :                                             TALLOC_CTX *mem_ctx,
      38             :                                             const struct auth_usersupplied_info *user_info)
      39             : {
      40           0 :         return NT_STATUS_OK;
      41             : }
      42             : 
      43             : /** 
      44             :  * Return an error based on username
      45             :  *
      46             :  * This function allows the testing of obscure errors, as well as the generation
      47             :  * of NT_STATUS -> DOS error mapping tables.
      48             :  *
      49             :  * This module is of no value to end-users.
      50             :  *
      51             :  * The password is ignored.
      52             :  *
      53             :  * @return An NTSTATUS value based on the username
      54             :  **/
      55             : 
      56           0 : static NTSTATUS name_to_ntstatus_check_password(struct auth_method_context *ctx,
      57             :                                                 TALLOC_CTX *mem_ctx,
      58             :                                                 const struct auth_usersupplied_info *user_info, 
      59             :                                                 struct auth_user_info_dc **_user_info_dc,
      60             :                                                 bool *authoritative)
      61             : {
      62           0 :         NTSTATUS nt_status;
      63           0 :         struct auth_user_info_dc *user_info_dc;
      64           0 :         struct auth_user_info *info;
      65           0 :         uint32_t error_num;
      66           0 :         const char *user;
      67             : 
      68           0 :         user = user_info->client.account_name;
      69             : 
      70           0 :         if (strncasecmp("NT_STATUS", user, strlen("NT_STATUS")) == 0) {
      71           0 :                 nt_status = nt_status_string_to_code(user);
      72             :         } else {
      73           0 :                 error_num = strtoul(user, NULL, 16);
      74           0 :                 DEBUG(5,("name_to_ntstatus_check_password: Error for user %s was 0x%08X\n", user, error_num));
      75           0 :                 nt_status = NT_STATUS(error_num);
      76             :         }
      77           0 :         NT_STATUS_NOT_OK_RETURN(nt_status);
      78             : 
      79           0 :         user_info_dc = talloc_zero(mem_ctx, struct auth_user_info_dc);
      80           0 :         NT_STATUS_HAVE_NO_MEMORY(user_info_dc);
      81             : 
      82             :         /* This returns a pointer to a struct dom_sid, which is the
      83             :          * same as a 1 element list of struct dom_sid */
      84           0 :         user_info_dc->num_sids = 1;
      85           0 :         user_info_dc->sids = talloc(user_info_dc, struct auth_SidAttr);
      86           0 :         NT_STATUS_HAVE_NO_MEMORY(user_info_dc->sids);
      87             : 
      88           0 :         user_info_dc->sids->sid = global_sid_Anonymous;
      89           0 :         user_info_dc->sids->attrs = SE_GROUP_DEFAULT_FLAGS;
      90             : 
      91             :         /* annoying, but the Anonymous really does have a session key, 
      92             :            and it is all zeros! */
      93           0 :         user_info_dc->user_session_key = data_blob_talloc(user_info_dc, NULL, 16);
      94           0 :         NT_STATUS_HAVE_NO_MEMORY(user_info_dc->user_session_key.data);
      95             : 
      96           0 :         user_info_dc->lm_session_key = data_blob_talloc(user_info_dc, NULL, 16);
      97           0 :         NT_STATUS_HAVE_NO_MEMORY(user_info_dc->lm_session_key.data);
      98             : 
      99           0 :         data_blob_clear(&user_info_dc->user_session_key);
     100           0 :         data_blob_clear(&user_info_dc->lm_session_key);
     101             : 
     102           0 :         user_info_dc->info = info = talloc_zero(user_info_dc, struct auth_user_info);
     103           0 :         NT_STATUS_HAVE_NO_MEMORY(user_info_dc->info);
     104             : 
     105           0 :         info->account_name = talloc_asprintf(user_info_dc, "NAME TO NTSTATUS %s ANONYMOUS LOGON", user);
     106           0 :         NT_STATUS_HAVE_NO_MEMORY(info->account_name);
     107             : 
     108           0 :         info->domain_name = talloc_strdup(user_info_dc, "NT AUTHORITY");
     109           0 :         NT_STATUS_HAVE_NO_MEMORY(info->domain_name);
     110             : 
     111           0 :         info->full_name = talloc_asprintf(user_info_dc, "NAME TO NTSTATUS %s Anonymous Logon", user);
     112           0 :         NT_STATUS_HAVE_NO_MEMORY(info->full_name);
     113             : 
     114           0 :         info->logon_script = talloc_strdup(user_info_dc, "");
     115           0 :         NT_STATUS_HAVE_NO_MEMORY(info->logon_script);
     116             : 
     117           0 :         info->profile_path = talloc_strdup(user_info_dc, "");
     118           0 :         NT_STATUS_HAVE_NO_MEMORY(info->profile_path);
     119             : 
     120           0 :         info->home_directory = talloc_strdup(user_info_dc, "");
     121           0 :         NT_STATUS_HAVE_NO_MEMORY(info->home_directory);
     122             : 
     123           0 :         info->home_drive = talloc_strdup(user_info_dc, "");
     124           0 :         NT_STATUS_HAVE_NO_MEMORY(info->home_drive);
     125             : 
     126           0 :         info->last_logon = 0;
     127           0 :         info->last_logoff = 0;
     128           0 :         info->acct_expiry = 0;
     129           0 :         info->last_password_change = 0;
     130           0 :         info->allow_password_change = 0;
     131           0 :         info->force_password_change = 0;
     132             : 
     133           0 :         info->logon_count = 0;
     134           0 :         info->bad_password_count = 0;
     135             : 
     136           0 :         info->acct_flags = ACB_NORMAL;
     137             : 
     138           0 :         info->user_flags = 0;
     139             : 
     140           0 :         *_user_info_dc = user_info_dc;
     141             : 
     142           0 :         return nt_status;
     143             : }
     144             : 
     145             : struct name_to_ntstatus_check_password_state {
     146             :         struct auth_user_info_dc *user_info_dc;
     147             :         bool authoritative;
     148             : };
     149             : 
     150           0 : static struct tevent_req *name_to_ntstatus_check_password_send(
     151             :         TALLOC_CTX *mem_ctx,
     152             :         struct tevent_context *ev,
     153             :         struct auth_method_context *ctx,
     154             :         const struct auth_usersupplied_info *user_info)
     155             : {
     156           0 :         struct tevent_req *req = NULL;
     157           0 :         struct name_to_ntstatus_check_password_state *state = NULL;
     158           0 :         NTSTATUS status;
     159             : 
     160           0 :         req = tevent_req_create(
     161             :                 mem_ctx,
     162             :                 &state,
     163             :                 struct name_to_ntstatus_check_password_state);
     164           0 :         if (req == NULL) {
     165           0 :                 return NULL;
     166             :         }
     167             : 
     168           0 :         status = name_to_ntstatus_check_password(
     169             :                 ctx,
     170             :                 state,
     171             :                 user_info,
     172           0 :                 &state->user_info_dc,
     173           0 :                 &state->authoritative);
     174           0 :         if (tevent_req_nterror(req, status)) {
     175           0 :                 return tevent_req_post(req, ev);
     176             :         }
     177           0 :         tevent_req_done(req);
     178           0 :         return tevent_req_post(req, ev);
     179             : }
     180             : 
     181           0 : static NTSTATUS name_to_ntstatus_check_password_recv(
     182             :         struct tevent_req *req,
     183             :         TALLOC_CTX *mem_ctx,
     184             :         struct auth_user_info_dc **interim_info,
     185             :         const struct authn_audit_info **client_audit_info,
     186             :         const struct authn_audit_info **server_audit_info,
     187             :         bool *authoritative)
     188             : {
     189           0 :         struct name_to_ntstatus_check_password_state *state = tevent_req_data(
     190             :                 req, struct name_to_ntstatus_check_password_state);
     191           0 :         NTSTATUS status;
     192             : 
     193           0 :         *authoritative = state->authoritative;
     194           0 :         *client_audit_info = NULL;
     195           0 :         *server_audit_info = NULL;
     196             : 
     197           0 :         if (tevent_req_is_nterror(req, &status)) {
     198           0 :                 tevent_req_received(req);
     199           0 :                 return status;
     200             :         }
     201           0 :         *interim_info = talloc_move(mem_ctx, &state->user_info_dc);
     202           0 :         tevent_req_received(req);
     203           0 :         return NT_STATUS_OK;
     204             : }
     205             : 
     206             : static const struct auth_operations name_to_ntstatus_auth_ops = {
     207             :         .name           = "name_to_ntstatus",
     208             :         .want_check     = name_to_ntstatus_want_check,
     209             :         .check_password_send    = name_to_ntstatus_check_password_send,
     210             :         .check_password_recv    = name_to_ntstatus_check_password_recv,
     211             : };
     212             : 
     213        9681 : _PUBLIC_ NTSTATUS auth4_developer_init(TALLOC_CTX *ctx)
     214             : {
     215         837 :         NTSTATUS ret;
     216             : 
     217        9681 :         ret = auth_register(ctx, &name_to_ntstatus_auth_ops);
     218        9681 :         if (!NT_STATUS_IS_OK(ret)) {
     219           0 :                 DEBUG(0,("Failed to register 'name_to_ntstatus' auth backend!\n"));
     220           0 :                 return ret;
     221             :         }
     222             : 
     223        9681 :         return ret;
     224             : }

Generated by: LCOV version 1.14