LCOV - code coverage report
Current view: top level - auth/credentials - credentials_cmdline.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 2 25 8.0 %
Date: 2024-06-13 04:01:37 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2005      Jelmer Vernooij <jelmer@samba.org>
       3             :  * Copyright (c) 2016      Stefan Metzmacher <metze@samba.org>
       4             :  *
       5             :  * This program is free software: you can redistribute it and/or modify
       6             :  * it under the terms of the GNU General Public License as published by
       7             :  * the Free Software Foundation, either version 3 of the License, or
       8             :  * (at your option) any later version.
       9             :  *
      10             :  * This program is distributed in the hope that it will be useful,
      11             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             :  * GNU General Public License for more details.
      14             :  *
      15             :  * You should have received a copy of the GNU General Public License
      16             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      17             :  */
      18             : 
      19             : #include "includes.h"
      20             : #include "system/filesys.h"
      21             : #include "auth/credentials/credentials.h"
      22             : 
      23           0 : static const char *cmdline_get_userpassword(struct cli_credentials *creds)
      24             : {
      25           0 :         TALLOC_CTX *frame = talloc_stackframe();
      26           0 :         const char *name = NULL;
      27           0 :         char *label = NULL;
      28           0 :         char *ret = NULL;
      29           0 :         char pwd[256] = {0};
      30             :         int rc;
      31             : 
      32           0 :         name = cli_credentials_get_unparsed_name(creds, frame);
      33           0 :         if (name == NULL) {
      34           0 :                 goto fail;
      35             :         }
      36           0 :         label = talloc_asprintf(frame, "Password for [%s]:", name);
      37           0 :         if (label == NULL) {
      38           0 :                 goto fail;
      39             :         }
      40           0 :         rc = samba_getpass(label, pwd, sizeof(pwd), false, false);
      41           0 :         if (rc != 0) {
      42           0 :                 goto fail;
      43             :         }
      44           0 :         ret = talloc_strdup(creds, pwd);
      45           0 :         if (ret == NULL) {
      46           0 :                 goto fail;
      47             :         }
      48           0 :         talloc_set_name_const(ret, __location__);
      49           0 : fail:
      50           0 :         ZERO_STRUCT(pwd);
      51           0 :         TALLOC_FREE(frame);
      52           0 :         return ret;
      53             : }
      54             : 
      55             : /**
      56             :  * @brief Set the command line password callback.
      57             :  *
      58             :  * This will set the callback to get the password from the command prompt or
      59             :  * read it from 'stdin'.
      60             :  *
      61             :  * @param[in]  cred   The credential context.
      62             :  *
      63             :  * @return On success true, false otherwise.
      64             :  */
      65        9359 : bool cli_credentials_set_cmdline_callbacks(struct cli_credentials *cred)
      66             : {
      67             :         /*
      68             :          * The there is no tty, then we will try to read the password from
      69             :          * stdin.
      70             :          */
      71        9359 :         return cli_credentials_set_password_callback(cred,
      72             :                                                      cmdline_get_userpassword);
      73             : }

Generated by: LCOV version 1.13