test-get-passwd.c
Go to the documentation of this file.
1 /* Copyright libuv contributors. All rights reserved.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to
5  * deal in the Software without restriction, including without limitation the
6  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7  * sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19  * IN THE SOFTWARE.
20  */
21 
22 #include "uv.h"
23 #include "task.h"
24 #include <string.h>
25 
26 TEST_IMPL(get_passwd) {
27  uv_passwd_t pwd;
28  size_t len;
29  int r;
30 
31  /* Test the normal case */
32  r = uv_os_get_passwd(&pwd);
33  ASSERT(r == 0);
34  len = strlen(pwd.username);
35  ASSERT(len > 0);
36 
37 #ifdef _WIN32
38  ASSERT(pwd.shell == NULL);
39 #else
40  len = strlen(pwd.shell);
41 # ifndef __PASE__
42  ASSERT(len > 0);
43 # endif
44 #endif
45 
46  len = strlen(pwd.homedir);
47  ASSERT(len > 0);
48 
49 #ifdef _WIN32
50  if (len == 3 && pwd.homedir[1] == ':')
51  ASSERT(pwd.homedir[2] == '\\');
52  else
53  ASSERT(pwd.homedir[len - 1] != '\\');
54 #else
55  if (len == 1)
56  ASSERT(pwd.homedir[0] == '/');
57  else
58  ASSERT(pwd.homedir[len - 1] != '/');
59 #endif
60 
61 #ifdef _WIN32
62  ASSERT(pwd.uid == -1);
63  ASSERT(pwd.gid == -1);
64 #else
65  ASSERT(pwd.uid >= 0);
66  ASSERT(pwd.gid >= 0);
67 #endif
68 
69  /* Test uv_os_free_passwd() */
70  uv_os_free_passwd(&pwd);
71 
72  ASSERT(pwd.username == NULL);
73  ASSERT(pwd.shell == NULL);
74  ASSERT(pwd.homedir == NULL);
75 
76  /* Test a double free */
77  uv_os_free_passwd(&pwd);
78 
79  ASSERT(pwd.username == NULL);
80  ASSERT(pwd.shell == NULL);
81  ASSERT(pwd.homedir == NULL);
82 
83  /* Test invalid input */
84  r = uv_os_get_passwd(NULL);
85  ASSERT(r == UV_EINVAL);
86 
87  return 0;
88 }
uv_os_free_passwd
UV_EXTERN void uv_os_free_passwd(uv_passwd_t *pwd)
Definition: unix/core.c:1223
task.h
uv_passwd_s
Definition: uv.h:1099
uv_passwd_s::username
char * username
Definition: uv.h:1100
uv_passwd_s::gid
long gid
Definition: uv.h:1102
uv_passwd_s::homedir
char * homedir
Definition: uv.h:1104
string.h
uv_os_get_passwd
UV_EXTERN int uv_os_get_passwd(uv_passwd_t *pwd)
Definition: unix/core.c:1239
ASSERT
#define ASSERT(expr)
Definition: task.h:102
uv_passwd_s::shell
char * shell
Definition: uv.h:1103
uv.h
uv_passwd_s::uid
long uid
Definition: uv.h:1101
TEST_IMPL
TEST_IMPL(get_passwd)
Definition: test-get-passwd.c:26
fix_build_deps.r
r
Definition: fix_build_deps.py:491
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:26