[S] Advfs quotas

From: Paul Wood <pcwood_at_uniblab.ocis.temple.edu>
Date: Mon, 15 Jul 96 11:46:10 EDT

My Original Message:

> We need to create a program for use by our help desk to allow them to
> change disk quotas on users accounts. There is a system function call
> (quotactl) but it says it only works on ufs type file systems. There
> is also some mention of supporting advfs, but my 4.0T beta version
> doesn't have anything. I am very curious if the actual 4.0 will
> work correctly.

Thanks very much for the replys from:

From: Trevor Stott <trevor.stott_at_sheridanc.on.ca>
From: Paul Richards <paulr_at_intermix.engr.arizona.edu>
From: System Administrator <sysadmin_at_homer.bus.miami.edu>
From: Tim Mooney <mooney_at_dogbert.cc.ndsu.NoDak.edu>
From: Nick Hill - RAL CISD Systems Group <NMH1_at_axprl1.rl.ac.uk>

The setquota.c code by Richad Jackson works on our 4.0 beta workstation
so I am going to write my own quota setting program here using it as a
guideline.


----------------------------------------------------------------------------

From: Trevor Stott <trevor.stott_at_sheridanc.on.ca>

Try sudo... I use it on an Ultrix box to allow certain users to use
certain root commands. I think the current release is 1.4. Hope this
helps!
                                                                See Ya!
------------------------------------------------------------------------------

From: Paul Richards <paulr_at_intermix.engr.arizona.edu>

I use vedquota to manipulate quotas on advfs partitions. It was available
under 3.2d and is on my 4.0 release system, as well.

----------------------------------------------------------------------------

From: System Administrator <sysadmin_at_homer.bus.miami.edu>

It works for both...

----------------------------------------------------------------------------

From: Tim Mooney <mooney_at_dogbert.cc.ndsu.NoDak.edu>

Paul-

1) You could just use `sudo' to give your helpdesk access to the `vedquota'
command. The advantage of doing things this way is that in the future when
someone like your helpdesk or operations staff needs special access to a
set of commands you will already have sudo installed and it will be a trivial
matter to give them access to the commands they need. Sudo can be found at:

        ftp://ftp.cs.colorado.edu/pub/sysadmin/sudo/cu-sudo.v1.4.tar.Z

2) The documentation for the quotactl command threw me too, but if you check
the archive for this mailing list you will see that a very handy program to
do exactly what you want has already been written by a gentleman named Richard
Jackson. He apparently did his homework and found out that despite what
the quotactl man page says, quotactl() will work for AdvFS quotas (even under
3.2). Mr. Jackson's program is very nice because everything can be
accomplished on the command line -- it's not interactive.

I recommend you get sudo and install it so that you helpdesk can use vedquota.
I recommend you get Mr. Jackson's program (and accompanying scripts) too, as
they will prove useful to you someday.

Tim

----------------------------------------------------------------------------


From: Nick Hill - RAL CISD Systems Group <NMH1_at_axprl1.rl.ac.uk>


/**********************************************************************/
/* */
/* NAME: setquota.c */
/* */
/* PROGRAMMER: Richard Jackson DATE: 950328 */
/* */
/* PURPOSE: Set the quota for a specified user on a specified */
/* filesystem. */
/* */
/* NOTES: */
/* To execute: */
/* 1. setquota username softlimit hardlimit filesystem */
/* for example, */
/* ./setquota jblow 2000 2500 /var/spool/mail */
/* */
/* To build under OSF/1 3.x: */
/* 1. cc -o setquota setquota.c */
/* 2. strip setquota */
/* */
/* Only root or authorized users can successfully run this program. */
/* Authorized users are anybody in group adm */
/* */
/* */
/* MODIFICATION HISTORY: */
/* DATE MOD NAME DESCRIPTION */
/* */
/* 950328 AAA rjackson initial version */
/* 960214 Nick Hill Changed name to setquota and add tests */
/* for authorized non root users to set */
/* quotas */
/* */
/**********************************************************************/

#include <stdio.h> /* printf() */
#include <pwd.h> /* getpwnam() */
#include <stdlib.h> /* atoi(), exit() */
#include <sys/types.h>
#include <ufs/quota.h> /* quotactl() */
#include <sys/mount.h> /* statfs() */
#include <errno.h> /* perror() */
#include <unistd.h> /* geteuid() */
#include <grp.h> /* getgrnam(), endgrent() */
#include <string.h> /* strcpy(), strcmp() */

main (int argc, char *argv[])
{
  struct dqblk dqblk_st; /* disk quota structure */
  struct passwd *pw; /* passwd file entry structure */
  u_int softlimit; /* quota soft limit */
  u_int hardlimit; /* quota hard limit */
  struct statfs statfs_st; /* mounted filesystem info */
  uid_t uid; /* user id */
  char user_running[31]; /* username running the program*/
  char progname[31]; /* program name */
  struct group *gstruct; /* group entry structure */
  int authorize=0; /* allow user to do it? 0=no, 1=yes */
  char *ptr, buffer[255];
  char **ptr2;
  
 strcpy(buffer,argv[0]);
 ptr=strrchr(buffer,'/');
 if (ptr==NULL)
   {strncpy(progname,buffer,30);
    progname[30] = '\0';
   }
 else
   {strncpy(progname,++ptr,30);
    progname[30]='\0';
   }

/*
 * make sure we have the required arguments
 */
  if (argc != 5)
  {
    fprintf(stderr, "Usage: %s username softlimit hardlimit filesystem\n",progname);
    fprintf(stderr, " :\n");
    fprintf(stderr, " : soft and hard limits are in units of 1024 as reported\n");
    fprintf(stderr, " : by other Advfs utilities. Eg 204800 is 200Mb\n");
    exit(1);
  }

/*
 * this program requires root privs
 */
  if ( geteuid() != (uid_t) 0)
  {
    fprintf(stderr, "%s: you do not have authorization to use %s\n", progname,progname);
    exit(1);
  }

/*
 * determine who is running me
 */
 
    uid = getuid();
    if ((pw = getpwuid(uid)) == (struct passwd *) NULL)
      {
       fprintf(stderr, "%s: can't find passwd entry for uid %d\n", progname, uid);
       exit(1);
      }
   
    strcpy(user_running,pw->pw_name);
/*
 * check user running against membership of group adm
 */
 
  if ((gstruct= getgrnam("adm")) == NULL )
    {fprintf(stderr,"%s: failed to get group entry for authentication\n",progname);
     exit(1);
    }

  ptr2=gstruct->gr_mem;
  while (ptr2[0] != NULL)
    {if (!strcmp(user_running,ptr2[0]))
       {authorize=1;
        break;
       }
     ptr2++;
    }
  endgrent();
  
  if ((authorize == 0) && strcmp(user_running,"root"))
    {fprintf(stderr,"%s: User %s not authorized to use %s\n",progname,user_running,progname);
     exit(1);
    }
  
/*
 * does this user exist in the /etc/passwd file?
 */
  if ((pw = getpwnam(argv[1])) == (struct passwd *) NULL)
  {
    fprintf(stderr, "%s: can't find passwd entry for %s\n", argv[0], argv[1]);
    exit(1);
  }

/*
 * check if quota's are valid for the specified filesystem
 */
  if (statfs(argv[4], &statfs_st, sizeof(struct statfs)))
  {
    fprintf(stderr, "%s: statfs() failed, errno=%d\n", argv[0], errno);
    exit(1);
  }

/*
 * Filesystem should manage quotas or be AdvFS (i.e., AdvFS always
 * manages quotas). M_QUOTA appears to not be set for AdvFS.
 */
  if (!((statfs_st.f_flags & M_QUOTA) || (statfs_st.f_type == MOUNT_MSFS)))
  {
    fprintf(stderr, "%s: quota is not enabled for %s filesystem\n",
         argv[0], argv[4]);
    exit(1);
  }

/*
 * fetch current values
 */
  if (quotactl(argv[4], QCMD(Q_GETQUOTA, USRQUOTA), pw->pw_uid, &dqblk_st))
  {
    fprintf(stderr, "%s: quotactl() GETQUOTA failed, errno=%d\n",
         argv[0], errno);
    exit(1);
  }
  
  fprintf(stdout,"\n%s : Setting quotas for user %s\n",progname, pw->pw_name);
  fprintf(stdout,"%s : Old softlimit in %s is %d\n",progname,argv[4],dqblk_st.dqb_bsoftlimit/2);
  fprintf(stdout,"%s : Old hardlimit in %s is %d\n",progname,argv[4],dqblk_st.dqb_bhardlimit/2);
  

  if((atoi(argv[2]) < 0) || (atoi(argv[3]) < 0))
    {fprintf(stderr,"%s : invalid negative value given for new soft or hard limit\n",progname);
     exit(1);
    }
    
    
  softlimit = atoi(argv[2]);
  hardlimit = atoi(argv[3]);
/*
 * disk blocks (512 bytes each) times 2. vquota reports number of 1024
 * byte blocks.
 */
  dqblk_st.dqb_bsoftlimit = softlimit * 2;
  dqblk_st.dqb_bhardlimit = hardlimit * 2;
  
  fprintf(stdout,"%s : New softlimit in %s is %d\n",progname,argv[4],dqblk_st.dqb_bsoftlimit/2);
  fprintf(stdout,"%s : New hardlimit in %s is %d\n\n",progname,argv[4],dqblk_st.dqb_bhardlimit/2);


/*
 * set new quotas
 */
  if (quotactl(argv[4], QCMD(Q_SETQUOTA, USRQUOTA), pw->pw_uid, &dqblk_st))
  {
    fprintf(stderr, "%s: quotactl() SETQUOTA failed, errno=%d\n",
         argv[0], errno);
    exit(1);
  }

  exit(0);

}

-- 
-=( Paul Wood                            http://thunder.temple.edu/~pcwood)=-
-=( pcwood_at_uniblab.ocis.temple.edu     Temple University Computer Services)=-
Received on Mon Jul 15 1996 - 18:11:50 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:46 NZDT