Beispiel #1
0
/* we have this on HPUX, ... */
static int sys_path_to_bdev(const char *path, char **mntpath, char **bdev, char **fs)
{
	int ret = -1;
	char dev_disk[256];
	SMB_STRUCT_STAT S;

	if (!path||!mntpath||!bdev||!fs)
		smb_panic("sys_path_to_bdev: called with NULL pointer");

	(*mntpath) = NULL;
	(*bdev) = NULL;
	(*fs) = NULL;
	
	/* find the block device file */

	if ((ret=sys_stat(path, &S))!=0) {
		return ret;
	}
	
	if ((ret=devnm(S_IFBLK, S.st_dev, dev_disk, 256, 1))!=0) {
		return ret;	
	}

	/* we should get the mntpath right...
	 * but I don't know how
	 * --metze
	 */
	(*mntpath) = SMB_STRDUP(path);
	(*bdev) = SMB_STRDUP(dev_disk);
	if ((*mntpath)&&(*bdev)) {
		ret = 0;
	} else {
		SAFE_FREE(*mntpath);
		SAFE_FREE(*bdev);
		ret = -1;
	}	
	
	
	return ret;	
}
Beispiel #2
0
/*
 * Private method that converts a psinfo struct into a Ruby struct.
 */
static VALUE proctable_getprocstruct(struct pst_status *p)
{
    char state[10];
    char flag[12];
    char ttydev[MAXPATHLEN+1];
    VALUE v_tty, v_struct;

    switch( p->pst_stat )
    {
    case PS_SLEEP:
        strcpy(state,SLEEP);
        break;
    case PS_RUN:
        strcpy(state,RUN);
        break;
    case PS_STOP:
        strcpy(state,STOP);
        break;
    case PS_ZOMBIE:
        strcpy(state,ZOMBIE);
        break;
    case PS_IDLE:
        strcpy(state,IDLE);
        break;
    case PS_OTHER:
        strcpy(state,OTHER);
        break;
    default:
        strcpy(state,"unknown");
    }

    /* If the major number is -1, there is no associated tty */
    if(p->pst_term.psd_major != -1) {
        devnm(
            S_IFCHR,
            (dev_t)((p->pst_term.psd_major << 24) | p->pst_term.psd_minor),
            ttydev,
            sizeof(ttydev),
            1
        );
        v_tty = rb_str_new2(ttydev);
    }
    else {
        v_tty = rb_str_new2("");
    }

    v_struct = rb_struct_new(sProcStruct,
                             rb_str_new2(p->pst_ucomm),
                             INT2NUM(p->pst_uid),
                             INT2NUM(p->pst_pid),
                             INT2NUM(p->pst_ppid),
                             INT2NUM(p->pst_dsize),
                             INT2NUM(p->pst_tsize),
                             INT2NUM(p->pst_ssize),
                             INT2NUM(p->pst_nice),
                             v_tty,
                             INT2NUM(p->pst_pgrp),
                             INT2NUM(p->pst_pri),
                             INT2NUM(p->pst_addr),
                             INT2NUM(p->pst_cpu),
                             INT2NUM(p->pst_utime),
                             INT2NUM(p->pst_stime),
                             rb_time_new(p->pst_start,0),
                             INT2NUM(p->pst_flag),
                             rb_str_new2(state),
                             INT2NUM(p->pst_wchan),
                             INT2NUM(p->pst_procnum),
                             rb_str_new2(p->pst_cmd),
                             rb_str_new2(p->pst_cmd),
                             INT2NUM(p->pst_time),
                             INT2NUM(p->pst_cpticks),
                             INT2NUM(p->pst_cptickstotal),
                             INT2NUM(p->pst_fss),
                             rb_float_new(p->pst_pctcpu),
                             INT2NUM(p->pst_rssize),
                             INT2NUM(p->pst_suid),
                             INT2NUM(p->pst_shmsize),
                             INT2NUM(p->pst_mmsize),
                             INT2NUM(p->pst_usize),
                             INT2NUM(p->pst_iosize),
                             INT2NUM(p->pst_vtsize),
                             INT2NUM(p->pst_vdsize),
                             INT2NUM(p->pst_vssize),
                             INT2NUM(p->pst_vshmsize),
                             INT2NUM(p->pst_vmmsize),
                             INT2NUM(p->pst_vusize),
                             INT2NUM(p->pst_viosize),
                             UINT2NUM(p->pst_minorfaults),
                             UINT2NUM(p->pst_majorfaults),
                             UINT2NUM(p->pst_nswap),
                             UINT2NUM(p->pst_nsignals),
                             UINT2NUM(p->pst_msgrcv),
                             UINT2NUM(p->pst_msgsnd),
                             INT2NUM(p->pst_maxrss),
                             INT2NUM(p->pst_sid),
                             INT2NUM(p->pst_schedpolicy),
                             INT2NUM(p->pst_ticksleft),
                             INT2NUM(p->pst_euid),
                             INT2NUM(p->pst_egid),
                             INT2NUM(p->pst_gid),
                             INT2NUM(p->pst_sgid)
                            );

    OBJ_FREEZE(v_struct);

    return v_struct;
}
Beispiel #3
0
BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
{
  int r;
  struct dqblk D;
  uid_t euser_id;
#if !defined(__FreeBSD__) && !defined(AIX) && !defined(__OpenBSD__)
  char dev_disk[256];
  SMB_STRUCT_STAT S;

  /* find the block device file */

#ifdef HPUX
  /* Need to set the cache flag to 1 for HPUX. Seems
   * to have a significant performance boost when
   * lstat calls on /dev access this function.
   */
  if ((sys_stat(path, &S)<0) || (devnm(S_IFBLK, S.st_dev, dev_disk, 256, 1)<0))
#else
  if ((sys_stat(path, &S)<0) || (devnm(S_IFBLK, S.st_dev, dev_disk, 256, 0)<0)) 
	return (False);
#endif /* ifdef HPUX */

#endif /* !defined(__FreeBSD__) && !defined(AIX) && !defined(__OpenBSD__) */

  euser_id = geteuid();

#ifdef HPUX
  /* for HPUX, real uid must be same as euid to execute quotactl for euid */
  save_re_uid();
  if (set_re_uid() != 0) return False;
  
  r=quotactl(Q_GETQUOTA, dev_disk, euser_id, &D);

  restore_re_uid();
#else 
#if defined(__FreeBSD__) || defined(__OpenBSD__)
  {
    /* FreeBSD patches from Marty Moll <*****@*****.**> */
    gid_t egrp_id;
 
    save_re_uid();
    set_effective_uid(0);

    egrp_id = getegid();
    r= quotactl(path,QCMD(Q_GETQUOTA,USRQUOTA),euser_id,(char *) &D);

    /* As FreeBSD has group quotas, if getting the user
       quota fails, try getting the group instead. */
    if (r) {
	    r= quotactl(path,QCMD(Q_GETQUOTA,GRPQUOTA),egrp_id,(char *) &D);
    }

    restore_re_uid();
  }
#elif defined(AIX)
  /* AIX has both USER and GROUP quotas: 
     Get the USER quota ([email protected]) */
  r= quotactl(path,QCMD(Q_GETQUOTA,USRQUOTA),euser_id,(char *) &D);
#else /* !__FreeBSD__ && !AIX && !__OpenBSD__ */
  r=quotactl(Q_GETQUOTA, dev_disk, euser_id, &D);
#endif /* !__FreeBSD__ && !AIX && !__OpenBSD__ */
#endif /* HPUX */

  /* Use softlimit to determine disk space, except when it has been exceeded */
#if defined(__FreeBSD__) || defined(__OpenBSD__)
  *bsize = DEV_BSIZE;
#else /* !__FreeBSD__ && !__OpenBSD__ */
  *bsize = 1024;
#endif /*!__FreeBSD__ && !__OpenBSD__ */

  if (r)
    {
      if (errno == EDQUOT) 
	{
 	  *dfree =0;
 	  *dsize =D.dqb_curblocks;
 	  return (True);
	}
      else return(False);
    }

  /* If softlimit is zero, set it equal to hardlimit.
   */

  if (D.dqb_bsoftlimit==0)
    D.dqb_bsoftlimit = D.dqb_bhardlimit;

  if (D.dqb_bsoftlimit==0)
    return(False);
  /* Use softlimit to determine disk space, except when it has been exceeded */
  if ((D.dqb_curblocks>D.dqb_bsoftlimit)
#if !defined(__FreeBSD__) && !defined(__OpenBSD__)
||((D.dqb_curfiles>D.dqb_fsoftlimit) && (D.dqb_fsoftlimit != 0))
#endif
    ) {
      *dfree = 0;
      *dsize = D.dqb_curblocks;
    }
  else {
    *dfree = D.dqb_bsoftlimit - D.dqb_curblocks;
    *dsize = D.dqb_bsoftlimit;
  }
  return (True);
}
Beispiel #4
0
BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
{
  int r;
  struct dqblk D;
  uid_t euser_id;
#if !defined(__FreeBSD__) && !defined(AIX) && !defined(__OpenBSD__) && !defined(__DragonFly__)
  char dev_disk[256];
  SMB_STRUCT_STAT S;

  /* find the block device file */

#ifdef HPUX
  /* Need to set the cache flag to 1 for HPUX. Seems
   * to have a significant performance boost when
   * lstat calls on /dev access this function.
   */
  if ((sys_stat(path, &S)<0) || (devnm(S_IFBLK, S.st_dev, dev_disk, 256, 1)<0))
#else
  if ((sys_stat(path, &S)<0) || (devnm(S_IFBLK, S.st_dev, dev_disk, 256, 0)<0)) 
	return (False);
#endif /* ifdef HPUX */

#endif /* !defined(__FreeBSD__) && !defined(AIX) && !defined(__OpenBSD__) && !defined(__DragonFly__) */

  euser_id = geteuid();

#ifdef HPUX
  /* for HPUX, real uid must be same as euid to execute quotactl for euid */
  save_re_uid();
  if (set_re_uid() != 0) return False;
  
  r=quotactl(Q_GETQUOTA, dev_disk, euser_id, &D);

  restore_re_uid();
#else 
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
  {
    /* FreeBSD patches from Marty Moll <*****@*****.**> */
    gid_t egrp_id;
#if defined(__FreeBSD__) || defined(__DragonFly__)
    SMB_DEV_T devno;
    struct statfs *mnts;
    SMB_STRUCT_STAT st;
    int mntsize, i;
    
    if (sys_stat(path,&st) < 0)
        return False;
    devno = st.st_dev;

    mntsize = getmntinfo(&mnts,MNT_NOWAIT);
    if (mntsize <= 0)
        return False;

    for (i = 0; i < mntsize; i++) {
        if (sys_stat(mnts[i].f_mntonname,&st) < 0)
            return False;
        if (st.st_dev == devno)
            break;
    }
    if (i == mntsize)
        return False;
#endif
    
    become_root();

#if defined(__FreeBSD__) || defined(__DragonFly__)
    if (strcmp(mnts[i].f_fstypename,"nfs") == 0) {
        BOOL retval;
        retval = nfs_quotas(mnts[i].f_mntfromname,euser_id,bsize,dfree,dsize);
        unbecome_root();
        return retval;
    }
#endif

    egrp_id = getegid();
    r= quotactl(path,QCMD(Q_GETQUOTA,USRQUOTA),euser_id,(char *) &D);

    /* As FreeBSD has group quotas, if getting the user
       quota fails, try getting the group instead. */
    if (r) {
	    r= quotactl(path,QCMD(Q_GETQUOTA,GRPQUOTA),egrp_id,(char *) &D);
    }

    unbecome_root();
  }
#elif defined(AIX)
  /* AIX has both USER and GROUP quotas: 
     Get the USER quota ([email protected]) */
#ifdef _AIXVERSION_530
  {
    struct statfs statbuf;
    quota64_t user_quota;
    if (statfs(path,&statbuf) != 0)
      return False;
    if(statbuf.f_vfstype == MNT_J2)
    {
    /* For some reason we need to be root for jfs2 */
      become_root();
      r = quotactl(path,QCMD(Q_J2GETQUOTA,USRQUOTA),euser_id,(char *) &user_quota);
      unbecome_root();
    /* Copy results to old struct to let the following code work as before */
      D.dqb_curblocks  = user_quota.bused;
      D.dqb_bsoftlimit = user_quota.bsoft;
      D.dqb_bhardlimit = user_quota.bhard;
    }
    else if(statbuf.f_vfstype == MNT_JFS)
    {
#endif /* AIX 5.3 */
  save_re_uid();
  if (set_re_uid() != 0) 
    return False;
  r= quotactl(path,QCMD(Q_GETQUOTA,USRQUOTA),euser_id,(char *) &D);
  restore_re_uid();
#ifdef _AIXVERSION_530
    }
    else
      r = 1; /* Fail for other FS-types */
  }
#endif /* AIX 5.3 */
#else /* !__FreeBSD__ && !AIX && !__OpenBSD__ && !__DragonFly__ */
  r=quotactl(Q_GETQUOTA, dev_disk, euser_id, &D);
#endif /* !__FreeBSD__ && !AIX && !__OpenBSD__ && !__DragonFly__ */
#endif /* HPUX */

  /* Use softlimit to determine disk space, except when it has been exceeded */
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
  *bsize = DEV_BSIZE;
#else /* !__FreeBSD__ && !__OpenBSD__ && !__DragonFly__ */
  *bsize = 1024;
#endif /*!__FreeBSD__ && !__OpenBSD__ && !__DragonFly__ */

  if (r)
    {
      if (errno == EDQUOT) 
	{
 	  *dfree =0;
 	  *dsize =D.dqb_curblocks;
 	  return (True);
	}
      else return(False);
    }

  /* If softlimit is zero, set it equal to hardlimit.
   */

  if (D.dqb_bsoftlimit==0)
    D.dqb_bsoftlimit = D.dqb_bhardlimit;

  if (D.dqb_bsoftlimit==0)
    return(False);
  /* Use softlimit to determine disk space, except when it has been exceeded */
  if ((D.dqb_curblocks>D.dqb_bsoftlimit)
#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__DragonFly__)
||((D.dqb_curfiles>D.dqb_fsoftlimit) && (D.dqb_fsoftlimit != 0))
#endif
    ) {
      *dfree = 0;
      *dsize = D.dqb_curblocks;
    }
  else {
    *dfree = D.dqb_bsoftlimit - D.dqb_curblocks;
    *dsize = D.dqb_bsoftlimit;
  }
  return (True);
}