Esempio n. 1
0
static void
parseproto(
	xfs_mount_t	*mp,
	xfs_inode_t	*pip,
	struct fsxattr	*fsxp,
	char		**pp,
	char		*name)
{
#define	IF_REGULAR	0
#define	IF_RESERVED	1
#define	IF_BLOCK	2
#define	IF_CHAR		3
#define	IF_DIRECTORY	4
#define	IF_SYMLINK	5
#define	IF_FIFO		6

	char		*buf;
	int		committed;
	int		error;
	xfs_fsblock_t	first;
	int		flags;
	xfs_bmap_free_t	flist;
	int		fmt;
	int		i;
	xfs_inode_t	*ip;
	int		len;
	long long	llen;
	int		majdev;
	int		mindev;
	int		mode;
	char		*mstr;
	xfs_trans_t	*tp;
	int		val;
	int		isroot = 0;
	cred_t		creds;
	char		*value;
	struct xfs_name	xname;

	memset(&creds, 0, sizeof(creds));
	mstr = getstr(pp);
	switch (mstr[0]) {
	case '-':
		fmt = IF_REGULAR;
		break;
	case 'r':
		fmt = IF_RESERVED;
		break;
	case 'b':
		fmt = IF_BLOCK;
		break;
	case 'c':
		fmt = IF_CHAR;
		break;
	case 'd':
		fmt = IF_DIRECTORY;
		break;
	case 'l':
		fmt = IF_SYMLINK;
		break;
	case 'p':
		fmt = IF_FIFO;
		break;
	default:
		fprintf(stderr, _("%s: bad format string %s\n"),
			progname, mstr);
		exit(1);
	}
	mode = 0;
	switch (mstr[1]) {
	case '-':
		break;
	case 'u':
		mode |= S_ISUID;
		break;
	default:
		fprintf(stderr, _("%s: bad format string %s\n"),
			progname, mstr);
		exit(1);
	}
	switch (mstr[2]) {
	case '-':
		break;
	case 'g':
		mode |= S_ISGID;
		break;
	default:
		fprintf(stderr, _("%s: bad format string %s\n"),
			progname, mstr);
		exit(1);
	}
	val = 0;
	for (i = 3; i < 6; i++) {
		if (mstr[i] < '0' || mstr[i] > '7') {
			fprintf(stderr, _("%s: bad format string %s\n"),
				progname, mstr);
			exit(1);
		}
		val = val * 8 + mstr[i] - '0';
	}
	mode |= val;
	creds.cr_uid = (int)getnum(pp);
	creds.cr_gid = (int)getnum(pp);
	xname.name = (uchar_t *)name;
	xname.len = name ? strlen(name) : 0;
	tp = libxfs_trans_alloc(mp, 0);
	flags = XFS_ILOG_CORE;
	xfs_bmap_init(&flist, &first);
	switch (fmt) {
	case IF_REGULAR:
		buf = newregfile(pp, &len);
		getres(tp, XFS_B_TO_FSB(mp, len));
		error = libxfs_inode_alloc(&tp, pip, mode|S_IFREG, 1, 0,
					   &creds, fsxp, &ip);
		if (error)
			fail(_("Inode allocation failed"), error);
		flags |= newfile(tp, ip, &flist, &first, 0, 0, buf, len);
		if (buf)
			free(buf);
		libxfs_trans_ijoin(tp, pip, 0);
		newdirent(mp, tp, pip, &xname, ip->i_ino, &first, &flist, 1);
		libxfs_trans_ihold(tp, pip);
		break;

	case IF_RESERVED:			/* pre-allocated space only */
		value = getstr(pp);
		llen = cvtnum(mp->m_sb.sb_blocksize, mp->m_sb.sb_sectsize, value);
		getres(tp, XFS_B_TO_FSB(mp, llen));

		error = libxfs_inode_alloc(&tp, pip, mode|S_IFREG, 1, 0,
					  &creds, fsxp, &ip);
		if (error)
			fail(_("Inode pre-allocation failed"), error);

		libxfs_trans_ijoin(tp, pip, 0);

		newdirent(mp, tp, pip, &xname, ip->i_ino, &first, &flist, 1);
		libxfs_trans_ihold(tp, pip);
		libxfs_trans_log_inode(tp, ip, flags);

		error = libxfs_bmap_finish(&tp, &flist, &committed);
		if (error)
			fail(_("Pre-allocated file creation failed"), error);
		libxfs_trans_commit(tp, 0);
		rsvfile(mp, ip, llen);
		return;

	case IF_BLOCK:
		getres(tp, 0);
		majdev = (int)getnum(pp);
		mindev = (int)getnum(pp);
		error = libxfs_inode_alloc(&tp, pip, mode|S_IFBLK, 1,
				IRIX_MKDEV(majdev, mindev), &creds, fsxp, &ip);
		if (error) {
			fail(_("Inode allocation failed"), error);
		}
		libxfs_trans_ijoin(tp, pip, 0);
		newdirent(mp, tp, pip, &xname, ip->i_ino, &first, &flist, 1);
		libxfs_trans_ihold(tp, pip);
		flags |= XFS_ILOG_DEV;
		break;

	case IF_CHAR:
		getres(tp, 0);
		majdev = (int)getnum(pp);
		mindev = (int)getnum(pp);
		error = libxfs_inode_alloc(&tp, pip, mode|S_IFCHR, 1,
				IRIX_MKDEV(majdev, mindev), &creds, fsxp, &ip);
		if (error)
			fail(_("Inode allocation failed"), error);
		libxfs_trans_ijoin(tp, pip, 0);
		newdirent(mp, tp, pip, &xname, ip->i_ino, &first, &flist, 1);
		libxfs_trans_ihold(tp, pip);
		flags |= XFS_ILOG_DEV;
		break;

	case IF_FIFO:
		getres(tp, 0);
		error = libxfs_inode_alloc(&tp, pip, mode|S_IFIFO, 1, 0,
				&creds, fsxp, &ip);
		if (error)
			fail(_("Inode allocation failed"), error);
		libxfs_trans_ijoin(tp, pip, 0);
		newdirent(mp, tp, pip, &xname, ip->i_ino, &first, &flist, 1);
		libxfs_trans_ihold(tp, pip);
		break;
	case IF_SYMLINK:
		buf = getstr(pp);
		len = (int)strlen(buf);
		getres(tp, XFS_B_TO_FSB(mp, len));
		error = libxfs_inode_alloc(&tp, pip, mode|S_IFLNK, 1, 0,
				&creds, fsxp, &ip);
		if (error)
			fail(_("Inode allocation failed"), error);
		flags |= newfile(tp, ip, &flist, &first, 1, 1, buf, len);
		libxfs_trans_ijoin(tp, pip, 0);
		newdirent(mp, tp, pip, &xname, ip->i_ino, &first, &flist, 1);
		libxfs_trans_ihold(tp, pip);
		break;
	case IF_DIRECTORY:
		getres(tp, 0);
		error = libxfs_inode_alloc(&tp, pip, mode|S_IFDIR, 1, 0,
				&creds, fsxp, &ip);
		if (error)
			fail(_("Inode allocation failed"), error);
		ip->i_d.di_nlink++;		/* account for . */
		if (!pip) {
			pip = ip;
			mp->m_sb.sb_rootino = ip->i_ino;
			libxfs_mod_sb(tp, XFS_SB_ROOTINO);
			mp->m_rootip = ip;
			isroot = 1;
		} else {
			libxfs_trans_ijoin(tp, pip, 0);
			newdirent(mp, tp, pip, &xname, ip->i_ino,
				  &first, &flist, 1);
			pip->i_d.di_nlink++;
			libxfs_trans_ihold(tp, pip);
			libxfs_trans_log_inode(tp, pip, XFS_ILOG_CORE);
		}
		newdirectory(mp, tp, ip, pip);
		libxfs_trans_log_inode(tp, ip, flags);
		error = libxfs_bmap_finish(&tp, &flist, &committed);
		if (error)
			fail(_("Directory creation failed"), error);
		libxfs_trans_ihold(tp, ip);
		libxfs_trans_commit(tp, 0);
		/*
		 * RT initialization.  Do this here to ensure that
		 * the RT inodes get placed after the root inode.
		 */
		if (isroot)
			rtinit(mp);
		tp = NULL;
		for (;;) {
			name = getstr(pp);
			if (!name)
				break;
			if (strcmp(name, "$") == 0)
				break;
			parseproto(mp, ip, fsxp, pp, name);
		}
		libxfs_iput(ip, 0);
		return;
	}
	libxfs_trans_log_inode(tp, ip, flags);
	error = libxfs_bmap_finish(&tp, &flist, &committed);
	if (error) {
		fail(_("Error encountered creating file from prototype file"),
			error);
	}
	libxfs_trans_commit(tp, 0);
}
Esempio n. 2
0
int main()
{
  int           i, gsiproxylimit_i = 1, delegation = 0;
  char         *cmd, *dir_uri, *file, *dir_path, *admin_file, *dn = NULL,
               *help_uri, *p, *content_type, *request_uri, *button, 
               *grst_auri_i, *grst_valid_i, *gsiproxylimit, buf[12];
  GRSTgaclCred *cred;
  GRSTgaclUser *user = NULL;
  GRSTgaclAcl  *acl;
  GRSTgaclPerm  perm = GRST_PERM_NONE;

  help_uri      = getenv("REDIRECT_GRST_HELP_URI"); /* can be NULL */
  admin_file    = getenv("REDIRECT_GRST_ADMIN_FILE");
  dir_path      = getenv("REDIRECT_GRST_DIR_PATH");
  request_uri   = getenv("REQUEST_URI");
  
  if ((dir_path == NULL) || (admin_file == NULL) || (request_uri == NULL))
    {
      puts("Status: 500 Internal Server Error\nContent-type: text/plain\n\n"
           "REDIRECT_GRST_DIR_PATH or REDIRECT_GRST_ADMIN_FILE "
           "or REQUEST_URI missing");
      return -1;
    }

  GRSTgaclInit();

  gsiproxylimit = getenv("REDIRECT_GRST_GSIPROXY_LIMIT");
  if (gsiproxylimit != NULL) sscanf(gsiproxylimit, "%d", &gsiproxylimit_i);

  grst_auri_i  = getenv("GRST_CRED_AURI_0");
  grst_valid_i = getenv("GRST_CRED_VALID_0");
  
  if ((grst_auri_i != NULL) && (strncmp(grst_auri_i, "dn:", 3) == 0))  
    {
      dn = &grst_auri_i[3];
    
      sscanf(grst_valid_i, 
         "notbefore=%*ld notafter=%*ld delegation=%d nist-loa=%*d",
         &delegation);
      
      if (delegation <= gsiproxylimit_i)
        {    
          cred = GRSTgaclCredCreate(grst_auri_i, NULL);
          user = GRSTgaclUserNew(cred);

          /* User has a cert so check for VOMS attributes etc */
          for (i=1; ; i++)
             {
               sprintf (buf, "GRST_CRED_%d", i);

  	       grst_auri_i = getenv(buf);
	       if (grst_auri_i == NULL) break;
 	       
               cred = GRSTgaclCredCreate(grst_auri_i, NULL);
               GRSTgaclUserAddCred(user, cred);
             }

          /* no more VOMS attributes etc found */
        }
    }
  else if ((dn = getenv("SSL_CLIENT_S_DN")) != NULL)
    {
      cred = GRSTgaclCredCreate("dn:", GRSThttpUrlMildencode(dn));
      user = GRSTgaclUserNew(cred);
    }

  if (GRSTgaclUserHasAURI(user, getenv("REDIRECT_GRST_ADMIN_LIST")))
    perm = GRST_PERM_ALL;
  else
    {
      p = getenv("REMOTE_HOST");
      if (p != NULL)
        {
          cred = GRSTgaclCredCreate("dns:", p);
  
          if (user == NULL) user = GRSTgaclUserNew(cred);
          else              GRSTgaclUserAddCred(user, cred);
        }

      acl = GRSTgaclAclLoadforFile(dir_path);
      if (acl != NULL) perm = GRSTgaclAclTestUser(acl, user);
    }
    
  /* we're relying on being a CGI with all this un-free()ed strdup()ing */

  dir_uri  = strdup(request_uri);
  p = rindex(dir_uri, '?');
  if (p != NULL) *p = '\0';
  p = rindex(dir_uri, '/');
  if (p != NULL) p[1] = '\0';

  content_type = getenv("CONTENT_TYPE");

  if ((content_type != NULL) &&
      (GRSTstrCmpShort(content_type, "multipart/form-data; boundary=") == 0))
    {
      uploadfile(dn, perm, help_uri, dir_path, dir_uri, admin_file);
      return 0;
    }
  
  cmd    = GRSThttpGetCGI("cmd");
  button = GRSThttpGetCGI("button");

  file   = GRSThttpGetCGI("file");
  
  if ((index(file, '/') != NULL) ||
      (index(file, '<') != NULL) ||
      (index(file, '>') != NULL) ||
      (index(file, '&') != NULL) ||
      (index(file, '"') != NULL)) file[0] = '\0';

  /* file and directory functions in grst_admin_file.c */

  if (strcmp(cmd, "header") == 0) 
      justheader(dn, perm, help_uri, dir_path, dir_uri, admin_file);
  else if (strcmp(cmd, "footer") == 0) 
      justfooter(dn, perm, help_uri, dir_path, dir_uri, admin_file);
  else if (strcmp(cmd, "managedir") == 0) 
      managedir(dn, perm, help_uri, dir_path, dir_uri, admin_file);
  else if (strcmp(cmd, "print") == 0) 
      printfile(dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd, "history") == 0) 
      filehistory(dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd, "managednlists") == 0) 
      managednlists(user, dn, perm, help_uri, dir_path, dir_uri, admin_file);
  else if (strcmp(cmd, "editdnlist") == 0) 
      editdnlistform(dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd, "edit") == 0)
    { 
      if ((strcasecmp(button, "new directory") == 0) ||
          (strcasecmp(button, "Create") == 0))
       newdirectory(dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
      else
       editfileform(dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
    }
  else if (strcmp(cmd, "editaction") == 0) 
      editfileaction(dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd, "editdnlistaction") == 0) 
      editdnlistaction(dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd, "delete") == 0) 
      deletefileform(dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd, "deleteaction") == 0) 
     deletefileaction(dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd, "rename") == 0) 
     renameform(dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd, "renameaction") == 0) 
     renameaction(dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd, "ziplist") == 0) 
     ziplist(dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd, "unzipfile") == 0) 
     unzipfile(dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd, "create_acl") == 0) 
     create_acl(dn, perm, help_uri, dir_path, file, dir_uri, admin_file);

  /* GACL functions in grst_admin_gacl.c */

  else if (strcmp(cmd, "show_acl") == 0)
     show_acl(0, user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd, "admin_acl") == 0)
     show_acl(1, user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd, "acl_history") == 0)
     show_acl(2, user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd, "revert_acl") == 0)
    revert_acl(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
    //show_acl(2, user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd,"new_entry_form")==0)
     new_entry_form(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd,"new_entry")==0)
     new_entry(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd,"del_entry_sure")==0)
     del_entry_sure(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd,"del_entry")==0)
     del_entry(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd,"edit_entry_form")==0)
     edit_entry_form(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd,"edit_entry")==0)
     edit_entry(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd,"add_cred_form")==0)
     add_cred_form(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd,"add_cred")==0)
     add_cred(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd,"del_cred_sure")==0)
     del_cred_sure(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);
  else if (strcmp(cmd,"del_cred")==0)
     del_cred(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file);

  /* you what? */

  else GRSThttpError("500 Internal Server Error");
}