Exemple #1
0
gint qq_login(QQInfo *info, const gchar *qqnum, const gchar *passwd
		        , const gchar *status, GError **err)
{
	if(info == NULL){
		g_warning("info == NULL. (%s, %d)", __FILE__, __LINE__);
        create_error_msg(err, PARAMETER_ERR, "info == NULL");
		return PARAMETER_ERR;
	}
	if(qqnum == NULL || passwd == NULL || strlen(qqnum) == 0){
		g_warning("qqnumber or passwd == NULL.(%s, %d)"
				, __FILE__, __LINE__);
        create_error_msg(err, PARAMETER_ERR, "qqnum or passwd  == NULL");
		return PARAMETER_ERR;
	}

    //
    // The user's uin and qq number are the same.
    //
    qq_buddy_set(info -> me, "qqnumber", qqnum);
    qq_buddy_set(info -> me, "uin", qqnum);

	if(status != NULL){
        qq_buddy_set(info -> me, "status", status);
	}else{
        qq_buddy_set(info -> me, "status", "online");
	}

    return do_login(info, qqnum, passwd, status, err);
}
Exemple #2
0
static void	_send_to_channel(t_server *server, int fd,
				 char *chan, char *msg)
{
  t_channel	*tmp;
  int		i;
  t_list	*lst;

  if (!(tmp = get_channel(server->channels, chan)))
    send_code_msg(server, fd, ERR_NOSUCHNICK,
		  create_error_msg(chan, " :No such nick/channel"));
  else if (get_list(tmp->clients, server->client[fd].nick) == tmp->clients)
    send_code_msg(server, fd, ERR_CANNOTSENDTOCHAN,
		  create_error_msg(chan, " :Cannot send to channel"));
  else
    {
      lst = tmp->clients->next;
      while (lst != tmp->clients)
	{
	  i = -1;
	  while (++i < MAX_FD)
	    if (server->type_fd[i] == FD_CLIENT &&
		strcmp(server->client[i].nick, lst->data) == 0)
	      break;
	  if (i != fd)
	    send_info_msg(server, i, server->client[fd].nick, msg);
	  lst = lst->next;
	}
    }
}
Exemple #3
0
/*
** @brief send 2 numbers
**
** Used to send X Y from every client.
** It will call send_msg to send our message generated
**
** @param server our main structure with all informations
** @param fd file descriptor we will send any message
** @param val1 first integer we want to send
** @param val2 second interger we want to send
** @return 0 if no problem, else -1
*/
int	send_nbrs(t_server *server, int fd, int val1, int val2)
{
  char	*msg;
  char	*t1;
  char	*t2;
  char	*tmp;

  t1 = int_to_str(val1);
  t2 = NULL;
  if (val2 != -1 && (t2 = int_to_str(val2)) != NULL)
    {
      tmp = my_malloc(strlen(" ") + strlen(t2) + 1);
      tmp[0] = '\0';
      tmp = strcat(tmp, " ");
      tmp = strcat(tmp, t2);
      msg = create_error_msg(t1, tmp);
      free(tmp);
      free(t2);
    }
  else if (val2 != -1 && t2 == NULL)
    return (-1);
  else
    msg = create_error_msg(t1, "");
  free(t1);
  return (send_msg(server, fd, msg));
}
Exemple #4
0
static void	_send_to_client(t_server *server, int fd, char *user, char *msg)
{
  int		i;
  int		found;

  i = -1;
  found = 0;
  while (!found && ++i < MAX_FD)
    {
      if (server->type_fd[i] == FD_CLIENT &&
	  strcmp(server->client[i].nick, user) == 0)
	found = 1;
    }
  if (!found)
    send_code_msg(server, fd, ERR_NOSUCHNICK,
		  create_error_msg(user, " :No such nick/channel"));
  else
    send_info_msg(server, i, server->client[fd].nick, msg);
}
Exemple #5
0
/*
 * Do the real login.
 * Run in the main event loop.
 */
static gint do_login(QQInfo *info, const gchar *uin, const gchar *passwd
		        , const gchar *status, GError **err)
{
	g_debug("Get version...(%s, %d)", __FILE__, __LINE__);
    gint retcode = NO_ERR;
    retcode = get_version(info);
	if(retcode != NO_ERR){
        create_error_msg(err, retcode, "Get version error.");
		return retcode;
	}

    if(info -> verify_code == NULL){
        g_warning("Need verify code!!(%s, %d)", __FILE__, __LINE__);
        create_error_msg(err, WRONGVC_ERR, "Need verify code.");
        return WRONGVC_ERR;
    }

	g_debug("Login...(%s, %d)", __FILE__, __LINE__);
	GString *md5 = get_pwvc_md5(passwd, info -> verify_code -> str, err);

	g_debug("Get ptcz and skey...(%s, %d)", __FILE__, __LINE__);
	gint ret = get_ptcz_skey(info, md5 -> str);
	if(ret != 0){
		g_string_free(md5, TRUE);
		const gchar * msg;
		switch(ret)
		{
		case 1:
			msg = "System busy! Please try again.";
            retcode = NETWORK_ERR;
			break;
		case 2:
			msg = "Out of date QQ number.";
            retcode = WRONGUIN_ERR;
			break;
		case 3:
		case 6:
			msg = "Wrong password.";
            retcode = WRONGPWD_ERR;
			break;
		case 4:
			msg = "Wrong verify code.";
            retcode = WRONGVC_ERR;
			break;
		case 5:
			msg = "Verify failed.";
            retcode = OTHER_ERR;
			break;
		default:
			msg = "Error occured! Please try again.";
            retcode = OTHER_ERR;
			break;
		}
        create_error_msg(err, retcode, msg);
		return retcode;
	}
	g_string_free(md5, TRUE);

	g_debug("Get psessionid...(%s, %d)", __FILE__, __LINE__);
    retcode = get_psessionid(info);
	if(retcode != NO_ERR){
        create_error_msg(err, retcode, "Get psessionid error.");
		return retcode;
	}
    
	g_debug("Initial done.(%s, %d)", __FILE__, __LINE__);
	return NO_ERR;
}
Exemple #6
0
bool Config::read_binary_config(const char* ld_config_file_path,
                                      const char* binary_realpath,
                                      bool is_asan,
                                      const Config** config,
                                      std::string* error_msg) {
  g_config.clear();

  std::unordered_map<std::string, PropertyValue> property_map;
  if (!parse_config_file(ld_config_file_path, binary_realpath, &property_map, error_msg)) {
    return false;
  }

  Properties properties(std::move(property_map));

  auto failure_guard = android::base::make_scope_guard([] { g_config.clear(); });

  std::unordered_map<std::string, NamespaceConfig*> namespace_configs;

  namespace_configs[kDefaultConfigName] = g_config.create_namespace_config(kDefaultConfigName);

  std::vector<std::string> additional_namespaces = properties.get_strings(kPropertyAdditionalNamespaces);
  for (const auto& name : additional_namespaces) {
    namespace_configs[name] = g_config.create_namespace_config(name);
  }

  bool versioning_enabled = properties.get_bool("enable.target.sdk.version");
  int target_sdk_version = __ANDROID_API__;
  if (versioning_enabled) {
    std::string version_file = dirname(binary_realpath) + "/.version";
    std::string content;
    if (!android::base::ReadFileToString(version_file, &content)) {
      if (errno != ENOENT) {
        *error_msg = std::string("error reading version file \"") +
                     version_file + "\": " + strerror(errno);
        return false;
      }
    } else {
      content = android::base::Trim(content);
      errno = 0;
      char* end = nullptr;
      const char* content_str = content.c_str();
      int result = strtol(content_str, &end, 10);
      if (errno == 0 && *end == '\0' && result > 0) {
        target_sdk_version = result;
        properties.set_target_sdk_version(target_sdk_version);
      } else {
        *error_msg = std::string("invalid version \"") + version_file + "\": \"" + content +"\"";
        return false;
      }
    }
  }

  g_config.set_target_sdk_version(target_sdk_version);

  for (auto ns_config_it : namespace_configs) {
    auto& name = ns_config_it.first;
    NamespaceConfig* ns_config = ns_config_it.second;

    std::string property_name_prefix = std::string("namespace.") + name;

    size_t lineno = 0;
    std::vector<std::string> linked_namespaces =
        properties.get_strings(property_name_prefix + ".links", &lineno);

    for (const auto& linked_ns_name : linked_namespaces) {
      if (namespace_configs.find(linked_ns_name) == namespace_configs.end()) {
        *error_msg = create_error_msg(ld_config_file_path,
                                      lineno,
                                      std::string("undefined namespace: ") + linked_ns_name);
        return false;
      }

      bool allow_all_shared_libs = properties.get_bool(property_name_prefix + ".link." +
                                                       linked_ns_name + ".allow_all_shared_libs");

      std::string shared_libs = properties.get_string(property_name_prefix +
                                                      ".link." +
                                                      linked_ns_name +
                                                      ".shared_libs", &lineno);

      if (!allow_all_shared_libs && shared_libs.empty()) {
        *error_msg = create_error_msg(ld_config_file_path,
                                      lineno,
                                      std::string("list of shared_libs for ") +
                                      name +
                                      "->" +
                                      linked_ns_name +
                                      " link is not specified or is empty.");
        return false;
      }

      if (allow_all_shared_libs && !shared_libs.empty()) {
        *error_msg = create_error_msg(ld_config_file_path, lineno,
                                      std::string("both shared_libs and allow_all_shared_libs "
                                                  "are set for ") +
                                      name + "->" + linked_ns_name + " link.");
        return false;
      }

      ns_config->add_namespace_link(linked_ns_name, shared_libs, allow_all_shared_libs);
    }

    ns_config->set_isolated(properties.get_bool(property_name_prefix + ".isolated"));
    ns_config->set_visible(properties.get_bool(property_name_prefix + ".visible"));

    // these are affected by is_asan flag
    if (is_asan) {
      property_name_prefix += ".asan";
    }

    // search paths are resolved (canonicalized). This is required mainly for
    // the case when /vendor is a symlink to /system/vendor, which is true for
    // non Treble-ized legacy devices.
    ns_config->set_search_paths(properties.get_paths(property_name_prefix + ".search.paths", true));

    // However, for permitted paths, we are not required to resolve the paths
    // since they are only set for isolated namespaces, which implies the device
    // is Treble-ized (= /vendor is not a symlink to /system/vendor).
    // In fact, the resolving is causing an unexpected side effect of selinux
    // denials on some executables which are not allowed to access some of the
    // permitted paths.
    ns_config->set_permitted_paths(properties.get_paths(property_name_prefix + ".permitted.paths", false));
  }

  failure_guard.Disable();
  *config = &g_config;
  return true;
}
Exemple #7
0
static bool parse_config_file(const char* ld_config_file_path,
                              const char* binary_realpath,
                              std::unordered_map<std::string, PropertyValue>* properties,
                              std::string* error_msg) {
  std::string content;
  if (!android::base::ReadFileToString(ld_config_file_path, &content)) {
    if (errno != ENOENT) {
      *error_msg = std::string("error reading file \"") +
                   ld_config_file_path + "\": " + strerror(errno);
    }
    return false;
  }

  ConfigParser cp(std::move(content));

  std::string section_name;

  while (true) {
    std::string name;
    std::string value;
    std::string error;

    int result = cp.next_token(&name, &value, &error);
    if (result == ConfigParser::kError) {
      DL_WARN("%s:%zd: warning: couldn't parse %s (ignoring this line)",
              ld_config_file_path,
              cp.lineno(),
              error.c_str());
      continue;
    }

    if (result == ConfigParser::kSection || result == ConfigParser::kEndOfFile) {
      return false;
    }

    if (result == ConfigParser::kPropertyAssign) {
      if (!android::base::StartsWith(name, "dir.")) {
        DL_WARN("%s:%zd: warning: unexpected property name \"%s\", "
                "expected format dir.<section_name> (ignoring this line)",
                ld_config_file_path,
                cp.lineno(),
                name.c_str());
        continue;
      }

      // remove trailing '/'
      while (value[value.size() - 1] == '/') {
        value = value.substr(0, value.size() - 1);
      }

      if (value.empty()) {
        DL_WARN("%s:%zd: warning: property value is empty (ignoring this line)",
                ld_config_file_path,
                cp.lineno());
        continue;
      }

      if (file_is_under_dir(binary_realpath, value)) {
        section_name = name.substr(4);
        break;
      }
    }
  }

  // skip everything until we meet a correct section
  while (true) {
    std::string name;
    std::string value;
    std::string error;

    int result = cp.next_token(&name, &value, &error);

    if (result == ConfigParser::kSection && name == section_name) {
      break;
    }

    if (result == ConfigParser::kEndOfFile) {
      *error_msg = create_error_msg(ld_config_file_path,
                                    cp.lineno(),
                                    std::string("section \"") + section_name + "\" not found");
      return false;
    }
  }

  // found the section - parse it
  while (true) {
    std::string name;
    std::string value;
    std::string error;

    int result = cp.next_token(&name, &value, &error);

    if (result == ConfigParser::kEndOfFile || result == ConfigParser::kSection) {
      break;
    }

    if (result == ConfigParser::kPropertyAssign) {
      if (properties->find(name) != properties->end()) {
        DL_WARN("%s:%zd: warning: redefining property \"%s\" (overriding previous value)",
                ld_config_file_path,
                cp.lineno(),
                name.c_str());
      }

      (*properties)[name] = PropertyValue(std::move(value), cp.lineno());
    } else if (result == ConfigParser::kPropertyAppend) {
      if (properties->find(name) == properties->end()) {
        DL_WARN("%s:%zd: warning: appending to undefined property \"%s\" (treating as assignment)",
                ld_config_file_path,
                cp.lineno(),
                name.c_str());
        (*properties)[name] = PropertyValue(std::move(value), cp.lineno());
      } else {
        if (android::base::EndsWith(name, ".links") ||
            android::base::EndsWith(name, ".namespaces")) {
          value = "," + value;
          (*properties)[name].append_value(std::move(value));
        } else if (android::base::EndsWith(name, ".paths") ||
                   android::base::EndsWith(name, ".shared_libs")) {
          value = ":" + value;
          (*properties)[name].append_value(std::move(value));
        } else {
          DL_WARN("%s:%zd: warning: += isn't allowed for property \"%s\" (ignoring)",
                  ld_config_file_path,
                  cp.lineno(),
                  name.c_str());
        }
      }
    }

    if (result == ConfigParser::kError) {
      DL_WARN("%s:%zd: warning: couldn't parse %s (ignoring this line)",
              ld_config_file_path,
              cp.lineno(),
              error.c_str());
      continue;
    }
  }

  return true;
}