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