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