(root)/
glibc-2.38/
nss/
tst-nss-files-alias-truncated.c
       1  /* Check handling of missing end-of-line at end of /etc/aliases (bug 24059).
       2     Copyright (C) 2019-2023 Free Software Foundation, Inc.
       3     This file is part of the GNU C Library.
       4  
       5     The GNU C Library is free software; you can redistribute it and/or
       6     modify it under the terms of the GNU Lesser General Public
       7     License as published by the Free Software Foundation; either
       8     version 2.1 of the License, or (at your option) any later version.
       9  
      10     The GNU C Library 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 GNU
      13     Lesser General Public License for more details.
      14  
      15     You should have received a copy of the GNU Lesser General Public
      16     License along with the GNU C Library; if not, see
      17     <https://www.gnu.org/licenses/>.  */
      18  
      19  #include <aliases.h>
      20  #include <gnu/lib-names.h>
      21  #include <nss.h>
      22  #include <stddef.h>
      23  #include <support/check.h>
      24  #include <support/namespace.h>
      25  #include <support/test-driver.h>
      26  #include <support/xdlfcn.h>
      27  #include <support/xunistd.h>
      28  
      29  static void
      30  in_chroot (void *closure)
      31  {
      32    struct support_chroot *chroot_env = closure;
      33    xchroot (chroot_env->path_chroot);
      34  
      35    struct aliasent *e = getaliasbyname ("user1");
      36    TEST_VERIFY_EXIT (e != NULL);
      37    TEST_COMPARE_STRING (e->alias_name, "user1");
      38    TEST_COMPARE (e->alias_members_len, 1);
      39    TEST_VERIFY_EXIT (e->alias_members != NULL);
      40    TEST_COMPARE_STRING (e->alias_members[0], "alias1");
      41    TEST_VERIFY (e->alias_local);
      42  }
      43  
      44  static int
      45  do_test (void)
      46  {
      47    /* Make sure we don't try to load the module in the chroot.  */
      48    xdlopen (LIBNSS_FILES_SO, RTLD_NOW);
      49  
      50    __nss_configure_lookup ("aliases", "files");
      51  
      52    support_become_root ();
      53    if (!support_can_chroot ())
      54      return EXIT_UNSUPPORTED;
      55  
      56    struct support_chroot *chroot_env = support_chroot_create
      57      ((struct support_chroot_configuration)
      58       {
      59         .aliases = "user1: alias1,\n"
      60          " "              /* Continuation line, but no \n.  */
      61       });
      62  
      63    support_isolate_in_subprocess (in_chroot, chroot_env);
      64  
      65    support_chroot_free (chroot_env);
      66    return 0;
      67  }
      68  
      69  #include <support/test-driver.c>