Chinaunix首页 | 论坛 | 博客
  • 博客访问: 325621
  • 博文数量: 106
  • 博客积分: 3081
  • 博客等级: 中校
  • 技术积分: 1090
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-15 14:07
文章分类

全部博文(106)

文章存档

2009年(1)

2007年(34)

2006年(71)

我的朋友

分类: C/C++

2006-03-22 17:45:37

#include
#include
#include
#include
#include
#include


int main()
{
        struct passwd *pwdptr;
        struct group *grpptr;

        char tmpstr[100];
        uid_t uid;
        gid_t gid;
        char username[100];
        char grpname[100];
        int i,count;


        printf("please input the userid or username:\n");

        scanf("%s",tmpstr);

        if((tmpstr[0]>='0') && (tmpstr[0]<='9')) {
                sscanf(tmpstr, "%d",&uid);
                pwdptr=getpwuid(uid);   /*返回的是一个passwd结购*/

                if(pwdptr==NULL){
                        fprintf(stderr,"No,such user!\n");
                        exit(0);
                }

                strcpy(username,pwdptr->pw_name);


        }else{
                sscanf(tmpstr,"%s",username);
        }

        setgrent();

        grpptr=getgrent(); /*提取组条目*/

        count=0;

        while(grpptr != NULL){

                i=0;
                while(grpptr->gr_mem[i]){
                        if(strcmp(grpptr->gr_mem[i],username)==0) {
                                printf("found one group! that is :%s\n",grpptr->gr_name);
                                count++;
                                break;
                        }
                        i++;
                }

                grpptr=getgrent();


        }

        endgrent();
        printf("Scan finished! this user is in %d groups totally.\n",count);
        return 0;

}


 

阅读(977) | 评论(0) | 转发(0) |
0

上一篇:scan port

下一篇:about UID EUID concept

给主人留下些什么吧!~~