In vpopmail-5.5.0 there is a bug in vdominfo that means option 'q' does
not work, there is a missing break after the 'q' case. Additionally
vdominfo's output differs from vuserinfo's output in that in vuserinfo
the quota and the quota usage are treated seperatly, I have changed
vdominfo to fix the bug and make it similar to vuserinfo. Patch attached.
!DSPAM:55f7e54541556238488843!
diff -uPr vpopmail-5.5.0.orig/vdominfo.c vpopmail-5.5.0/vdominfo.c
--- vpopmail-5.5.0.orig/vdominfo.c 2010-11-05 18:37:23.000000000 +0000
+++ vpopmail-5.5.0/vdominfo.c 2015-09-07 10:51:22.215095738 +0100
@@ -43,6 +43,7 @@
int DisplayTotalUsers;
int DisplayRealDomain;
int DisplayQuota;
+int DisplayQuotaUsage;
void usage();
void get_options(int argc, char **argv);
@@ -60,7 +61,7 @@
ret = vauth_load_module(NULL);
if (!ret)
- vexiterror(stderr, "could not load authentication module");
+ vexiterror(stderr, "could not load authentication module");
if( vauth_open( 0 )) {
vexiterror( stderr, "Initial open." );
@@ -89,7 +90,8 @@
printf(" -d (display domain directory)\n");
printf(" -t (display total users)\n");
printf(" -r (display real domain)\n");
- printf(" -q (display quota usage)\n");
+ printf(" -q (display quota field)\n");
+ printf(" -Q (display quota usage)\n");
}
void get_options(int argc, char **argv)
@@ -104,13 +106,14 @@
DisplayDir = 0;
DisplayTotalUsers = 0;
DisplayAll = 1;
- DisplayRealDomain = 0;
- DisplayQuota = 0;
+ DisplayRealDomain = 0;
+ DisplayQuota = 0;
+ DisplayQuotaUsage = 0;
memset(Domain, 0, sizeof(Domain));
errflag = 0;
- while( !errflag && (c=getopt(argc,argv,"vanugdtrq")) != -1 ) {
+ while( !errflag && (c=getopt(argc,argv,"vanugdtrqQ")) != -1 ) {
switch(c) {
case 'v':
printf("version: %s\n", VERSION);
@@ -140,11 +143,16 @@
break;
case 'r':
DisplayRealDomain = 1;
- DisplayAll = 0;
+ DisplayAll = 0;
+ break;
+ case 'q':
+ DisplayQuota = 1;
+ DisplayAll = 0;
+ break;
+ case 'Q':
+ DisplayQuotaUsage = 1;
+ DisplayAll = 0;
break;
- case 'q':
- DisplayQuota = 1;
- DisplayAll = 0;
default:
errflag = 1;
break;
@@ -157,18 +165,47 @@
}
if ( optind < argc ) {
- snprintf(Domain, sizeof(Domain), "%s", argv[optind]);
+ snprintf(Domain, sizeof(Domain), "%s", argv[optind]);
++optind;
}
}
-void display_domain(char *domain, char *dir, uid_t uid, gid_t gid, char
*realdomain)
+void display_quota(char *realdomain)
{
int ret = 0;
struct vlimits vl;
+
+ ret = vget_limits(realdomain, &vl);
+ if (!ret)
+ printf("S=%llu,C=%llu\n",
(storage_t)(((storage_t)vl.diskquota)*((storage_t)1000000)),
(storage_t)(vl.maxmsgcount));
+ else
+ printf("NOQUOTA\n");
+}
+
+void display_quota_usage(char *realdomain)
+{
+ int ret = 0, len = 0;
+ struct vlimits vl;
storage_t bytes = 0, count = 0;
char b[256] = { 0 };
+ ret = vget_limits(realdomain, &vl);
+ len = strlen(realdomain);
+ if (len <= (sizeof(b) - 2)) {
+ memcpy((b + 1), realdomain, len);
+ *b = '@';
+ *(b + len + 1) = '\0';
+
+ quota_get_usage(b, &bytes, &count);
+ }
+
+ printf("%d%% (%llu byte(s) in %llu file(s))\n",
+ quota_percent(bytes, count, (storage_t)((storage_t)vl.diskquota *
((storage_t)1000000)), vl.maxmsgcount),
+ bytes, count);
+}
+
+void display_domain(char *domain, char *dir, uid_t uid, gid_t gid, char
*realdomain)
+{
if ( DisplayAll ) {
if(strcmp(domain, realdomain)==0)
printf("domain: %s\n", domain);
@@ -180,27 +217,10 @@
open_big_dir(realdomain, uid, gid);
printf("users: %lu\n", vdir.cur_users);
close_big_dir(realdomain,uid,gid);
-
- ret = vget_limits(realdomain, &vl);
- if (!ret)
- printf("quota: S=%llu,C=%llu\n",
(storage_t)(((storage_t)vl.diskquota)*((storage_t)1000000)),
(storage_t)(vl.maxmsgcount));
-
- else
- printf("quota: NOQUOTA\n");
-
- ret = strlen(realdomain);
- if (ret <= (sizeof(b) - 2)) {
- memcpy((b + 1), realdomain, ret);
- *b = '@';
- *(b + ret + 1) = '\0';
-
- quota_get_usage(b, &bytes, &count);
- }
-
- printf("usage: %d%% (%llu byte(s) in %llu file(s))\n",
- quota_percent(bytes, count,
(storage_t)((storage_t)vl.diskquota * ((storage_t)1000000)), vl.maxmsgcount),
- bytes, count);
-
+ printf("quota: ");
+ display_quota(realdomain);
+ printf("usage: ");
+ display_quota_usage(realdomain);
} else {
if ( DisplayName ) {
if(strcmp(domain, realdomain)==0)
@@ -217,7 +237,10 @@
close_big_dir(realdomain,uid,gid);
}
- if ( DisplayRealDomain ) printf("%s\n", realdomain);
+ if ( DisplayRealDomain ) printf("%s\n", realdomain);
+
+ if ( DisplayQuota ) display_quota(realdomain);
+ if ( DisplayQuotaUsage ) display_quota_usage(realdomain);
}
}
@@ -237,10 +260,10 @@
}
while( entry ) {
- display_domain(entry->domain, entry->path, entry->uid,
+ display_domain(entry->domain, entry->path, entry->uid,
entry->gid, entry->realdomain);
- printf ("\n");
+ printf ("\n");
entry = get_domain_entries(NULL);
}
}
@@ -263,21 +286,21 @@
}
while( entry ) {
- if (strcmp(entry->domain, entry->realdomain) != 0) {
-// printf ("Note: %s is an alias for %s\n",
+ if (strcmp(entry->domain, entry->realdomain) != 0) {
+// printf ("Note: %s is an alias for %s\n",
// entry->domain, entry->realdomain);
aliases[aliascount++] = strdup(entry->domain);
} else {
- display_domain(entry->domain, entry->path, entry->uid,
- entry->gid, entry->realdomain);
- }
+ display_domain(entry->domain, entry->path, entry->uid,
+ entry->gid, entry->realdomain);
+ }
entry = get_domain_entries(NULL);
}
for(i=0;i<aliascount;i++) {
- printf ("alias: %s\n", aliases[i]);
+ printf ("alias: %s\n", aliases[i]);
free( aliases[i] );
}
}