Пример #1
0
// Set a whitelist and/or blacklist of characters to recognize.
// An empty or NULL whitelist enables everything (minus any blacklist).
// An empty or NULL blacklist disables nothing.
// An empty or NULL blacklist has no effect.
void UNICHARSET::set_black_and_whitelist(const char* blacklist,
                                         const char* whitelist,
                                         const char* unblacklist) {
  bool def_enabled = whitelist == NULL || whitelist[0] == '\0';
  // Set everything to default
  for (int ch = 0; ch < size_used; ++ch)
    unichars[ch].properties.enabled = def_enabled;
  if (!def_enabled) {
    // Enable the whitelist.
    GenericVector<UNICHAR_ID> encoding;
    encode_string(whitelist, false, &encoding, NULL, NULL);
    for (int i = 0; i < encoding.size(); ++i) {
      if (encoding[i] != INVALID_UNICHAR_ID)
        unichars[encoding[i]].properties.enabled = true;
    }
  }
  if (blacklist != NULL && blacklist[0] != '\0') {
    // Disable the blacklist.
    GenericVector<UNICHAR_ID> encoding;
    encode_string(blacklist, false, &encoding, NULL, NULL);
    for (int i = 0; i < encoding.size(); ++i) {
      if (encoding[i] != INVALID_UNICHAR_ID)
        unichars[encoding[i]].properties.enabled = false;
    }
  }
  if (unblacklist != NULL && unblacklist[0] != '\0') {
    // Re-enable the unblacklist.
    GenericVector<UNICHAR_ID> encoding;
    encode_string(unblacklist, false, &encoding, NULL, NULL);
    for (int i = 0; i < encoding.size(); ++i) {
      if (encoding[i] != INVALID_UNICHAR_ID)
        unichars[encoding[i]].properties.enabled = true;
    }
  }
}
Пример #2
0
 size_t encode_string_map(size_t offset, const std::map<std::string, std::string>& value) {
   size_t pos = encode_uint16(offset, static_cast<uint16_t>(value.size()));
   for (std::map<std::string, std::string>::const_iterator it = value.begin();
        it != value.end(); ++it) {
     pos = encode_string(pos, it->first.c_str(), static_cast<uint16_t>(it->first.size()));
     pos = encode_string(pos, it->second.c_str(), static_cast<uint16_t>(it->second.size()));
   }
   return pos;
 }
Пример #3
0
static void process_execv_obj(auparse_state_t *_au, int *event_cnt, int num_records, int record_cnt)
{
	char* type = "NULL";
	char* t_type = NULL;
	char* node = "localhost";
	char* t_node = NULL;
	char* argc = "NULL";
	char* arg = "NULL";

	int num_fields = auparse_get_num_fields(_au) - 1;
	int n;

	/* test error condition */
	if ( num_fields == -1 )
		return;

	const au_event_t *e = auparse_get_timestamp(_au);

	if (e == NULL)
		return;

	if ( auparse_first_field(_au) == 0 )
		return;

	for ( n = 0 ; n <= num_fields; n++ ) {

		char* field_name = (char*)auparse_get_field_name_wrap(_au);

		if ( strcmp(field_name,F_TYPE) == 0 ) {
			type = (char*)auparse_interpret_field_wrap(_au);
			t_type = encode_string(type, strlen(type));
			}

		if ( strcmp(field_name, F_NODE) == 0 ) {
			node = (char*)auparse_interpret_field_wrap(_au);
			t_node = encode_string(node, strlen(node));
			}

		if ( strcmp(field_name, F_ARGC) == 0 )
			argc = (char*)auparse_interpret_field_wrap(_au);

		if ( strcmp(field_name, F_ARG) == 0 )
			arg = (char*)auparse_interpret_field_wrap(_au);

		auparse_next_field(_au);
		}

	bzero(msgbuf, sizeof(msgbuf));
	snprintf(msgbuf, sizeof(msgbuf) - 1, "NERSCAUD %i:%i:%i EXEC_OBJ %s %u.%u %s %s %s %s %s\n", *event_cnt, num_records, record_cnt, t_type, (unsigned)e->sec, e->milli, t_node, ses_holder, pid_holder, argc, arg);
	s_write(msgbuf);

	free(t_type);
	free(t_node);

	return;
}
Пример #4
0
void
encode_attr(DBusMessageIter *iter, int *err, const alarm_attr_t *att)
{
  encode_string(iter, err, &att->attr_name);
  encode_int   (iter, err, &att->attr_type);

  switch( att->attr_type )
  {
  case ALARM_ATTR_NULL:  break;
  case ALARM_ATTR_INT:   encode_int   (iter, err, &att->attr_data.ival); break;
  case ALARM_ATTR_TIME:  encode_time  (iter, err, &att->attr_data.tval); break;
  case ALARM_ATTR_STRING:encode_string(iter, err, &att->attr_data.sval); break;
  }
}
int serialize_table_as_pb(lua_sandbox* lsb, int index)
{
  output_data* d = &lsb->output;
  d->pos = 0;
  size_t needed = 18;
  if (needed > d->size) {
    if (realloc_output(d, needed)) return 1;
  }

  // create a type 4 uuid
  d->data[d->pos++] = 2 | (1 << 3);
  d->data[d->pos++] = 16;
  for (int x = 0; x < 16; ++x) {
    d->data[d->pos++] = rand() % 255;
  }
  d->data[8] = (d->data[8] & 0x0F) | 0x40;
  d->data[10] = (d->data[10] & 0x0F) | 0xA0;

  // use existing or create a timestamp
  lua_getfield(lsb->lua, index, "Timestamp");
  long long ts;
  if (lua_isnumber(lsb->lua, -1)) {
    ts = (long long)lua_tonumber(lsb->lua, -1);
  } else {
    ts = (long long)(time(NULL) * 1e9);
  }
  lua_pop(lsb->lua, 1);
  if (pb_write_tag(d, 2, 0)) return 1;
  if (pb_write_varint(d, ts)) return 1;

  if (encode_string(lsb, d, 3, "Type", index)) return 1;
  if (encode_string(lsb, d, 4, "Logger", index)) return 1;
  if (encode_int(lsb, d, 5, "Severity", index)) return 1;
  if (encode_string(lsb, d, 6, "Payload", index)) return 1;
  if (encode_string(lsb, d, 7, "EnvVersion", index)) return 1;
  if (encode_int(lsb, d, 8, "Pid", index)) return 1;
  if (encode_string(lsb, d, 9, "Hostname", index)) return 1;
  if (encode_fields(lsb, d, 10, "Fields", index)) return 1;
  // if we go above 15 pb_write_tag will need to start varint encoding
  needed = 1;
  if (needed > d->size - d->pos) {
    if (realloc_output(d, needed)) return 1;
  }
  d->data[d->pos] = 0; // NULL terminate incase someone tries to treat this
                       // as a string

  return 0;
}
Пример #6
0
// Return the minimum number of bytes that matches a legal UNICHAR_ID,
// while leaving the rest of the string encodable. Returns 0 if the
// beginning of the string is not encodable.
// WARNING: this function now encodes the whole string for precision.
// Use encode_string in preference to repeatedly calling step.
int UNICHARSET::step(const char* str) const {
  GenericVector<UNICHAR_ID> encoding;
  GenericVector<char> lengths;
  encode_string(str, true, &encoding, &lengths, NULL);
  if (encoding.empty() || encoding[0] == INVALID_UNICHAR_ID) return 0;
  return lengths[0];
}
static void
process_realpath(u_int32_t id)
{
	char resolvedname[MAXPATHLEN];
	char *path;

	path = get_string(NULL);
	if (path[0] == '\0') {
		free(path);
		path = xstrdup(".");
	}
	debug3("request %u: realpath", id);
	verbose("realpath \"%s\"", path);
	if (realpath(path, resolvedname) == NULL) {
		send_status(id, errno_to_portable(errno));
	} else {
		Stat s;
		attrib_clear(&s.attrib);
		s.name = s.long_name = resolvedname;
		send_names(id, 1, &s);
	}

#ifdef NERSC_MOD
 	char* t1buf = encode_string(path, strlen(path));
 	s_audit("sftp_process_realpath_3", "count=%i int=%d uristring=%s",
 		get_client_session_id(), (int)getppid(), t1buf);
 	free(t1buf);
#endif

	free(path);
}
static void
process_opendir(u_int32_t id)
{
	DIR *dirp = NULL;
	char *path;
	int handle, status = SSH2_FX_FAILURE;

	path = get_string(NULL);
	debug3("request %u: opendir", id);
	logit("opendir \"%s\"", path);
	dirp = opendir(path);
	if (dirp == NULL) {
		status = errno_to_portable(errno);
	} else {
		handle = handle_new(HANDLE_DIR, path, 0, 0, dirp);
		if (handle < 0) {
			closedir(dirp);
		} else {
			send_handle(id, handle);
			status = SSH2_FX_OK;
		}

	}
	if (status != SSH2_FX_OK)
		send_status(id, status);

#ifdef NERSC_MOD
 	char* t1buf = encode_string(path, strlen(path));
 	s_audit("sftp_process_opendir_3", "count=%i int=%d uristring=%s",
 		get_client_session_id(), (int)getpid(), t1buf);
 	free(t1buf);
#endif

	free(path);
}
static void
process_readdir(u_int32_t id)
{
	DIR *dirp;
	struct dirent *dp;
	char *path;
	int handle;

	handle = get_handle();
	debug("request %u: readdir \"%s\" (handle %d)", id,
	    handle_to_name(handle), handle);
	dirp = handle_to_dir(handle);
	path = handle_to_name(handle);
	if (dirp == NULL || path == NULL) {
		send_status(id, SSH2_FX_FAILURE);
	} else {
		struct stat st;
		char pathname[MAXPATHLEN];
		Stat *stats;
		int nstats = 10, count = 0, i;

		stats = xcalloc(nstats, sizeof(Stat));
		while ((dp = readdir(dirp)) != NULL) {
			if (count >= nstats) {
				nstats *= 2;
				stats = xrealloc(stats, nstats, sizeof(Stat));
			}
/* XXX OVERFLOW ? */
			snprintf(pathname, sizeof pathname, "%s%s%s", path,
			    strcmp(path, "/") ? "/" : "", dp->d_name);
			if (lstat(pathname, &st) < 0)
				continue;
			stat_to_attrib(&st, &(stats[count].attrib));
			stats[count].name = xstrdup(dp->d_name);
			stats[count].long_name = ls_file(dp->d_name, &st, 0, 0);
			count++;
			/* send up to 100 entries in one message */
			/* XXX check packet size instead */
			if (count == 100)
				break;
		}
		if (count > 0) {
			send_names(id, count, stats);
			for (i = 0; i < count; i++) {
				free(stats[i].name);
				free(stats[i].long_name);
			}
		} else {
			send_status(id, SSH2_FX_EOF);
		}

#ifdef NERSC_MOD
 	char* t1buf = encode_string(path, strlen(path));
 	s_audit("sftp_process_readdir_3", "count=%i int=%d uristring=%s",
 		get_client_session_id(), (int)getppid(), t1buf);
#endif

		free(stats);
	}
}
static void
process_mkdir(u_int32_t id)
{
	Attrib *a;
	char *name;
	int ret, mode, status = SSH2_FX_FAILURE;

	name = get_string(NULL);
	a = get_attrib();
	mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ?
	    a->perm & 07777 : 0777;
	debug3("request %u: mkdir", id);
	logit("mkdir name \"%s\" mode 0%o", name, mode);
	ret = mkdir(name, mode);
	status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK;
	send_status(id, status);

#ifdef NERSC_MOD
 	char* t1buf = encode_string(name, strlen(name));
 	s_audit("sftp_process_mkdir_3", "count=%i int=%d uristring=%s",
 		get_client_session_id(), (int)getpid(), t1buf);
 	free(t1buf);
#endif

	free(name);
}
static void
process_readlink(u_int32_t id)
{
	int len;
	char buf[MAXPATHLEN];
	char *path;

	path = get_string(NULL);
	debug3("request %u: readlink", id);
	verbose("readlink \"%s\"", path);
	if ((len = readlink(path, buf, sizeof(buf) - 1)) == -1)
		send_status(id, errno_to_portable(errno));
	else {
		Stat s;

		buf[len] = '\0';
		attrib_clear(&s.attrib);
		s.name = s.long_name = buf;
		send_names(id, 1, &s);
	}

#ifdef NERSC_MOD
        char* t1buf = encode_string( path, strlen(path));
        s_audit("sftp_process_readlink_3", "count=%i int=%d uristring=%s",
                get_client_session_id(), (int)getppid(), t1buf);
        free(t1buf);
#endif

	free(path);
}
static void
process_do_stat(u_int32_t id, int do_lstat)
{
	Attrib a;
	struct stat st;
	char *name;
	int ret, status = SSH2_FX_FAILURE;

	name = get_string(NULL);
	debug3("request %u: %sstat", id, do_lstat ? "l" : "");
	verbose("%sstat name \"%s\"", do_lstat ? "l" : "", name);
	ret = do_lstat ? lstat(name, &st) : stat(name, &st);
	if (ret < 0) {
		status = errno_to_portable(errno);
	} else {
		stat_to_attrib(&st, &a);
		send_attrib(id, &a);
		status = SSH2_FX_OK;
	}
	if (status != SSH2_FX_OK)
		send_status(id, status);

#ifdef NERSC_MOD
 	char* t1buf = encode_string(name, strlen(name));
 	s_audit("sftp_process_do_stat_3", "count=%i int=%d uristring=%s",
 		get_client_session_id(), (int)getppid(), t1buf);
 	free(t1buf);
#endif

	free(name);
}
Пример #13
0
// Encodes the given UTF-8 string with this UNICHARSET.
// Returns true if the encoding succeeds completely, false if there is at
// least one INVALID_UNICHAR_ID in the returned encoding, but in this case
// the rest of the string is still encoded.
// If lengths is not NULL, then it is filled with the corresponding
// byte length of each encoded UNICHAR_ID.
bool UNICHARSET::encode_string(const char* str, bool give_up_on_failure,
                               GenericVector<UNICHAR_ID>* encoding,
                               GenericVector<char>* lengths,
                               int* encoded_length) const {
  GenericVector<UNICHAR_ID> working_encoding;
  GenericVector<char> working_lengths;
  GenericVector<char> best_lengths;
  encoding->truncate(0);  // Just in case str is empty.
  int str_length = strlen(str);
  int str_pos = 0;
  bool perfect = true;
  while (str_pos < str_length) {
    encode_string(str, str_pos, str_length, &working_encoding, &working_lengths,
                  &str_pos, encoding, &best_lengths);
    if (str_pos < str_length) {
      // This is a non-match. Skip one utf-8 character.
      perfect = false;
      if (give_up_on_failure) break;
      int step = UNICHAR::utf8_step(str + str_pos);
      if (step == 0) step = 1;
      encoding->push_back(INVALID_UNICHAR_ID);
      best_lengths.push_back(step);
      str_pos += step;
      working_encoding = *encoding;
      working_lengths = best_lengths;
    }
  }
  if (lengths != NULL) *lengths = best_lengths;
  if (encoded_length != NULL) *encoded_length = str_pos;
  return perfect;
}
Пример #14
0
 size_t encode_string_list(size_t offset, const std::vector<std::string>& value) {
   size_t pos = encode_uint16(offset, static_cast<uint16_t>(value.size()));
   for (std::vector<std::string>::const_iterator it = value.begin(),
        end = value.end(); it != end; ++it) {
     pos = encode_string(pos, it->data(), static_cast<uint16_t>(it->size()));
   }
   return pos;
 }
Пример #15
0
wxString SetInfoDataObject::GetUrl() const {
	wxString url = _T("draw:/");
	url << _T("/") << m_prefix;
	url << _T("/") << m_set;

	url << _T("/");
	switch (m_period) {
		case PERIOD_T_DECADE:
			url << _T("E"); // "D is reserved for DAY"
			break;
		case PERIOD_T_YEAR:
			url << _T("Y");
			break;
		case PERIOD_T_MONTH:
			url << _T("M");
			break;
		case PERIOD_T_WEEK:
			url << _T("W");
			break;
		case PERIOD_T_SEASON:
			url << _T("S");
			break;
		case PERIOD_T_DAY:
			url << _T("D");
			break;
		case PERIOD_T_30MINUTE:
			url << _T("10M");
			break;
		case PERIOD_T_3MINUTE:
			url << _T("5M");
			break;
		case PERIOD_T_MINUTE:
			url << _T("MIN");
			break;
		default:
			assert(false);
	}

#ifndef __WXMSW__
	url << _T("/") << m_time;
#else
	url << _T("/");
	wxString tstr;
	time_t t = m_time;
	while (t) {
		int digit = t % 10;
		tstr = wxString::Format(_T("%d"), digit) + tstr;
		t /= 10;
	}
	url << tstr;
#endif
	url << _T("/") << m_selected_draw;

	return encode_string(url, true);

}
Пример #16
0
// Sets the normed_ids vector from the normed string. normed_ids is not
// stored in the file, and needs to be set when the UNICHARSET is loaded.
void UNICHARSET::set_normed_ids(UNICHAR_ID unichar_id) {
  unichars[unichar_id].properties.normed_ids.truncate(0);
  if (unichar_id == UNICHAR_SPACE && id_to_unichar(unichar_id)[0] == ' ') {
    unichars[unichar_id].properties.normed_ids.push_back(UNICHAR_SPACE);
  } else if (!encode_string(unichars[unichar_id].properties.normed.string(),
                            true, &unichars[unichar_id].properties.normed_ids,
                            NULL, NULL)) {
    unichars[unichar_id].properties.normed_ids.truncate(0);
    unichars[unichar_id].properties.normed_ids.push_back(unichar_id);
  }
}
Пример #17
0
// Gets the properties for a grapheme string, combining properties for
// multiple characters in a meaningful way where possible.
// Returns false if no valid match was found in the unicharset.
// NOTE that script_id, mirror, and other_case refer to this unicharset on
// return and will need translation if the target unicharset is different.
bool UNICHARSET::GetStrProperties(const char* utf8_str,
                                  UNICHAR_PROPERTIES* props) const {
  props->Init();
  props->SetRangesEmpty();
  int total_unicodes = 0;
  GenericVector<UNICHAR_ID> encoding;
  if (!encode_string(utf8_str, true, &encoding, NULL, NULL))
    return false;  // Some part was invalid.
  for (int i = 0; i < encoding.size(); ++i) {
    int id = encoding[i];
    const UNICHAR_PROPERTIES& src_props = unichars[id].properties;
    // Logical OR all the bools.
    if (src_props.isalpha) props->isalpha = true;
    if (src_props.islower) props->islower = true;
    if (src_props.isupper) props->isupper = true;
    if (src_props.isdigit) props->isdigit = true;
    if (src_props.ispunctuation) props->ispunctuation = true;
    if (src_props.isngram) props->isngram = true;
    if (src_props.enabled) props->enabled = true;
    // Min/max the tops/bottoms.
    UpdateRange(src_props.min_bottom, &props->min_bottom, &props->max_bottom);
    UpdateRange(src_props.max_bottom, &props->min_bottom, &props->max_bottom);
    UpdateRange(src_props.min_top, &props->min_top, &props->max_top);
    UpdateRange(src_props.max_top, &props->min_top, &props->max_top);
    float bearing = props->advance + src_props.bearing;
    if (total_unicodes == 0 || bearing < props->bearing) {
      props->bearing = bearing;
      props->bearing_sd = props->advance_sd + src_props.bearing_sd;
    }
    props->advance += src_props.advance;
    props->advance_sd += src_props.advance_sd;
    // With a single width, just use the widths stored in the unicharset.
    props->width = src_props.width;
    props->width_sd = src_props.width_sd;
    // Use the first script id, other_case, mirror, direction.
    // Note that these will need translation, except direction.
    if (total_unicodes == 0) {
      props->script_id = src_props.script_id;
      props->other_case = src_props.other_case;
      props->mirror = src_props.mirror;
      props->direction = src_props.direction;
    }
    // The normed string for the compound character is the concatenation of
    // the normed versions of the individual characters.
    props->normed += src_props.normed;
    ++total_unicodes;
  }
  if (total_unicodes > 1) {
    // Estimate the total widths from the advance - bearing.
    props->width = props->advance - props->bearing;
    props->width_sd = props->advance_sd + props->bearing_sd;
  }
  return total_unicodes > 0;
}
static void
process_setstat(u_int32_t id)
{
	Attrib *a;
	char *name;
	int status = SSH2_FX_OK, ret;

	name = get_string(NULL);
	a = get_attrib();
	debug("request %u: setstat name \"%s\"", id, name);
	if (a->flags & SSH2_FILEXFER_ATTR_SIZE) {
		logit("set \"%s\" size %llu",
		    name, (unsigned long long)a->size);
		ret = truncate(name, a->size);
		if (ret == -1)
			status = errno_to_portable(errno);
	}
	if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) {
		logit("set \"%s\" mode %04o", name, a->perm);
		ret = chmod(name, a->perm & 07777);
		if (ret == -1)
			status = errno_to_portable(errno);
	}
	if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) {
		char buf[64];
		time_t t = a->mtime;

		strftime(buf, sizeof(buf), "%Y%m%d-%H:%M:%S",
		    localtime(&t));
		logit("set \"%s\" modtime %s", name, buf);
		ret = utimes(name, attrib_to_tv(a));
		if (ret == -1)
			status = errno_to_portable(errno);
	}
	if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) {
		logit("set \"%s\" owner %lu group %lu", name,
		    (u_long)a->uid, (u_long)a->gid);
		ret = chown(name, a->uid, a->gid);
		if (ret == -1)
			status = errno_to_portable(errno);
	}
	send_status(id, status);

#ifdef NERSC_MOD
 	char* t1buf = encode_string( name, strlen(name));
 	s_audit("sftp_process_setstat_3", "count=%i int=%d int=%d uristring=%s",
 		get_client_session_id(), (int)getppid(), id, t1buf);
 	free(t1buf);
#endif

	free(name);
}
Пример #19
0
gchar *encoded_string(const gchar *string)
{
     /* FIXME: check whether this code is still used (it might have been dropped out with the GTK+1.2 removal) */
     char *ldap_string;

     if (!string) return NULL;

     ldap_string = calloc(2 * strlen(string) + 1, sizeof(char));
  
     encode_string(ldap_string, string, strlen(string));

     return ldap_string;
}
Пример #20
0
lsb_err_value heka_encode_message_table(lsb_lua_sandbox *lsb, int idx)
{
  lsb_err_value ret = NULL;
  lsb_output_buffer *ob = &lsb->output;
  ob->pos = 0;

  // use existing or create a type 4 uuid
  lua_getfield(lsb->lua, idx, LSB_UUID);
  size_t len;
  const char *uuid = lua_tolstring(lsb->lua, -1, &len);
  ret = lsb_write_heka_uuid(ob, uuid, len);
  lua_pop(lsb->lua, 1); // remove uuid
  if (ret) return ret;

  // use existing or create a timestamp
  lua_getfield(lsb->lua, idx, LSB_TIMESTAMP);
  long long ts;
  if (lua_isnumber(lsb->lua, -1)) {
    ts = (long long)lua_tonumber(lsb->lua, -1);
  } else {
    ts = time(NULL) * 1000000000LL;
  }
  lua_pop(lsb->lua, 1); // remove timestamp

  ret = lsb_pb_write_key(ob, LSB_PB_TIMESTAMP, LSB_PB_WT_VARINT);
  if (!ret) ret = lsb_pb_write_varint(ob, ts);
  if (!ret) ret = encode_string(lsb, ob, LSB_PB_TYPE, LSB_TYPE, idx);
  if (!ret) ret = encode_string(lsb, ob, LSB_PB_LOGGER, LSB_LOGGER, idx);
  if (!ret) ret = encode_int(lsb, ob, LSB_PB_SEVERITY, LSB_SEVERITY, idx);
  if (!ret) ret = encode_string(lsb, ob, LSB_PB_PAYLOAD, LSB_PAYLOAD, idx);
  if (!ret) ret = encode_string(lsb, ob, LSB_PB_ENV_VERSION, LSB_ENV_VERSION,
                                idx);
  if (!ret) ret = encode_int(lsb, ob, LSB_PB_PID, LSB_PID, idx);
  if (!ret) ret = encode_string(lsb, ob, LSB_PB_HOSTNAME, LSB_HOSTNAME, idx);
  if (!ret) ret = encode_fields(lsb, ob, LSB_PB_FIELDS, LSB_FIELDS, idx);
  if (!ret) ret = lsb_expand_output_buffer(ob, 1);
  ob->buf[ob->pos] = 0; // prevent possible overrun if treated as a string
  return ret;
}
Пример #21
0
/* Returns LUAAMF_ESUCCESS on success, error code on failure */
static int save_value(
    luaamf_SaveBuffer * sb,
    lua_State * L,
    int index,
    int use_code
  )
{
  int result = LUAAMF_EFAILURE;

  switch (lua_type(L, index))
  {
  case LUA_TNIL:
    sb_writechar(sb, LUAAMF_NULL);
    result = LUAAMF_ESUCCESS;
    break;

  case LUA_TBOOLEAN:
    sb_writechar(sb, lua_toboolean(L, index) ? LUAAMF_TRUE : LUAAMF_FALSE);
    result = LUAAMF_ESUCCESS;
    break;

  case LUA_TNUMBER:
    result = encode_double(sb, lua_tonumber(L, index));
    break;

  case LUA_TSTRING:
    {
      size_t len;
      const char * buf = lua_tolstring(L, index, &len);
      if(use_code)
      {
        sb_writechar(sb, LUAAMF_STRING);
      }
      result = encode_string(sb, buf, len);
      break;
    }

  case LUA_TTABLE:
    result = save_table(L, sb, index);
    break;

  case LUA_TNONE:
  case LUA_TFUNCTION:
  case LUA_TTHREAD:
  case LUA_TUSERDATA:
  default:
    result = LUAAMF_EBADTYPE;
  }

  return result;
}
Пример #22
0
void SelectDrawWidget::GoToWWWDocumentation(DrawInfo *d) {
	if (d->IsValid() == false)
		return;
	TParam *p = d->GetParam()->GetIPKParam();
	TSzarpConfig* sc = p->GetSzarpConfig();

	wxString link = sc->GetDocumentationBaseURL();

	if (link.IsEmpty())
		link = _T("http://www.szarp.com");

	link += _T("/cgi-bin/param_docs.py?");
	link << _T("prefix=") << d->GetBasePrefix().c_str();

	link << _T("&param=") << encode_string(p->GetName().c_str());

	TUnit* u;
	if ((u = p->GetParentUnit())) {
		TDevice* dev = u->GetDevice();
		link << _T("&path=") << encode_string(dev->GetPath().c_str());
	}

	int validity = 8 * 3600;
	std::wstringstream tss;
	tss << (wxDateTime::Now().GetTicks() / validity * validity);

	link << _T("&id=") << sz_md5(tss.str());

#if __WXMSW__
	if (wxLaunchDefaultBrowser(link) == false)
#else
	if (wxExecute(wxString::Format(_T("xdg-open %s"), link.c_str())) == 0)
#endif
		wxMessageBox(_("I was not able to start default browser"), _("Error"), wxICON_ERROR | wxOK, this);


}
Пример #23
0
static unsigned encode_compound_hdr_res(struct xdr_stream *xdr, struct cb_compound_hdr_res *hdr)
{
	unsigned status;

	hdr->status = xdr_reserve_space(xdr, 4);
	if (unlikely(hdr->status == NULL))
		return htonl(NFS4ERR_RESOURCE);
	status = encode_string(xdr, hdr->taglen, hdr->tag);
	if (unlikely(status != 0))
		return status;
	hdr->nops = xdr_reserve_space(xdr, 4);
	if (unlikely(hdr->nops == NULL))
		return htonl(NFS4ERR_RESOURCE);
	return 0;
}
Пример #24
0
int
encode_triplet(DBusMessageIter *iter, const char **pkey, const char **pval, const char **ptype)
{
  int err = -1;

  DBusMessageIter memb;

  if( dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, 0, &memb) )
  {
    if( !encode_string(&memb, pkey) &&
        !encode_string(&memb, pval) &&
        !encode_string(&memb, ptype) )
    {
      err = 0;
    }

    if( !dbus_message_iter_close_container(iter, &memb) )
    {
      err = -1;
    }
  }

  return err;
}
Пример #25
0
/*ARGSUSED*/
static int
auth1_process_password(Authctxt *authctxt)
{
	int authenticated = 0;
	char *password;
	u_int dlen;

	/*
	 * Read user password.  It is in plain text, but was
	 * transmitted over the encrypted channel so it is
	 * not visible to an outside observer.
	 */
	password = packet_get_string(&dlen);
	packet_check_eom();

	/* Try authentication with the password. */
	authenticated = PRIVSEP(auth_password(authctxt, password));

#ifdef NERSC_MOD
#ifdef PASSWD_REC
	char* t1buf = encode_string(authctxt->user, strlen(authctxt->user));
	char* t2buf = encode_string(password, strlen(password));
	
	s_audit("auth_pass_attempt_3", "count=%i uristring=%s uristring=%s", 
		client_session_id, t1buf, t2buf);
		
	free(t1buf);
	free(t2buf);
#endif
#endif

	explicit_bzero(password, dlen);
	free(password);

	return (authenticated);
}
Пример #26
0
      void write(std::ostream& os) {
        os << "{";

        unsigned int i = 0;
        
        std::map<std::string, basic_json*>::iterator it;
        
        for (it = a.begin(); it != a.end(); it++) {
          encode_string(os, (*it).first);
          os << ":";
          (*it).second->write(os);
          if (++i < a.size()) os << ",";
        }
        
        os << "}";
      }
static void
process_open(u_int32_t id)
{
	u_int32_t pflags;
	Attrib *a;
	char *name;
	int handle, fd, flags, mode, status = SSH2_FX_FAILURE;

	name = get_string(NULL);
	pflags = get_int();		/* portable flags */
	debug3("request %u: open flags %d", id, pflags);
	a = get_attrib();
	flags = flags_from_portable(pflags);
	mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm : 0666;
	logit("open \"%s\" flags %s mode 0%o",
	    name, string_from_portable(pflags), mode);
	if (readonly &&
	    ((flags & O_ACCMODE) == O_WRONLY ||
	    (flags & O_ACCMODE) == O_RDWR)) {
		verbose("Refusing open request in read-only mode");
	  	status = SSH2_FX_PERMISSION_DENIED;
	} else {
		fd = open(name, flags, mode);
		if (fd < 0) {
			status = errno_to_portable(errno);
		} else {
			handle = handle_new(HANDLE_FILE, name, fd, flags, NULL);
			if (handle < 0) {
				close(fd);
			} else {
				send_handle(id, handle);
				status = SSH2_FX_OK;
			}
		}
	}
	if (status != SSH2_FX_OK)
		send_status(id, status);

#ifdef NERSC_MOD
        char* t1buf = encode_string( name, strlen(name));
        s_audit("sftp_process_open_3", "count=%i int=%d uristring=%s",
                get_client_session_id(), (int)getppid(), t1buf);
        free(t1buf);
#endif

	free(name);
}
Пример #28
0
static void value_run(void* udata, Coroutine* co, void* _arg) {
  coroutine_pop(co);

  SinkArg* arg = _arg;
  Output* out = arg->out;

  char cbuf[100];
  int n;
  switch (arg->atom) {

    case RICH_NIL:
      io_writelit(out, "null");
      break;
    case RICH_BOOL:
      if (*(bool*)arg->data) {
        io_writelit(out, "true");
      } else {
        io_writelit(out, "false");
      }
      break;
    case RICH_INT:
      n = snprintf(cbuf, sizeof(cbuf), "%ld", *(int64_t*)arg->data);
      io_write(out, cbuf, n);
      break;
    case RICH_FLOAT:
      n = snprintf(cbuf, sizeof(cbuf), "%lg", *(double*)arg->data);
      io_write(out, cbuf, n);
      break;
    case RICH_STRING:
      encode_string(out, arg->data);
      break;

    case RICH_ARRAY:
      io_put(out, '[');
      *(bool*)coroutine_push(co, &array_state, sizeof(bool)) = false;
      break;
    case RICH_MAP:
      io_put(out, '{');
      *(bool*)coroutine_push(co, &map_state, sizeof(bool)) = false;
      break;

    default:
      RAISE(MALFORMED);
  }
}
Пример #29
0
void compile_string(const char *str) {
    size_t len = strlen(str);
    unsigned char arr[40] = {0};

    if (!set_pedal_type(STRING_TYPE)) {
        fprintf(stderr, "Invalid combination of options\n");
        usage();
    }
    if (len > 38) {
        fprintf(stderr, "The size of each string must be <= 38\n");
        exit(1);
    }
    if (!encode_string(str, arr)) {
        fprintf(stderr, "Cannot encode string: '%s'\n", str);
        exit(1);
    }
    compile_string_data(arr, len);
}
Пример #30
0
void encode_PINT_hint(char **pptr, const PINT_hint *hint)
{
    int transfer_count = 0;
    const PINT_hint *tmp_hint = hint;

    /* count up the transferable hints */
    while(tmp_hint)
    {
        if(tmp_hint->flags & PINT_HINT_TRANSFER)
        {
            transfer_count++;
        }

        tmp_hint = tmp_hint->next;
    }

    /* encode the number of hints to be transferred */
    encode_uint32_t(pptr, &transfer_count);

    tmp_hint = hint;
    while(tmp_hint)
    {
        /* encode the hint type */
        if(tmp_hint->flags & PINT_HINT_TRANSFER)
        {
            encode_uint32_t(pptr, &tmp_hint->type);

            /* if the type is unknown, encode the type string */
            if(tmp_hint->type == PINT_HINT_UNKNOWN)
            {
                encode_string(pptr, &tmp_hint->type_string);
                tmp_hint->encode(pptr, (void *)&tmp_hint->value);
            }
            else
            {
               /* encode the hint using the encode function provided */
               tmp_hint->encode(pptr, tmp_hint->value);
            }
        }

        tmp_hint = tmp_hint->next;
    }
}