getpwnam_error.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Fri, 27 Dec 2013 16:00:09 +0100
changeset 167 7c6b221900bf
parent 77 49e0babccb23
permissions -rw-r--r--
Proper Datatypes to leave the 80's
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
/**
77
49e0babccb23 HEADER TAGS
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 59
diff changeset
     2
 * getpwnam_error.c
33
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     3
 * Copyright (C) 2008 Markus Broeker
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
 */
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
#include <stdio.h>
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
#include <stdlib.h>
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
#include <pwd.h>
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    10
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
/**
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
==7531==
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
==7531== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 25 from 2)
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
==7531== malloc/free: in use at exit: 156 bytes in 11 blocks.
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
==7531== malloc/free: 66 allocs, 55 frees, 6,342 bytes allocated.
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
==7531== For counts of detected errors, rerun with: -v
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
==7531== searching for pointers to 11 not-freed blocks.
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
==7531== checked 60,444 bytes.
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    19
==7531==
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
==7531== 156 (36 direct, 120 indirect) bytes in 1 blocks are definitely lost in loss record 1 of 3
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
==7531==    at 0x4022D6E: malloc (vg_replace_malloc.c:207)
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
==7531==    by 0x412C7E0: (within /lib/i686/cmov/libc-2.7.so)
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    23
==7531==    by 0x412D0DB: __nss_database_lookup (in /lib/i686/cmov/libc-2.7.so)
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    24
==7531==    by 0x4596F5B: ???
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    25
==7531==    by 0x4597CF6: ???
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
==7531==    by 0x40D3BD1: getpwnam_r (in /lib/i686/cmov/libc-2.7.so)
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    27
==7531==    by 0x40D3646: getpwnam (in /lib/i686/cmov/libc-2.7.so)
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
==7531==    by 0x8048478: main (getpwnam_error.c:48)
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    29
==7531==
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    30
==7531== LEAK SUMMARY:
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
==7531==    definitely lost: 36 bytes in 1 blocks.
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    32
==7531==    indirectly lost: 120 bytes in 10 blocks.
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    33
==7531==      possibly lost: 0 bytes in 0 blocks.
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    34
==7531==    still reachable: 0 bytes in 0 blocks.
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    35
==7531==         suppressed: 0 bytes in 0 blocks.
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    36
*/
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    37
59
a7ba10b68915 getpwnam_error.c:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 33
diff changeset
    38
/*
a7ba10b68915 getpwnam_error.c:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 33
diff changeset
    39
 * LD_PRELOAD=/lib/libnss_compat.so.2 valgrind --leak-check=full \
a7ba10b68915 getpwnam_error.c:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 33
diff changeset
    40
 * ./getpwnam_error
a7ba10b68915 getpwnam_error.c:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 33
diff changeset
    41
 * fixes it - Many thanks to telexicon for reporting this...
a7ba10b68915 getpwnam_error.c:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 33
diff changeset
    42
 *
a7ba10b68915 getpwnam_error.c:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 33
diff changeset
    43
 */
a7ba10b68915 getpwnam_error.c:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 33
diff changeset
    44
33
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    45
int main (int argc, char **argv)
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    46
{
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    47
    struct passwd *pwd;
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    48
    char *user;
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    49
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    50
    if ((user = getenv ("USER")) == NULL) {
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    51
        printf ("This system isn't supported yet\n");
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    52
        return EXIT_FAILURE;
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    53
    }
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    54
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    55
    if ((pwd = getpwnam (user)) == NULL) {
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    56
        printf ("I wasn't able to retrieve the neccessary data\n");
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    57
        return EXIT_FAILURE;
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    58
    }
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    59
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    60
    printf ("Your full name: %s\n", pwd->pw_gecos);
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    61
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    62
    return EXIT_SUCCESS;
5e0a954f7c0b getpwnam_error:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    63
}