Hello,
I apologize if this is a repeat; I tried sending a similar message earlier
today via e-mail, and it hasn't shown up yet. I'm now trying through the
lyris form.
I need to set users quota through a CGI script and was unable to do this
with a C program I had written (it kept returning EINVAL, even though
quotas are enabled in the kernel). I realized that since the target
machine
for this CGI script is RedHat, it will have Linuxconf available for use.
So, my question is, how do I use Linuxconf, in script-friendly commandline
mode, to set a users quota?
Alternatively, if this is not possible, does anyone know what may be wrong
with the program below? I hope that you may find it a useful little
utility
if it can be fixed. If it helps, I am writing it on a RH 5.1 (w/ updates)
system.
Thanks very much,
Nick
#include <stdio.h>
#include <stdlib.h>
#include <linux/types.h>
#include <linux/quota.h>
#include <errno.h>
#include <assert.h>
int main(int argc, char *argv[])
{
int uid, quotasize;
int ret;
struct dqblk quota;
if (argc != 4)
{
assert (argv[0] != NULL);
fprintf(stderr, "Usage: %s <user id> <quota size> <block special "\
"device>\n", argv[0]);
exit(1);
}
uid = atoi(argv[1]);
quotasize = atoi(argv[2]);
if (uid <= 0 || quotasize <= 0 || argv[3] == NULL || strlen(argv[3]) ==
0)
{
fprintf(stderr, "Usage: %s <user id> <quota size> <block special "\
"device>\nBoth user id and quota size must be integers "\
"greater than 0.\n ", argv[0]);
exit(1);
}
quota.dqb_bhardlimit = quotasize;
quota.dqb_bsoftlimit = quotasize;
ret = quotactl(Q_SETQUOTA, argv[3], uid, (caddr_t)"a);
if (ret == -1)
{
switch (errno)
{
case EFAULT:
fprintf(stderr, "Block special device or internal quota struct "\
"invalid.\n");
exit(1);
case EINVAL:
fprintf(stderr, "Kernel not compiled with QUOTA option.\n");
exit(1);
case ENOENT:
fprintf(stderr, "Block special device or part of internal quota "\
"struct does not exist.\n");
exit(1);
case ENOTBLK:
fprintf(stderr, "%s is not a block device.\n", argv[3]);
exit(1);
case EPERM:
fprintf(stderr, "You must be root to run this.\n");
exit(1);
case ESRCH:
fprintf(stderr, "No disc quota found for user %d.\n", uid);
exit(1);
case EUSERS:
fprintf(stderr, "Quota table is full.\n");
exit(1);
default:
fprintf(stderr, "UNKNOWN ERROR.\n");
exit(1);
}
}
/* Success
*/
return 0;
}
---
You are currently subscribed to linuxconf as: [[email protected]]
To unsubscribe, forward this message to [EMAIL PROTECTED]