Example #1
0
static int directory_exec(struct cw_channel *chan, int argc, char **argv)
{
	struct localuser *u;
	struct cw_config *cfg;
	char *context, *dialcontext, *dirintro;
	int res = 0;
	int last = 1;

	if (argc < 1 || argc > 3) {
		cw_log(LOG_ERROR, "Syntax: %s\n", directory_syntax);
		return -1;
	}

	LOCAL_USER_ADD(u);

	context = argv[0];
	dialcontext = (argc > 1 && argv[1][0] ? argv[1] : context);
	if (argc > 2 && strchr(argv[2], 'f'))
		last = 0;

	cfg = realtime_directory(context);
	if (!cfg) {
		LOCAL_USER_REMOVE(u);
		return -1;
	}

	dirintro = cw_variable_retrieve(cfg, context, "directoryintro");
	if (cw_strlen_zero(dirintro))
		dirintro = cw_variable_retrieve(cfg, "general", "directoryintro");
	if (cw_strlen_zero(dirintro)) {
		if (last)
			dirintro = "dir-intro";	
		else
			dirintro = "dir-intro-fn";
	}
	
	for (;;) {
		if (!res)
			res = cw_streamfile(chan, dirintro, chan->language);
		if (!res)
			res = cw_waitstream(chan, CW_DIGIT_ANY);
		cw_stopstream(chan);
		if (!res)
			res = cw_waitfordigit(chan, 5000);
		if (res >0) {
			res = do_directory(chan, cfg, context, dialcontext, res, last);
			if (res > 0){
				res = cw_waitstream(chan, CW_DIGIT_ANY);
				cw_stopstream(chan);
				if (res >= 0) {
					continue;
				}
			}
		}
		break;
	}
	cw_config_destroy(cfg);
	LOCAL_USER_REMOVE(u);
	return res;
}
Example #2
0
static void expand_fs(char *path, struct cramfs_inode *inode)
{
	if (S_ISDIR(inode->mode))
		do_directory(path, inode);
	else if (S_ISREG(inode->mode))
		do_file(path, inode);
	else if (S_ISLNK(inode->mode))
		do_symlink(path, inode);
	else
		do_special_inode(path, inode);
}
Example #3
0
File: wad.c Project: jsummers/deark
static void de_run_wad(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	i64 pos;

	d = de_malloc(c, sizeof(lctx));

	pos = 0;
	if(!do_header(c, d, pos)) goto done;
	pos += 12;

	do_directory(c, d, d->dir_pos);

done:
	de_free(c, d);
}
Example #4
0
void do_file_entry(const u8* base,
		   const char* dir,
	           const char* path,
		   const char* name, int namelen, 
		   const struct cramfs_inode* inode)
{
   int dirlen=strlen(dir);
   int pathlen=strlen(path);
   char pname[dirlen+pathlen+namelen+3];
   const char* basename;
   
   if (dirlen) {
      strncpy(pname, dir, dirlen);
   }
   
   if (pathlen) {
      if (dirlen) {
	 pname[dirlen]='/';
	 ++dirlen;
      }
      strncpy(pname+dirlen, path, pathlen);
   }
   
   if (namelen) {
      if (pathlen+dirlen) {
	 pname[dirlen+pathlen]='/';
	 ++pathlen;
      }
      strncpy(pname+dirlen+pathlen, name, namelen);
   }

   pname[pathlen+dirlen+namelen]=0;
   basename=namelen ? pname+dirlen+pathlen : "/";
   
   // Create things here
   printmode(inode);
   printuidgid(inode);
   
   if (S_ISREG(inode->mode)) {
      do_file(base, inode->offset<<2, inode->size, pname, basename, inode->mode);
   } else  if (S_ISDIR(inode->mode)) {
      do_directory(base, inode->offset<<2, inode->size, pname, basename, inode->mode);
   } else  if (S_ISLNK(inode->mode)) {
      do_symlink(base, inode->offset<<2, inode->size, pname, basename, inode->mode);
   } else  if (S_ISFIFO(inode->mode)) {
      do_fifo(base, inode->offset<<2, inode->size, pname, basename, inode->mode, inode->uid, inode->gid);
   } else  if (S_ISSOCK(inode->mode)) {
      do_socket(base, inode->offset<<2, inode->size, pname, basename, inode->mode);
   } else  if (S_ISCHR(inode->mode)) {
      do_chrdev(base, inode->offset<<2, inode->size, pname, basename, inode->mode, inode->uid, inode->gid);
   } else  if (S_ISBLK(inode->mode)) {
      do_blkdev(base, inode->offset<<2, inode->size, pname, basename, inode->mode, inode->uid, inode->gid);
   } else {
      do_unknown(base, inode->offset<<2, inode->size, pname, basename, inode->mode);
   }
   
   if (geteuid() == 0) {
      if (lchown(pname, inode->uid, inode->gid) == -1)
         perror("cannot change owner or group");
   } else if(opt_idsfile && path && path[0]) {
      char dfp[1024];
      char *p;
      FILE *f;

      strcpy(dfp,pname);
      p = strrchr(dfp,'/');
      if (!p) {
         fprintf(stderr,"could not find path in '%s'\n",pname);
         return;
      }
      strcpy(p+1,opt_idsfile);
      f = fopen(dfp,"at");
      if (!f) {
   	    perror(dfp);
   	    return;
      }
	  fprintf(f,"%s,%u,%u,%08x\n",basename,inode->uid,inode->gid,inode->mode);
      fclose(f);
   }

   if (geteuid() == 0 || !opt_idsfile) {
      if (inode->mode & (S_ISGID|S_ISUID|S_ISVTX)) {
        if (0 != chmod(pname, inode->mode)){
          perror("chmod");
          return;
        }
      }
   }


   
   printf("\n");
}
static int directory_exec(struct ast_channel *chan, void *data)
{
	int res = 0;
	struct localuser *u;
	struct ast_config *cfg;
	int last = 1;
	int fromappvm = 0;
	char *context, *dialcontext, *dirintro, *options;

	if (ast_strlen_zero(data)) {
		ast_log(LOG_WARNING, "Directory requires an argument (context[,dialcontext])\n");
		return -1;
	}

	LOCAL_USER_ADD(u);

	context = ast_strdupa(data);
	dialcontext = strchr(context, '|');
	if (dialcontext) {
		*dialcontext = '\0';
		dialcontext++;
		options = strchr(dialcontext, '|');
		if (options) {
			*options = '\0';
			options++; 
			if (strchr(options, 'f'))
				last = 0;
			if (strchr(options, 'v'))
				fromappvm = 1;
		}
	} else	
		dialcontext = context;

	cfg = realtime_directory(context);
	if (!cfg) {
		LOCAL_USER_REMOVE(u);
		return -1;
	}

	dirintro = ast_variable_retrieve(cfg, context, "directoryintro");
	if (ast_strlen_zero(dirintro))
		dirintro = ast_variable_retrieve(cfg, "general", "directoryintro");
	if (ast_strlen_zero(dirintro)) {
		if (last)
			dirintro = "dir-intro";	
		else
			dirintro = "dir-intro-fn";
	}

	if (chan->_state != AST_STATE_UP) 
		res = ast_answer(chan);

	for (;;) {
		if (!res)
			res = ast_streamfile(chan, dirintro, chan->language);
		if (!res)
			res = ast_waitstream(chan, AST_DIGIT_ANY);
		ast_stopstream(chan);
		if (!res)
			res = ast_waitfordigit(chan, 5000);
		if (res > 0) {
			res = do_directory(chan, cfg, context, dialcontext, res, last, fromappvm);
			if (res > 0) {
				res = ast_waitstream(chan, AST_DIGIT_ANY);
				ast_stopstream(chan);
				if (res >= 0) {
					continue;
				}
			}
		}
		break;
	}
	ast_config_destroy(cfg);
	LOCAL_USER_REMOVE(u);
	return res;
}
Example #6
0
void do_file_entry(const u8 * base, const char *dir, const char *path, const char *name, int namelen, const struct cramfs_inode *inode) {
	int dirlen = strlen(dir);
	int pathlen = strlen(path);
	char pname[dirlen + pathlen + namelen + 3];
	const char *basename;
	u32 gid = inode->gid;

	if (dirlen) {
		strncpy(pname, dir, dirlen);
	}

	if (pathlen) {
		if (dirlen) {
			pname[dirlen] = '/';
			++dirlen;
		}
		strncpy(pname + dirlen, path, pathlen);
	}

	if (namelen) {
		if (pathlen + dirlen) {
			pname[dirlen + pathlen] = '/';
			++pathlen;
		}
		strncpy(pname + dirlen + pathlen, name, namelen);
	}

	pname[pathlen + dirlen + namelen] = 0;
	basename = namelen ? pname + dirlen + pathlen : "/";

	// Create things here
	//printmode(inode);
	//printuidgid(inode);

	if (S_ISREG(inode->mode)) {

		u32 size = inode->size;

		if (gid > DIR_GID) {
			// sirius: this is a special LG encoding of the size.
			// misusing gid field to encode the most significant byte of the size
			int lg = gid - DIR_GID;
			gid -= lg;
			lg = lg * 0x1000000;
			size += (lg);
		}

		do_file(base, inode->offset << 2, size, pname, basename, inode->mode);
	} else if (S_ISDIR(inode->mode)) {
		if (DIR_GID == 0) {
			DIR_GID = gid;
		}
		do_directory(base, inode->offset << 2, inode->size, pname, basename, inode->mode);
	} else if (S_ISLNK(inode->mode)) {
		do_symlink(base, inode->offset << 2, inode->size, pname, basename, inode->mode);
	} else if (S_ISFIFO(inode->mode)) {
		do_fifo(base, inode->offset << 2, inode->size, pname, basename, inode->mode, inode->uid, inode->gid);
	} else if (S_ISSOCK(inode->mode)) {
		do_socket(base, inode->offset << 2, inode->size, pname, basename, inode->mode);
	} else if (S_ISCHR(inode->mode)) {
		do_chrdev(base, inode->offset << 2, inode->size, pname, basename, inode->mode, inode->uid, inode->gid);
	} else if (S_ISBLK(inode->mode)) {
		do_blkdev(base, inode->offset << 2, inode->size, pname, basename, inode->mode, inode->uid, inode->gid);
	} else {
		do_unknown(base, inode->offset << 2, inode->size, pname, basename, inode->mode);
	}

	if (geteuid() == 0) {
		if (lchown(pname, inode->uid, gid) == -1)
			perror("cannot change owner or group");
	} else if (opt_idsfile && path && path[0]) {
		char dfp[1024];
		char *p;
		FILE *f;

		strcpy(dfp, pname);
		p = strrchr(dfp, '/');
		if (!p) {
			fprintf(stderr, "could not find path in '%s'\n", pname);
			return;
		}
		strcpy(p + 1, opt_idsfile);
		f = fopen(dfp, "at");
		if (!f) {
			perror(dfp);
			return;
		}
		fprintf(f, "%s,%u,%u,%08x\n", basename, inode->uid, inode->gid, inode->mode);
		fclose(f);
	}

	if (geteuid() == 0 || !opt_idsfile) {
		if (inode->mode & (S_ISGID | S_ISUID | S_ISVTX)) {
			if (0 != chmod(pname, inode->mode)) {
				perror("chmod");
				return;
			}
		}
	}
	//printf("\n");
}
Example #7
0
/*  find domain assigned the parameter mcs category
 *  return >= 0 (0 is valuid domid) on success
 *  return -1 if nothing found
 *  return -2 on error
 */
static int
get_domid_by_mcs (xs_handle_t *xsh, uint16_t cat)
{
        int ret = 0, i = 0, cat_int = 0, domid = -1;
        char data [BUF_SIZE] = { 0, }, **domids = NULL, *cat_str = NULL;
        unsigned len = 0;
        uint16_t cat_uint16 = 0;

        /*  cycle through /local/domain/# */
        syslog (LOG_DEBUG, "searching for domid with mcs: %d", cat);
        domids = do_directory (xsh, LOCAL_DOMAINS, &len);
        if (!domids) {
                syslog (LOG_CRIT, "do_directory failed on: %s", LOCAL_DOMAINS);
                return -2;
        }
        for (i = 0; i < len; ++i) {
                /*  reading contents of /local/domain/#/selinux-mcs  */
                ret = snprintf (data,
                                sizeof (data),
                                "%s/%s/selinux-mcs",
                                LOCAL_DOMAINS,
                                domids [i]);
                if (ret < 0 || ret > BUF_SIZE) {
                        syslog (LOG_CRIT, "insufficient buffer size");
                        return -2;
                }
                cat_str = do_read (xsh, data);
                /*  if read fails assume domain has no mcs set and continue
                 *    search
                 */
                if (!cat_str) {
                        syslog (LOG_WARNING,
                                "do_read failed on: %s.  Carrying on.",
                                data);
                        continue;
                }
                cat_int = atoi (cat_str);
                if (cat_int < 1 || cat_int > 1023) {
                        syslog (LOG_CRIT,
                                "value at %s is inconsistent: %d < 1 || %d > 1023",
                                data,
                                cat_int,
                                cat_int);
                        free (cat_str);
                        return -2;
                }
                cat_uint16 = cat_int;
                /*    if value returned == cat return domain ID (# in outer loop)  */
                if (cat_uint16 == cat) {
                        free (cat_str);
                        domid = atoi (domids [i]);
                        syslog (LOG_INFO,
                                "found dom with mcs %d: %s",
                                cat_uint16,
                                data);
                        break;
                }
                free (cat_str);
        }
free_ids:
        if (domids)
                free (domids);
        return domid;
}