5
Last change
on this file since 1c6926c1 was
b471854b,
checked in by Sebastian Huber <sebastian.huber@…>, on 11/14/14 at 10:01:48
|
libcsupport: Split passwd/group support
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Line | |
---|
1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief User Database Access Routines |
---|
5 | * @ingroup libcsupport |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * Copyright (c) 1999-2009 Ralf Corsepius <corsepiu@faw.uni-ulm.de> |
---|
10 | * Copyright (c) 1999-2013 Joel Sherrill <joel.sherrill@OARcorp.com> |
---|
11 | * Copyright (c) 2000-2001 Fernando Ruiz Casas <fernando.ruiz@ctv.es> |
---|
12 | * Copyright (c) 2002 Eric Norum <eric.norum@usask.ca> |
---|
13 | * Copyright (c) 2003 Till Straumann <strauman@slac.stanford.edu> |
---|
14 | * Copyright (c) 2012 Alex Ivanov <alexivanov97@gmail.com> |
---|
15 | * |
---|
16 | * The license and distribution terms for this file may be |
---|
17 | * found in the file LICENSE in this distribution or at |
---|
18 | * http://www.rtems.org/license/LICENSE. |
---|
19 | */ |
---|
20 | |
---|
21 | #if HAVE_CONFIG_H |
---|
22 | #include "config.h" |
---|
23 | #endif |
---|
24 | |
---|
25 | #include "pwdgrp.h" |
---|
26 | |
---|
27 | /* |
---|
28 | * Static, thread-unsafe, buffers |
---|
29 | */ |
---|
30 | static FILE *passwd_fp; |
---|
31 | static char pwbuf[200]; |
---|
32 | static struct passwd pwent; |
---|
33 | |
---|
34 | struct passwd *getpwnam( |
---|
35 | const char *name |
---|
36 | ) |
---|
37 | { |
---|
38 | struct passwd *p; |
---|
39 | |
---|
40 | if(getpwnam_r(name, &pwent, pwbuf, sizeof pwbuf, &p)) |
---|
41 | return NULL; |
---|
42 | return p; |
---|
43 | } |
---|
44 | |
---|
45 | struct passwd *getpwuid( |
---|
46 | uid_t uid |
---|
47 | ) |
---|
48 | { |
---|
49 | struct passwd *p; |
---|
50 | |
---|
51 | if(getpwuid_r(uid, &pwent, pwbuf, sizeof pwbuf, &p)) |
---|
52 | return NULL; |
---|
53 | return p; |
---|
54 | } |
---|
55 | |
---|
56 | struct passwd *getpwent(void) |
---|
57 | { |
---|
58 | if (passwd_fp == NULL) |
---|
59 | return NULL; |
---|
60 | if (!_libcsupport_scanpw(passwd_fp, &pwent, pwbuf, sizeof pwbuf)) |
---|
61 | return NULL; |
---|
62 | return &pwent; |
---|
63 | } |
---|
64 | |
---|
65 | void setpwent(void) |
---|
66 | { |
---|
67 | _libcsupport_pwdgrp_init(); |
---|
68 | |
---|
69 | if (passwd_fp != NULL) |
---|
70 | fclose(passwd_fp); |
---|
71 | passwd_fp = fopen("/etc/passwd", "r"); |
---|
72 | } |
---|
73 | |
---|
74 | void endpwent(void) |
---|
75 | { |
---|
76 | if (passwd_fp != NULL) |
---|
77 | fclose(passwd_fp); |
---|
78 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.