Bug 186803

Summary: nscd cache make groupadd error in scripts
Product: [Fedora] Fedora Reporter: Kazutoshi Morioka <morioka>
Component: shadow-utilsAssignee: Peter Vrabec <pvrabec>
Status: CLOSED RAWHIDE QA Contact: David Lawrence <dkl>
Severity: medium Docs Contact:
Priority: medium    
Version: 5CC: jakub, k.georgiou
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2006-04-05 11:45:51 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Kazutoshi Morioka 2006-03-26 17:06:18 UTC
Description of problem:
While nscd is running, chgrp after groupadd fails with group does not exist.
For example, preinstall script of screen does groupadd to make "screen" group,
and then, /usr/bin/screen and /var/run/screen/ is created with the "screen".
but this is sometimes fail, and screen do not work.

Version-Release number of selected component (if applicable):
# rpm -q glibc
glibc-2.4-4
# rpm -q screen
screen-4.0.2-12

How reproducible:
sometimes

Steps to Reproduce:
1. service nscd start
2. groupadd foogroup ; groupdel foogroup ; sleep 1
3. repeat 2 some times. 
  
Actual results:
[root@myhost ~]# groupadd foogroup ; groupdel foogroup ; sleep 1
[root@myhost ~]# groupadd foogroup ; groupdel foogroup ; sleep 1
[root@myhost ~]# groupadd foogroup ; groupdel foogroup ; sleep 1
[root@myhost ~]# groupadd foogroup ; groupdel foogroup ; sleep 1
[root@myhost ~]# groupadd foogroup ; groupdel foogroup ; sleep 1
groupdel: group foogroup does not exist

Expected results:
No error reported.

Additional info:
This is another example of this problem:

[root@myhost ~]# yum -y install screen
Loading "installonlyn" plugin
Setting up Remove Process

         snip

Running Transaction
  Installing: screen                                                
[1/1]warning: group screen does not exist - using root
  Installing: screen                       ######################## 
[1/1]warning: group screen does not exist - using root
  Installing: screen                       ######################### [1/1]

Installed: screen.i386 0:4.0.2-12
Complete!
[root@myhost ~]# ls -ld /usr/bin/screen /var/run/screen
-rwxr-xr-x 1 root root 346612  2æ 27 18:10 /usr/bin/screen
drwxrwxr-x 2 root root   4096  2æ 27 18:10 /var/run/screen

Comment 1 Jakub Jelinek 2006-04-03 13:45:49 UTC
That's a bug in shadow-utils, it doesn't properly notify nscd that it needs
to flush its cache.
shadow-4.0.14/lib/nscd.c has:
int nscd_flush_cache (char *service)
{
        int sock = nscd_open_socket ();
        request_header req;
        struct iovec iov[2];
        ssize_t nbytes;

        if (sock == -1)
                return -1;

        req.version = NSCD_VERSION;
        req.type = INVALIDATE;
        req.key_len = strlen (service);

        iov[0].iov_base = &req;
        iov[0].iov_len = sizeof (req);
        iov[1].iov_base = service;
        iov[1].iov_len = req.key_len;

        nbytes = writev (sock, iov, 2);

        close (sock);
        return (nbytes != iov[0].iov_len + iov[1].iov_len ? (-1) : 0);
}

which is wrong, the INVALIDATE request's key is supposed to contain the trailing
'\0' character and req.key_len is supposed to include that as well.
Compare that to what nscd does for nscd -i:
          if (strcmp (arg, "passwd") == 0)
            req.key_len = sizeof "passwd";
          else if (strcmp (arg, "group") == 0)
            req.key_len = sizeof "group";
          else if (strcmp (arg, "hosts") == 0)
            req.key_len = sizeof "hosts";
          else
            return ARGP_ERR_UNKNOWN;

          req.version = NSCD_VERSION;
          req.type = INVALIDATE;

So, shadow-utils needs to change the
req.key_len = strlen (service);
line in lib/nscd.c to:
req.key_len = strlen (service) + 1;


Comment 2 Peter Vrabec 2006-04-05 11:45:51 UTC
fixed in FC5(shadow-utils-4.0.14-6.FC5) and devel