summaryrefslogtreecommitdiff
path: root/myfind/user_belong/user_belong.c
blob: bb7332a17f64c70b032a25ee6967d07035e36eaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <pwd.h>
#include <stdio.h>
#include <sys/stat.h>

int main(int argc, char **argv)
{
    if (argc != 3)
        return 2;

    struct passwd *p = getpwnam(argv[2]);
    if (!p)
    {
        printf("user %s does not exist\n", argv[2]);
        return 0;
    }
    struct stat s;
    stat(argv[1], &s);

    printf("%s does ", argv[1]);
    if (s.st_uid != p->pw_uid)
        printf("not ");
    printf("belong to user %s\n", argv[2]);

    return 0;
}