LCOV - code coverage report
Current view: top level - source3/auth - user_info.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 49 74 66.2 %
Date: 2024-02-28 12:06:22 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    Authentication utility functions
       4             :    Copyright (C) Volker Lendecke 2010
       5             : 
       6             :    This program is free software; you can redistribute it and/or modify
       7             :    it under the terms of the GNU General Public License as published by
       8             :    the Free Software Foundation; either version 3 of the License, or
       9             :    (at your option) any later version.
      10             : 
      11             :    This program is distributed in the hope that it will be useful,
      12             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :    GNU General Public License for more details.
      15             : 
      16             :    You should have received a copy of the GNU General Public License
      17             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : */
      19             : 
      20             : #include "includes.h"
      21             : #include "auth.h"
      22             : #include "librpc/gen_ndr/samr.h"
      23             : #include "../lib/tsocket/tsocket.h"
      24             : 
      25             : #undef DBGC_CLASS
      26             : #define DBGC_CLASS DBGC_AUTH
      27             : 
      28         104 : static int clear_samr_Password(struct samr_Password *password)
      29             : {
      30         104 :         memset(password->hash, '\0', sizeof(password->hash));
      31         104 :         return 0;
      32             : }
      33             : 
      34           0 : static int clear_string(char *password)
      35             : {
      36           0 :         memset(password, '\0', strlen(password));
      37           0 :         return 0;
      38             : }
      39             : 
      40             : /****************************************************************************
      41             :  Create an auth_usersupplied_data structure
      42             : ****************************************************************************/
      43             : 
      44       29226 : NTSTATUS make_user_info(TALLOC_CTX *mem_ctx,
      45             :                         struct auth_usersupplied_info **ret_user_info,
      46             :                         const char *smb_name,
      47             :                         const char *internal_username,
      48             :                         const char *client_domain,
      49             :                         const char *domain,
      50             :                         const char *workstation_name,
      51             :                         const struct tsocket_address *remote_address,
      52             :                         const struct tsocket_address *local_address,
      53             :                         const char *service_description,
      54             :                         const DATA_BLOB *lm_pwd,
      55             :                         const DATA_BLOB *nt_pwd,
      56             :                         const struct samr_Password *lm_interactive_pwd,
      57             :                         const struct samr_Password *nt_interactive_pwd,
      58             :                         const char *plaintext_password,
      59             :                         enum auth_password_state password_state)
      60             : {
      61           0 :         struct auth_usersupplied_info *user_info;
      62       29226 :         *ret_user_info = NULL;
      63             : 
      64       29226 :         DEBUG(5,("attempting to make a user_info for %s (%s)\n", internal_username, smb_name));
      65             : 
      66       29226 :         user_info = talloc_zero(mem_ctx, struct auth_usersupplied_info);
      67       29226 :         if (user_info == NULL) {
      68           0 :                 DEBUG(0,("talloc failed for user_info\n"));
      69           0 :                 return NT_STATUS_NO_MEMORY;
      70             :         }
      71             : 
      72       29226 :         DEBUG(5,("making strings for %s's user_info struct\n", internal_username));
      73             : 
      74       29226 :         user_info->client.account_name = talloc_strdup(user_info, smb_name);
      75       29226 :         if (user_info->client.account_name == NULL) {
      76           0 :                 goto nomem;
      77             :         }
      78             : 
      79       29226 :         user_info->mapped.account_name = talloc_strdup(user_info, internal_username);
      80       29226 :         if (user_info->mapped.account_name == NULL) {
      81           0 :                 goto nomem;
      82             :         }
      83             : 
      84       29226 :         user_info->mapped.domain_name = talloc_strdup(user_info, domain);
      85       29226 :         if (user_info->mapped.domain_name == NULL) {
      86           0 :                 goto nomem;
      87             :         }
      88             : 
      89       29226 :         user_info->client.domain_name = talloc_strdup(user_info, client_domain);
      90       29226 :         if (user_info->client.domain_name == NULL) {
      91           0 :                 goto nomem;
      92             :         }
      93             : 
      94       29226 :         user_info->workstation_name = talloc_strdup(user_info, workstation_name);
      95       29226 :         if (user_info->workstation_name == NULL) {
      96           0 :                 goto nomem;
      97             :         }
      98             : 
      99       29226 :         user_info->remote_host = tsocket_address_copy(remote_address, user_info);
     100       29226 :         if (user_info->remote_host == NULL) {
     101           0 :                 goto nomem;
     102             :         }
     103             : 
     104       29226 :         if (local_address != NULL) {
     105       29226 :                 user_info->local_host = tsocket_address_copy(local_address,
     106             :                                                              user_info);
     107       29226 :                 if (user_info->local_host == NULL) {
     108           0 :                         goto nomem;
     109             :                 }
     110             :         }
     111             : 
     112       29226 :         user_info->service_description = talloc_strdup(user_info, service_description);
     113       29226 :         if (user_info->service_description == NULL) {
     114           0 :                 goto nomem;
     115             :         }
     116             : 
     117       29226 :         DEBUG(5,("making blobs for %s's user_info struct\n", internal_username));
     118             : 
     119       29226 :         if (lm_pwd && lm_pwd->data) {
     120       28405 :                 user_info->password.response.lanman = data_blob_talloc(user_info, lm_pwd->data, lm_pwd->length);
     121       28405 :                 if (user_info->password.response.lanman.data == NULL) {
     122           0 :                         goto nomem;
     123             :                 }
     124             :         }
     125       29226 :         if (nt_pwd && nt_pwd->data) {
     126       28558 :                 user_info->password.response.nt = data_blob_talloc(user_info, nt_pwd->data, nt_pwd->length);
     127       28558 :                 if (user_info->password.response.nt.data == NULL) {
     128           0 :                         goto nomem;
     129             :                 }
     130             :         }
     131       29226 :         if (lm_interactive_pwd) {
     132          52 :                 user_info->password.hash.lanman = talloc(user_info, struct samr_Password);
     133          52 :                 if (user_info->password.hash.lanman == NULL) {
     134           0 :                         goto nomem;
     135             :                 }
     136          52 :                 memcpy(user_info->password.hash.lanman->hash, lm_interactive_pwd->hash,
     137             :                        sizeof(user_info->password.hash.lanman->hash));
     138          52 :                 talloc_set_destructor(user_info->password.hash.lanman, clear_samr_Password);
     139             :         }
     140             : 
     141       29226 :         if (nt_interactive_pwd) {
     142          52 :                 user_info->password.hash.nt = talloc(user_info, struct samr_Password);
     143          52 :                 if (user_info->password.hash.nt == NULL) {
     144           0 :                         goto nomem;
     145             :                 }
     146          52 :                 memcpy(user_info->password.hash.nt->hash, nt_interactive_pwd->hash,
     147             :                        sizeof(user_info->password.hash.nt->hash));
     148          52 :                 talloc_set_destructor(user_info->password.hash.nt, clear_samr_Password);
     149             :         }
     150             : 
     151       29226 :         if (plaintext_password) {
     152           0 :                 user_info->password.plaintext = talloc_strdup(user_info, plaintext_password);
     153           0 :                 if (user_info->password.plaintext == NULL) {
     154           0 :                         goto nomem;
     155             :                 }
     156           0 :                 talloc_set_destructor(user_info->password.plaintext, clear_string);
     157             :         }
     158             : 
     159       29226 :         user_info->password_state = password_state;
     160             : 
     161       29226 :         user_info->logon_parameters = 0;
     162             : 
     163       29226 :         DEBUG(10,("made a user_info for %s (%s)\n", internal_username, smb_name));
     164       29226 :         *ret_user_info = user_info;
     165       29226 :         return NT_STATUS_OK;
     166           0 : nomem:
     167           0 :         TALLOC_FREE(user_info);
     168           0 :         return NT_STATUS_NO_MEMORY;
     169             : }

Generated by: LCOV version 1.14