[Kde-kiosk] Problem with Applying Group Profiles to new Users

Martijn Klingens klingens at kde.org
Wed Jan 19 18:34:32 CET 2005


On Wednesday 19 January 2005 16:09, Murray Trainer wrote:
> ldap:~ # cc -o test test.c
> test.c: In function `main':
> test.c:17: error: `for' loop initial declaration used outside C99 mode
> test.c:19: error: `user' undeclared (first use in this function)
> test.c:19: error: (Each undeclared identifier is reported only once
> test.c:19: error: for each function it appears in.)

Bah, the first error is only a reason to use C++ instead of C ;-)

Anyway, the second error is a real one, I copy-pasted too much.

Try this instead:

-------
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>

int main( void )
{
    char *member;

    struct passwd *pw = getpwuid(geteuid());
    if ( !pw )
    {
        printf( "Cannot read user info!\n" );
        return -1;
    }
    char *user = pw->pw_name;

    struct group *grp_ent = getgrnam( "external" );
    if (!grp_ent)
    {
        printf( "Cannot read group external!\n" );
        return -1;
    }

    char ** members = grp_ent->gr_mem;
    for( ; (member = *members); ++members )
    {
        if (strcmp(member, user) == 0)
            printf( "User is in group 'external'\n" );
        else
            printf( "User is *NOT* in group 'external'!\n" );
    }
    return 0;
}
-------

Still untested, but at least there should be less errors now...

-- 
Martijn


More information about the kde-kiosk mailing list