LCOV - code coverage report
Current view: top level - source4/kdc - kpasswd_glue.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 12 15 80.0 %
Date: 2024-06-13 04:01:37 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    kpasswd Server implementation
       5             : 
       6             :    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2005
       7             :    Copyright (C) Andrew Tridgell        2005
       8             : 
       9             :    This program is free software; you can redistribute it and/or modify
      10             :    it under the terms of the GNU General Public License as published by
      11             :    the Free Software Foundation; either version 3 of the License, or
      12             :    (at your option) any later version.
      13             : 
      14             :    This program is distributed in the hope that it will be useful,
      15             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :    GNU General Public License for more details.
      18             : 
      19             :    You should have received a copy of the GNU General Public License
      20             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      21             : */
      22             : 
      23             : #include "includes.h"
      24             : #include "dsdb/samdb/samdb.h"
      25             : #include "../lib/util/util_ldb.h"
      26             : #include "libcli/security/security.h"
      27             : #include "dsdb/common/util.h"
      28             : #include "auth/auth.h"
      29             : #include "kdc/kpasswd_glue.h"
      30             : 
      31             : /*
      32             :    A user password change
      33             : 
      34             :    Return true if there is a valid error packet (or success) formed in
      35             :    the error_blob
      36             : */
      37          16 : NTSTATUS samdb_kpasswd_change_password(TALLOC_CTX *mem_ctx,
      38             :                                        struct loadparm_context *lp_ctx,
      39             :                                        struct tevent_context *event_ctx,
      40             :                                        struct auth_session_info *session_info,
      41             :                                        const DATA_BLOB *password,
      42             :                                        enum samPwdChangeReason *reject_reason,
      43             :                                        struct samr_DomInfo1 **dominfo,
      44             :                                        const char **error_string,
      45             :                                        NTSTATUS *result)
      46             : {
      47             :         NTSTATUS status;
      48          16 :         struct ldb_context *samdb = NULL;
      49             : 
      50             :         /* Start a SAM with user privileges for the password change */
      51          16 :         samdb = samdb_connect(mem_ctx,
      52             :                               event_ctx,
      53             :                               lp_ctx,
      54             :                               session_info,
      55             :                               NULL,
      56             :                               0);
      57          16 :         if (!samdb) {
      58           0 :                 *error_string = "Failed to open samdb";
      59           0 :                 return NT_STATUS_ACCESS_DENIED;
      60             :         }
      61             : 
      62          16 :         DEBUG(3, ("Changing password of %s\\%s (%s)\n",
      63             :                   session_info->info->domain_name,
      64             :                   session_info->info->account_name,
      65             :                   dom_sid_string(mem_ctx, &session_info->security_token->sids[PRIMARY_USER_SID_INDEX])));
      66             : 
      67             :         /* Performs the password change */
      68          16 :         status = samdb_set_password_sid(samdb,
      69             :                                         mem_ctx,
      70          16 :                                         &session_info->security_token->sids[PRIMARY_USER_SID_INDEX],
      71             :                                         NULL,
      72             :                                         password,
      73             :                                         NULL,
      74             :                                         DSDB_PASSWORD_CHECKED_AND_CORRECT,
      75             :                                         reject_reason,
      76             :                                         dominfo);
      77          16 :         if (NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)) {
      78           0 :                 *error_string = "No such user when changing password";
      79          16 :         } else if (!NT_STATUS_IS_OK(status)) {
      80           2 :                 *error_string = nt_errstr(status);
      81             :         }
      82          16 :         *result = status;
      83             : 
      84          16 :         return NT_STATUS_OK;
      85             : }

Generated by: LCOV version 1.13