MySQL 9.0.0
Source Code Documentation
passwd.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTER_HTTP_PASSWD_INCLUDED
27#define ROUTER_HTTP_PASSWD_INCLUDED
28
29#include <iostream>
30#include <istream>
31#include <string>
32#include <vector>
33
34#include "kdf_sha_crypt.h"
36
37/**
38 * exception thrown by the frontend.
39 *
40 * Should be presented to the user.
41 */
42class FrontendError : public std::runtime_error {
43 public:
44 FrontendError(const std::string &what) : std::runtime_error(what) {}
45};
46
47/**
48 * frontend error that involved the command-line options.
49 *
50 * should be handled by showing the user the help-text or a hint how to get the
51 * help
52 */
53class UsageError : public FrontendError {
54 public:
55 UsageError(const std::string &what) : FrontendError(what) {}
56};
57
58/**
59 * passwd file management frontend.
60 */
62 public:
65 struct Config {
67 std::string filename;
68 std::string username;
71 };
72
73 PasswdFrontend(const std::string &exe_name,
74 const std::vector<std::string> &args,
75 std::ostream &os = std::cout, std::ostream &es = std::cerr);
76
77 /**
78 * run frontend according to configuration.
79 *
80 * @return exit-status
81 * @retval EXIT_FAILURE on error
82 * @retval EXIT_SUCCESS on success
83 */
84 int run();
85
86 /**
87 * get help text.
88 *
89 * @param screen_width wraps text at screen-width
90 * @returns help text
91 */
92 std::string get_help(const size_t screen_width = 80) const;
93
94 /**
95 * get version text.
96 */
97 static std::string get_version() noexcept;
98
99 private:
100 void init_from_arguments(const std::vector<std::string> &arguments);
101
103 std::string read_password();
104
106 CmdArgHandler arg_handler_{true}; // allow arguments
107 std::ostream &cout_;
108 std::ostream &cerr_;
109
110 Config config_; // must be last as init_from_arguments depends on cin, ...
111 // and arg_handler_
112};
113#endif
Defining the commandline argument handler class CmdArgHandler.
Handles command line arguments.
Definition: arg_handler.h:141
exception thrown by the frontend.
Definition: passwd.h:42
FrontendError(const std::string &what)
Definition: passwd.h:44
passwd file management frontend.
Definition: passwd.h:61
Cmd
Definition: passwd.h:64
std::ostream & cerr_
Definition: passwd.h:108
int run()
run frontend according to configuration.
Definition: passwd.cc:147
std::string get_help(const size_t screen_width=80) const
get help text.
Definition: passwd.cc:87
void prepare_command_options()
Definition: passwd.cc:358
PasswdFrontend(const std::string &exe_name, const std::vector< std::string > &args, std::ostream &os=std::cout, std::ostream &es=std::cerr)
Definition: passwd.cc:68
CmdArgHandler arg_handler_
Definition: passwd.h:106
Config config_
Definition: passwd.h:110
static std::string get_version() noexcept
get version text.
Definition: passwd.cc:75
std::ostream & cout_
Definition: passwd.h:107
std::string program_name_
Definition: passwd.h:105
Kdf
Definition: passwd.h:63
std::string read_password()
Definition: passwd.cc:143
void init_from_arguments(const std::vector< std::string > &arguments)
Definition: passwd.cc:57
static constexpr unsigned long kDefaultRounds
number of rounds if no rounds was specified in from_mcf().
Definition: kdf_sha_crypt.h:120
frontend error that involved the command-line options.
Definition: passwd.h:53
UsageError(const std::string &what)
Definition: passwd.h:55
Definition: gcs_xcom_synode.h:64
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2875
Definition: passwd.h:65
std::string filename
Definition: passwd.h:67
unsigned long cost
Definition: passwd.h:70
Kdf kdf
Definition: passwd.h:69
std::string username
Definition: passwd.h:68
Cmd cmd
Definition: passwd.h:66