Ejemplo n.º 1
0
/* Read one mount table entry from STREAM. Returns a pointer to storage
 reused on the next call, or null for EOF or error (use feof/ferror to
 check). */
struct mntent *getmntent_r (FILE *stream, struct mntent *mp, char *buffer, int bufsiz)
{
    char *cp;
    char *head;

    do
    {
        char *end_ptr;

        if (fgets (buffer, bufsiz, stream) == NULL)
        {
            return NULL;
        }

        end_ptr = strchr (buffer, '\n');
        if (end_ptr != NULL) /* chop newline */
            *end_ptr = '\0';
        else
        {
            /* Not the whole line was read. Do it now but forget it. */
            char tmp[1024];
            while (fgets (tmp, sizeof tmp, stream) != NULL)
                if (strchr (tmp, '\n') != NULL)
                    break;
        }

        head = buffer + strspn (buffer, " \t");
        /* skip empty lines and comment lines: */
    }
    while (head[0] == '\0' || head[0] == '#');

    cp = strsep (&head, " \t");
    mp->mnt_fsname = cp != NULL ? decode_name (cp) : (char *) "";
    if (head)
        head += strspn (head, " \t");
    cp = strsep (&head, " \t");
    mp->mnt_dir = cp != NULL ? decode_name (cp) : (char *) "";
    if (head)
        head += strspn (head, " \t");
    cp = strsep (&head, " \t");
    mp->mnt_type = cp != NULL ? decode_name (cp) : (char *) "";
    if (head)
        head += strspn (head, " \t");
    cp = strsep (&head, " \t");
    mp->mnt_opts = cp != NULL ? decode_name (cp) : (char *) "";
    switch (head ? sscanf (head, " %d %d ", &mp->mnt_freq, &mp->mnt_passno) : 0)
    {
        case 0:
            mp->mnt_freq = 0;
        case 1:
            mp->mnt_passno = 0;
        case 2:
            break;
    }

    return mp;
}
GP<GIFFChunk>
GIFFChunk::get_chunk(const GUTF8String &name, int * pos_ptr)
   // The name may contain brackets to specify the chunk number
{
  DEBUG_MSG("GIFFChunk::get_chunk(): Returning chunk '" << name <<
     "' from '" << get_name() << "'\n");
  DEBUG_MAKE_INDENT(3);

  int number;
  const GUTF8String short_name=decode_name(name,number);

  int num=0;
  int pos_num;
  GP<GIFFChunk> retval;
  GPosition pos;
  for(pos=chunks, pos_num=0;pos;++pos, pos_num++)
  {
    if (chunks[pos]->get_name()==short_name && num++==number)
    {
      if (pos_ptr)
        *pos_ptr=pos_num;
      retval=chunks[pos];
      break;
    }
  }
  return retval;
}
void
GIFFChunk::del_chunk(const GUTF8String &name)
   // The name may contain brackets to specify the chunk number
{
  DEBUG_MSG("GIFFChunk::del_chunk(): Deleting chunk '" << name <<
     "' from '" << get_name() << "'\n");
  DEBUG_MAKE_INDENT(3);

  int number;
  const GUTF8String short_name=decode_name(name,number);

  GPosition pos=chunks;
  for(int num=0;pos;++pos)
  {
    if ((chunks[pos]->get_name()==short_name)&&(num++ == number))
    {
      chunks.del(pos);
      break;
    }
  }
  if(! pos)
  {
    G_THROW( ERR_MSG("GIFFManager.no_chunk") "\t"+short_name+"\t"+GUTF8String(number)+"\t"+get_name());
  }
}
static gint
dissect_query_afp_set_acl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset)
{
	guint16 bitmap;

	PAD(1);
	offset = decode_vol_did(tree, tvb, offset);

	bitmap = decode_acl_list_bitmap(tvb, tree, offset);
	offset += 2;

	offset = decode_name(tree, pinfo, tvb, offset);

	offset = decode_uuid_acl(tvb, tree, offset, bitmap);

	return offset;
}
int
GIFFChunk::get_chunks_number(const GUTF8String &name)
{
  DEBUG_MSG("GIFFChunk::get_chunks_number(): Returning number of chunks '" << name <<
     "' in '" << get_name() << "'\n");
  DEBUG_MAKE_INDENT(3);

  if (name.contains("[]")>=0)
    G_THROW( ERR_MSG("GIFFManager.no_brackets") );
  
  int number; 
  GUTF8String short_name=decode_name(name,number);
   
  int num=0;
  for(GPosition pos=chunks;pos;++pos)
     num+=(chunks[pos]->get_name()==short_name);
  return num;
}
Ejemplo n.º 6
0
/* Read one mount table entry from STREAM.  Returns a pointer to storage
   reused on the next call, or null for EOF or error (use feof/ferror to
   check).  */
struct mntent *
__getmntent_r (FILE *stream, struct mntent *mp, char *buffer, int bufsiz)
{
  char *cp;
  char *head;

  flockfile (stream);
  do
    {
      char *end_ptr;

      if (__fgets_unlocked (buffer, bufsiz, stream) == NULL)
	{
	  funlockfile (stream);
	  return NULL;
	}

      end_ptr = strchr (buffer, '\n');
      if (end_ptr != NULL)	/* chop newline */
	{
	  /* Do not walk past the start of buffer if it's all whitespace.  */
	  while (end_ptr != buffer
		 && (end_ptr[-1] == ' ' || end_ptr[-1] == '\t'))
            end_ptr--;
	  *end_ptr = '\0';
	}
      else
	{
	  /* Not the whole line was read.  Do it now but forget it.  */
	  char tmp[1024];
	  while (__fgets_unlocked (tmp, sizeof tmp, stream) != NULL)
	    if (strchr (tmp, '\n') != NULL)
	      break;
	}

      head = buffer + strspn (buffer, " \t");
      /* skip empty lines and comment lines:  */
    }
  while (head[0] == '\0' || head[0] == '#');

  cp = __strsep (&head, " \t");
  mp->mnt_fsname = cp != NULL ? decode_name (cp) : (char *) "";
  if (head)
    head += strspn (head, " \t");
  cp = __strsep (&head, " \t");
  mp->mnt_dir = cp != NULL ? decode_name (cp) : (char *) "";
  if (head)
    head += strspn (head, " \t");
  cp = __strsep (&head, " \t");
  mp->mnt_type = cp != NULL ? decode_name (cp) : (char *) "";
  if (head)
    head += strspn (head, " \t");
  cp = __strsep (&head, " \t");
  mp->mnt_opts = cp != NULL ? decode_name (cp) : (char *) "";
  switch (head ? sscanf (head, " %d %d ", &mp->mnt_freq, &mp->mnt_passno) : 0)
    {
    case 0:
      mp->mnt_freq = 0;
    case 1:
      mp->mnt_passno = 0;
    case 2:
      break;
    }
  funlockfile (stream);

  return mp;
}
Ejemplo n.º 7
0
int bg_test(int id,char *name)
{
  return decode_name(name,Drivers[id].namep,&bg_par);
}
Ejemplo n.º 8
0
int prt_test(int id, char *name)
{
  return decode_name(name,Drivers[id].namep,prt_par);
  /*return RW(name)==strlen("PRT") && !strncasecmp("PRT",name+2,RW(name));*/
}
Ejemplo n.º 9
0
int check_trace_body(Settings *opts, Trace_reader *trc, srf_t *srf) {
  char         name[512];
  Spot_info    spot = { NULL, 0, 0, 0, 0, 0, 0 };
  ztr_t       *ztr = NULL;
  ztr_chunk_t *chunk;
  int          start_chunk = 0;
  int          i;

  if (-1 == construct_trace_name(srf->th.id_prefix,
				 (unsigned char *)srf->tb.read_id,
				 srf->tb.read_id_length,
				 name, sizeof(name))) {
    printf("Couldn't construct read name\n");
    return -1;
  }

  if (0 != decode_name(name, &spot)) {
    printf("Couldn't decode read name.\n");
    return -1;
  }

  if (opts->verbosity > 0) {
    printf("%s\n", name);
  }

  if (0 != read_trace_data(opts, trc, &spot)) {
    printf("Couldn't get trace data for %s\n", name);
    return -1;
  }

  mfseek(srf->mf, srf->mf_end, SEEK_SET);
  if (srf->tb.trace_size) {
    mfwrite(srf->tb.trace, 1, srf->tb.trace_size, srf->mf);
    free(srf->tb.trace);
    srf->tb.trace = NULL;
  }
  mftruncate(srf->mf, mftell(srf->mf));
  mfseek(srf->mf, srf->mf_pos, SEEK_SET);
  
  if (srf->ztr) {
    start_chunk = srf->ztr->nchunks;
    ztr = ztr_dup(srf->ztr);
  }

  if (NULL == partial_decode_ztr(srf, srf->mf, ztr)) {
    printf("Couldn't decode ZTR data for %s\n", name);
    return -1;
  }

  for (i = start_chunk; i < ztr->nchunks; i++) {
    chunk = &ztr->chunk[i];
    if (opts->verbosity > 1) {
      printf(" Chunk %d type %.4s\n", i,
	      (char *) &chunk->type);
    }
    switch (chunk->type) {
    case ZTR_TYPE_BASE:
      if (0 != uncompress_chunk(ztr, chunk)) {
	printf("Couldn't uncompress BASE chunk\n");
	return -1;
      }
      if (trc->seq_len + 1 != chunk->dlength
	  || 0 != memcmp(trc->seq, chunk->data + 1, trc->seq_len)) {
	printf("Sequence differs for %s\n", name);
	return -1;
      }
      break;
    case ZTR_TYPE_CNF1:
      if (0 != uncompress_chunk(ztr, chunk)) {
	printf("Couldn't uncompress CNF1 chunk\n");
	return -1;
      }
      if (trc->seq_len + 1 != chunk->dlength
	  || 0 != memcmp(trc->qual, chunk->data + 1, trc->seq_len)) {
	printf("CNF1 confidence values differ for %s\n", name);
	return -1;
      }
      break;
    case ZTR_TYPE_CNF4:
      if (0 != uncompress_chunk(ztr, chunk)) {
	printf("Couldn't uncompress CNF4 chunk\n");
	return -1;
      }
      if (0 != check_cnf4(ztr, chunk, trc)) {
	printf("CNF4 confidence values differ for %s\n", name);
	return -1;
      }
      break;
    case ZTR_TYPE_SMP4:
      if (0 != uncompress_chunk(ztr, chunk)) {
	printf("Couldn't uncompress SMP4 chunk\n");
	return -1;
      }
      if (0 != check_trace(ztr, chunk, trc)) {
	printf("Trace doesn't match for %s\n", name);
	return -1;
      }
      break;
    default:
      printf("Found unexpected chunk type in trace body for %s\n",
	      name);
      return -1;
    }
  }

  delete_ztr(ztr);

  return 0;
}
/* Read one mount table entry from STREAM.  Returns a pointer to storage
   reused on the next call, or null for EOF or error (use feof/ferror to
   check).  */
struct mntent *
__getmntent_r (FILE *stream, struct mntent *mp, char *buffer, int bufsiz)
{
  char *cp;
  char *head;

#ifndef __WIN32__
  flockfile (stream);
  do
    {
      char *end_ptr;

      if (fgets_unlocked (buffer, bufsiz, stream) == NULL)
	{
	  funlockfile (stream);
	  return NULL;
	}

      end_ptr = strchr (buffer, '\n');
      if (end_ptr != NULL)	/* chop newline */
	*end_ptr = '\0';
      else
	{
	  /* Not the whole line was read.  Do it now but forget it.  */
	  char tmp[1024];
	  while (fgets_unlocked (tmp, sizeof tmp, stream) != NULL)
	    if (strchr (tmp, '\n') != NULL)
	      break;
	}

      head = buffer + strspn (buffer, " \t");
      /* skip empty lines and comment lines:  */
    }
  while (head[0] == '\0' || head[0] == '#');
#else /* __WIN32__ */
  struct statfsx64 buf;
  if (!strcmp(rootlist, NotSet)) {
//	fprintf(stderr, "rootlist0\n");
	rootlist = getrootdirs(rootlist);
  }
  /* skip the rootdirs that are not mounted */
  while ( (statfsx64 (rootlist, &buf) < 0)) { //(access (rootlist, F_OK) < 0) ||
//    fprintf(stderr, "rootlist < 0: %s\n", rootlist);
	if (rootlist[0] == 0)
    	return NULL;
	else
		rootlist = strchr (rootlist, 0) + 1;	
  }
//  fprintf(stderr, "rootlist: %s\n", rootlist);
//  fprintf(stderr, "buf.f_mntonname: %s\n", buf.f_mntonname);
//  fprintf(stderr, "buf.f_mntfromname: %s\n", buf.f_mntfromname);
//  fprintf(stderr, "buf.f_mntfromname: %s\n", buf.f_mntfromname);
//  fprintf(stderr, "buf.f_fstypename: %s\n", buf.f_fstypename);
  mp->mnt_fsname = buf.f_mntonname;
  mp->mnt_dir = buf.f_mntfromname;
  mp->mnt_type = buf.f_fstypename;
  mp->mnt_opts = MNTOPT_RW;
  __addmntentstr(buffer, mp);
//  fprintf(stderr, "mp->mnt_fsname: %s\n", mp->mnt_fsname);
//  fprintf(stderr, "mp->mnt_dir: %s\n", mp->mnt_dir);
//  fprintf(stderr, "mp->mnt_type: %s\n", mp->mnt_type);
//  fprintf(stderr, "mp->mnt_opts: %s\n", mp->mnt_opts);
  head = buffer + strspn (buffer, " \t");
  rootlist = strchr (rootlist, 0) + 1;
#endif /* __WIN32 */

  cp = __strsep (&head, " \t");
  mp->mnt_fsname = cp != NULL ? decode_name (cp) : (char *) "";
  if (head)
    head += strspn (head, " \t");
  cp = __strsep (&head, " \t");
  mp->mnt_dir = cp != NULL ? decode_name (cp) : (char *) "";
  if (head)
    head += strspn (head, " \t");
  cp = __strsep (&head, " \t");
  mp->mnt_type = cp != NULL ? decode_name (cp) : (char *) "";
  if (head)
    head += strspn (head, " \t");
  cp = __strsep (&head, " \t");
  mp->mnt_opts = cp != NULL ? decode_name (cp) : (char *) "";
  switch (head ? sscanf (head, " %d %d ", &mp->mnt_freq, &mp->mnt_passno) : 0)
    {
    case 0:
      mp->mnt_freq = 0;
    case 1:
      mp->mnt_passno = 0;
    case 2:
      break;
    }
  funlockfile (stream);
 
  return mp;
}
Ejemplo n.º 11
0
/* Inspired by generic filldir in fs/readdir.c */
static int wrapfs_filldir(void *dirent, const char *lower_name, int lower_namelen, 
										loff_t offset, u64 ino, unsigned int d_type)
{
	struct wrapfs_getdents_callback *buf = (struct wrapfs_getdents_callback *)dirent;
	char *decoded_name;
	size_t decoded_size;
	int rc;

	char *clear_text;
	size_t clear_text_len;

	/* dont perform decoding for special directories */
	if ((lower_namelen == 1 && !strcmp(lower_name, "."))
	    || (lower_namelen == 2 && !strcmp(lower_name, ".."))) {
		// printk("wrapfs_filldir: special directories [lower_name=%s, lower_namelen=%d]\n", lower_name, lower_namelen);
		buf->filldir_called++;
		rc = buf->filldir(buf->dirent, lower_name, lower_namelen, offset, ino, d_type);
	}
	else {
		/* decoding the filename */
		if(lower_namelen%2 != 0) {
			printk(KERN_ERR "wrapfs_filldir: filesystem might be corrupted\n");
			rc = -EILSEQ;
			goto out;
		}

		if(WRAPFS_SB(buf->dentry->d_sb)->has_key == FALSE) {
	        printk(KERN_ERR "__wrapfs_lookup: cannot perform action, provide cipher key\n");
	        rc=-EACCES;
	        goto out;
	    }

	    decoded_size = lower_namelen/2 + 1;
		decoded_name = (char *)kmalloc(decoded_size, GFP_KERNEL);
		if(!decoded_name) {
			printk("wrapfs_filldir: cannot allocate memory for decoded_name\n");
			rc = -ENOMEM;
			goto out;
		}
		memset(decoded_name, '\0', decoded_size);
		decode_name(lower_name, lower_namelen, decoded_name, decoded_size);
		// printk("wrapfs_filldir: lower_name=%s, lower_namelen=%d\n", lower_name, lower_namelen);
		// printk("wrapfs_filldir: decoded_name=%s, decoded_size=%d\n", decoded_name, decoded_size);

	    /* because of null character at the end for string */
	    clear_text_len = decoded_size - 1;

	    /* allocate memory of clear_text */
	    clear_text = (char *)kmalloc(clear_text_len, GFP_KERNEL);
	    if(!clear_text) {
	        printk("wrapfs_filldir: cannot allocate memory for clear_text\n");
	        rc = -ENOMEM;
	        kfree(decoded_name);
	        goto out;
	    }
	    memset(clear_text, 0, clear_text_len);

	    /* decrypting the decoded filename */
	    rc = aes_decrypt(WRAPFS_SB(buf->dentry->d_sb)->key, KEYLEN, decoded_name, clear_text, clear_text_len);
	    if(rc) {
	        printk("wrapfs_filldir: error encrypting page\n");
	        kfree(clear_text);
	        kfree(decoded_name);
	        goto out;
	    }
	    // printk("wrapfs_filldir: clear_text=");
	    // print_str(clear_text, clear_text_len);

	    /* call regular filldir to perform the action */
		buf->filldir_called++;
		rc = buf->filldir(buf->dirent, clear_text, clear_text_len, offset, ino, d_type);

		kfree(clear_text);
		kfree(decoded_name);
	}

	if (rc >= 0)
		buf->entries_written++;

out:
	return rc;
}
Ejemplo n.º 12
0
bool JsonValueToProtoMessage(const BUTIL_RAPIDJSON_NAMESPACE::Value& json_value,
                             google::protobuf::Message* message,
                             const Json2PbOptions& options,
                             std::string* err) {
    const google::protobuf::Descriptor* descriptor = message->GetDescriptor();
    if (!json_value.IsObject()) {
        J2PERROR(err, "`json_value' is not a json object. %s", descriptor->name().c_str());
        return false;
    }

    const google::protobuf::Reflection* reflection = message->GetReflection();
    
    std::vector<const google::protobuf::FieldDescriptor*> fields;
    fields.reserve(64);
    for (int i = 0; i < descriptor->extension_range_count(); ++i) {
        const google::protobuf::Descriptor::ExtensionRange*
            ext_range = descriptor->extension_range(i);
        for (int tag_number = ext_range->start; tag_number < ext_range->end;
             ++tag_number) {
            const google::protobuf::FieldDescriptor* field =
                reflection->FindKnownExtensionByNumber(tag_number);
            if (field) {
                fields.push_back(field);
            }
        }
    }
    for (int i = 0; i < descriptor->field_count(); ++i) {
        fields.push_back(descriptor->field(i));
    }

    std::string field_name_str_temp; 
    const BUTIL_RAPIDJSON_NAMESPACE::Value* value_ptr = NULL;
    for (size_t i = 0; i < fields.size(); ++i) {
        const google::protobuf::FieldDescriptor* field = fields[i];
        
        const std::string& orig_name = field->name();
        bool res = decode_name(orig_name, field_name_str_temp); 
        const std::string& field_name_str = (res ? field_name_str_temp : orig_name);

#ifndef RAPIDJSON_VERSION_0_1
        BUTIL_RAPIDJSON_NAMESPACE::Value::ConstMemberIterator member =
                json_value.FindMember(field_name_str.data());
        if (member == json_value.MemberEnd()) {
            if (field->is_required()) {
                J2PERROR(err, "Missing required field: %s", field->full_name().c_str());
                return false;
            }
            continue; 
        }
        value_ptr = &(member->value);
#else 
        const BUTIL_RAPIDJSON_NAMESPACE::Value::Member* member =
                json_value.FindMember(field_name_str.data());
        if (member == NULL) {
            if (field->is_required()) {
                J2PERROR(err, "Missing required field: %s", field->full_name().c_str());
                return false;
            }
            continue; 
        }
        value_ptr = &(member->value);
#endif

        if (IsProtobufMap(field) && value_ptr->IsObject()) {
            // Try to parse json like {"key":value, ...} into protobuf map
            if (!JsonMapToProtoMap(*value_ptr, field, message, options, err)) {
                return false;
            }
        } else {
            if (!JsonValueToProtoField(*value_ptr, field, message, options, err)) {
                return false;
            }
        }
    }
    return true;
}
Ejemplo n.º 13
0
static int
cldap_parse(ad_disc_t ctx, ad_disc_cds_t *cds, BerElement *ber)
{
	ad_disc_ds_t *dc = &cds->cds_ds;
	uchar_t *base = NULL, *cp = NULL;
	char val[512]; /* how big should val be? */
	int l, msgid, rc = 0;
	uint16_t opcode;
	field_5ex_t f = OPCODE;

	/*
	 * Later, compare msgid's/some validation?
	 */

	if (ber_scanf(ber, "{i{x{{x[la", &msgid, &l, &cp) == LBER_ERROR) {
		rc = 1;
		goto out;
	}

	for (base = cp; ((cp - base) < l) && (f <= LM_20_TOKEN); f++) {
		val[0] = '\0';
		switch (f) {
		case OPCODE:
			/* opcode = *(uint16_t *)cp; */
			/* cp +=2; */
			opcode = *cp++;
			opcode |= (*cp++ << 8);
			break;
		case SBZ:
			cp += 2;
			break;
		case FLAGS:
			/* dci->Flags = *(uint32_t *)cp; */
			/* cp +=4; */
			dc->flags = *cp++;
			dc->flags |= (*cp++ << 8);
			dc->flags |= (*cp++ << 16);
			dc->flags |= (*cp++ << 26);
			break;
		case DOMAIN_GUID:
			if (ctx != NULL)
				auto_set_DomainGUID(ctx, cp);
			cp += 16;
			break;
		case FOREST_NAME:
			cp += decode_name(base, cp, val);
			if (ctx != NULL)
				auto_set_ForestName(ctx, val);
			break;
		case DNS_DOMAIN_NAME:
			/*
			 * We always have this already.
			 * (Could validate it here.)
			 */
			cp += decode_name(base, cp, val);
			break;
		case DNS_HOST_NAME:
			cp += decode_name(base, cp, val);
			if (0 != strcasecmp(val, dc->host)) {
				logger(LOG_ERR, "DC name %s != %s?",
				    val, dc->host);
			}
			break;
		case NET_DOMAIN_NAME:
			/*
			 * This is the "Flat" domain name.
			 * (i.e. the NetBIOS name)
			 * ignore for now.
			 */
			cp += decode_name(base, cp, val);
			break;
		case NET_COMP_NAME:
			/* not needed */
			cp += decode_name(base, cp, val);
			break;
		case USER_NAME:
			/* not needed */
			cp += decode_name(base, cp, val);
			break;
		case DC_SITE_NAME:
			cp += decode_name(base, cp, val);
			(void) strlcpy(dc->site, val, sizeof (dc->site));
			break;
		case CLIENT_SITE_NAME:
			cp += decode_name(base, cp, val);
			if (ctx != NULL)
				auto_set_SiteName(ctx, val);
			break;
		/*
		 * These are all possible, but we don't really care about them.
		 * Sockaddr_size && sockaddr might be useful at some point
		 */
		case SOCKADDR_SIZE:
		case SOCKADDR:
		case NEXT_CLOSEST_SITE_NAME:
		case NTVER:
		case LM_NT_TOKEN:
		case LM_20_TOKEN:
			break;
		default:
			rc = 3;
			goto out;
		}
	}

out:
	if (base)
		free(base);
	else if (cp)
		free(cp);
	return (rc);
}