1 //
2 // aegis - project change supervisor
3 // Copyright (C) 2007, 2008, 2012 Peter Miller
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
17 // <http://www.gnu.org/licenses/>.
18 //
19
20 #include <common/error.h>
21 #include <common/trace.h>
22 #include <libaegis/getpw_cache.h>
23 #include <libaegis/sub.h>
24 #include <libaegis/user.h>
25
26
27 user_ty::pointer
user_symbolic(string_ty * name)28 user_symbolic(string_ty *name)
29 {
30 return user_ty::create(nstring(name));
31 }
32
33
34 user_ty::pointer
create(const nstring & u_name)35 user_ty::create(const nstring &u_name)
36 {
37 trace(("user_ty::create(name = %s)\n{\n", u_name.quote_c().c_str()));
38
39 struct passwd *pw = getpwnam_cached(u_name);
40 if (!pw)
41 {
42 nstring best = getpwnam_fuzzy(u_name);
43 if (!best.empty())
44 {
45 if (u_name == best)
46 {
47 error_raw
48 (
49 "Your name service seems to be broken: it can't "
50 "find user %s by name (via getpwnam), but this "
51 "user is present when scanning through all users "
52 "(via getpwent). This is not an Aegis bug, please "
53 "do not report it as such. You network sysadmin "
54 "should be informed.",
55 u_name.quote_c().c_str()
56 );
57 }
58
59 sub_context_ty sc;
60 sc.var_set_string("Name", u_name);
61 sc.var_set_string("Guess", best);
62 sc.fatal_intl(i18n("user $name unknown, closest is $guess"));
63 // NOTREACHED
64 }
65 else
66 {
67 sub_context_ty sc;
68 sc.var_set_string("Name", u_name);
69 sc.fatal_intl(i18n("user $name unknown"));
70 // NOTREACHED
71 }
72 }
73
74 user_ty::pointer result = user_ty::create(pw->pw_uid);
75 trace(("return %p;\n", result.get()));
76 trace(("}\n"));
77 return result;
78 }
79
80
81 // vim: set ts=8 sw=4 et :
82