Ejemplo n.º 1
0
static struct passwd *
gi_getpwnam(const char *name)
{
	int rval;

	if (!pwstart())
		return NULL;
	rval = pwscan(1, 0, name);
	if (!_pw_stayopen)
		endpwent();
	return (rval) ? &_pw_passwd : NULL;
}
Ejemplo n.º 2
0
static struct passwd *
gi_getpwuid(uid_t uid)
{
	int rval;

	if (!pwstart())
		return NULL;
	rval = pwscan(1, uid, NULL);
	if (!_pw_stayopen)
		endpwent();
	return (rval) ? &_pw_passwd : NULL;
}
Ejemplo n.º 3
0
int 
main(int argc, char *argv[])
{
    confent_t *conf;
    int c;
    int dopt = 0;
    int popt = 0;
    unsigned long bsize = 1024*1024;
    char *fsname = NULL;
    List qlist;
    int Fopt = 0;
    int ropt = 0;
    int sopt = 0;
    int Hopt = 0;
    int Uopt = 0;
    int nopt = 0;
    int hopt = 0;
    List uids = NULL;
    char *conf_path = _PATH_QUOTA_CONF;
    conf_t config;

    prog = basename(argv[0]);
    while ((c = GETOPT(argc, argv, OPTIONS, longopts)) != EOF) {
        switch(c) {
            case 'd':   /* --dirscan */
                dopt++;
                break;
            case 'p':   /* --pwscan */
                popt++;
                break;
            case 'b':   /* --blocksize */
                if (parse_blocksize(optarg, &bsize)) {
                    fprintf(stderr, "%s: error parsing blocksize\n", prog); 
                    exit(1);
                }
                break;
            case 'u':   /* --uid-range */
                uids = listint_create(optarg);
                if (uids == NULL) {
                    fprintf(stderr, "%s: error parsing uid-range\n", prog);
                    exit(1);
                }
                break;
            case 'r':   /* --reverse */
                ropt++;
                break;
            case 'F':   /* --files-sort */
                Fopt++;
                break;
            case 's':   /* --space-sort */
                sopt++;
                break;
            case 'U':   /* --usage-only */
                Uopt++;
                break;
            case 'H':   /* --suppress-heading */
                Hopt++;
                break;
            case 'f':   /* --config */
                conf_path = optarg;
                break;
            case 'T':   /* --selftest */
#ifndef NDEBUG
                listint_test();
                exit(0);
#else
                fprintf(stderr, "%s: not built with debugging enabled\n", prog);
                exit(1);
#endif
                break;
            case 'D':   /* --debug */
                debug = 1;
                break;
            case 'n':   /* --nouserlookup */
                nopt = 1;
                break;
            case 'h':   /* --human-readable */
                hopt = 1;
                break;
            default:
                usage();
        }
    }
    if (Fopt && sopt) {
        fprintf(stderr, "%s: -f and -s are mutually exclusive\n", prog);
        exit(1);
    }
    if (popt && dopt) {
        fprintf(stderr, "%s: -p and -d are mutually exclusive\n", prog);
        exit(1);
    }
    if (!popt && !dopt && !uids) {
        fprintf(stderr, "%s: need at least one of -pdu\n", prog);
        exit(1);
    }
    if (optind < argc)
        fsname = argv[optind++];
    else
        usage();
    if (optind < argc)
        usage();
    config = conf_init(conf_path); /* exit/perror on error */

    if (!(conf = conf_get_bylabel(config, fsname, 0))) {
        fprintf(stderr, "%s: %s: not found in quota.conf\n", prog, fsname);
        exit(1);
    }
        
    /* Scan.
     */
    qlist = list_create((ListDelF)quota_destroy);
    if (popt)
        pwscan(conf, qlist, uids, !nopt);
    if (dopt) 
        dirscan(conf, qlist, uids, !nopt);
    if (!dopt && !popt)
        uidscan(conf, qlist, uids, !nopt);


    /* Sort.
     */
    if (ropt) {
        if (sopt)
            list_sort(qlist, (ListCmpF)quota_cmp_bytes_reverse);
        else if (Fopt)
            list_sort(qlist, (ListCmpF)quota_cmp_files_reverse);
        else
            list_sort(qlist, (ListCmpF)quota_cmp_uid_reverse);
    } else {
        if (sopt)
            list_sort(qlist, (ListCmpF)quota_cmp_bytes);
        else if (Fopt)
            list_sort(qlist, (ListCmpF)quota_cmp_files);
        else
            list_sort(qlist, (ListCmpF)quota_cmp_uid);
    }

    /* Report.
     */
    if (!Hopt) {

        if (hopt)
            printf("Quota report for %s\n", fsname);
        else {
            char tmpstr[16];
            size2str(bsize, tmpstr, sizeof(tmpstr));
            printf("Quota report for %s (blocksize %s)\n", fsname, tmpstr);
        }
    }
    if (Uopt) {
        if (!Hopt)
            quota_report_heading_usageonly();
        if (hopt)
            list_for_each(qlist, (ListForF)quota_report_usageonly_h, &bsize);
        else
            list_for_each(qlist, (ListForF)quota_report_usageonly, &bsize);
    } else {
        if (!Hopt)
            quota_report_heading();
        if (hopt)
            list_for_each(qlist, (ListForF)quota_report_h, &bsize);
        else
            list_for_each(qlist, (ListForF)quota_report, &bsize);
    }

    if (qlist)
        list_destroy(qlist);
    if (uids)
        listint_destroy(uids);
    conf_fini(config);

    return 0;
}