MySQL 8.1.0
Source Code Documentation
my_getpwnam.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2019, 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, version 2.0, 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#ifndef MY_GETPWNAM_INCLUDED
25#define MY_GETPWNAM_INCLUDED
26
27/**
28 @file include/my_getpwnam.h
29*/
30#include <string>
31#include "my_config.h"
32
33#ifdef HAVE_GETPWNAM
34#include <pwd.h>
35#include <sys/types.h>
36
37/**
38 Shadow struct for passwd which has proper value semantics, so that
39 it can be safely copied and assigned to.
40 */
42 std::string pw_name;
43 std::string pw_passwd;
44 uid_t pw_uid{0};
45 gid_t pw_gid{0};
46 std::string pw_gecos;
47 std::string pw_dir;
48 std::string pw_shell;
49
50 /** Constructs from a passwd instance. */
51 PasswdValue(const passwd &p)
52 : pw_name{p.pw_name},
59
60 /** Default constructor creates a void value. */
61 PasswdValue() = default;
62
63 /**
64 Returns true if this PasswdValue instance does not represent a
65 real passwd entry.
66 */
67 bool IsVoid() const { return pw_name.empty(); }
68};
69
70PasswdValue my_getpwnam(const char *);
72
73#endif /* HAVE_GETPWNAM */
74
75#endif // MY_GETPWNAM_INCLUDED
const char * p
Definition: ctype-mb.cc:1234
PasswdValue my_getpwnam(const char *)
Wrapper around the getpwnam_r() POSIX function which places the contents of the passwd struct into an...
Definition: my_getpwnam.cc:84
PasswdValue my_getpwuid(uid_t)
Wrapper around the getpwuid_r() POSIX function which places the contents of the passwd struct into an...
Definition: my_getpwnam.cc:102
Shadow struct for passwd which has proper value semantics, so that it can be safely copied and assign...
Definition: my_getpwnam.h:41
std::string pw_passwd
Definition: my_getpwnam.h:43
std::string pw_shell
Definition: my_getpwnam.h:48
PasswdValue()=default
Default constructor creates a void value.
std::string pw_gecos
Definition: my_getpwnam.h:46
std::string pw_dir
Definition: my_getpwnam.h:47
bool IsVoid() const
Returns true if this PasswdValue instance does not represent a real passwd entry.
Definition: my_getpwnam.h:67
std::string pw_name
Definition: my_getpwnam.h:42
PasswdValue(const passwd &p)
Constructs from a passwd instance.
Definition: my_getpwnam.h:51
uid_t pw_uid
Definition: my_getpwnam.h:44
gid_t pw_gid
Definition: my_getpwnam.h:45