Exemple #1
0
static int __parse_oneitem_int_section(const char *k, int *v,
                                       struct collection_item *ini,
                                       const char *section)
{
    struct collection_item *item;
    int error;

    if (get_config_item(section, k, ini, &item)) {
        logsimple(_("error reading value for %s\n"), k);
        return CLC_CONFIG_RET_ERR_CONF;
    }
    else {
        if (!item)
            return 0;

        *v = get_int_config_value(item, 1, 10, &error);
        if (error) {
            logsimple(_("error getting %s\n"), k);
            return CLC_CONFIG_RET_ERR_CONF;
        }
        else if (debug_flag == 1)
            logdebug(_("%s has value %d\n"), k, *v);
    }

    return 0;
}
Exemple #2
0
/* *v == NULL require space to be allocated */
static int __parse_oneitem_str(const char *k, char **v, int vlen, struct collection_item *ini)
{
    struct collection_item *item;
    int error;

    if (get_config_item(NULL, k, ini, &item)) {
        logsimple(_("error reading value for %s\n"), k);
        return NODE_CONFIG_RET_ERR_CONF;
    }
    else {
        if (!item)
            return 0;

        const char *s = get_const_string_config_value(item, &error);
        if (error) {
            logsimple(_("error getting %s\n"), k);
            return NODE_CONFIG_RET_ERR_CONF;
        }

        if (s == NULL || strlen(s) == 0)
            *v = NULL;
        else if (*v == NULL) {
            *v = strdup(s);
            if (*v == NULL)
                return NODE_CONFIG_RET_ERR_NOMEM;
        }
        else
            strncpy(*v, s, vlen);
    }

    return 0;
}
Exemple #3
0
    int get_recycle_directory(const int32_t disk_no, char *path, const int64_t path_len)
    {
      int ret = OB_SUCCESS;
      if (disk_no < 0 || NULL == path || path_len < 0)
      {
        TBSYS_LOG(WARN, "get_recycle_directory invalid arguments, "
            "disk_no=%d,path=%p,path_len=%ld", disk_no, path, path_len);
        ret = OB_INVALID_ARGUMENT;
      }
      else
      {
        // read from configure file
        const char *data_dir = NULL;
        const char *app_name = NULL;
        ret = get_config_item(data_dir, app_name);
        if (OB_SUCCESS == ret)
        {
          int bufsiz = snprintf(path, path_len, "%s/%d/Recycle", data_dir, disk_no);
          if (bufsiz + 1 > path_len)
          {
            TBSYS_LOG(WARN, "get_recycle_directory , path_len=%ld <= bufsiz=%d", path_len, bufsiz);
            ret = OB_SIZE_OVERFLOW;
          }
        }
      }


      return ret;
    }
Exemple #4
0
int read_colors()
{
	bracket_color = (char *)malloc(64);
	gauge_color = (char *)malloc(64);
	header_color = (char *)malloc(64);
	fs_color = (char *)malloc(64);
	data_color = (char *)malloc(64);
	perc_color = (char *)malloc(64);

	
	if (!(bracket_color = cl(get_config_item("bracket_color"))))
		bracket_color = BLUE;
	if (!(gauge_color = cl(get_config_item("gauge_color"))))
		gauge_color = YELLOW;
	if (!(header_color = cl(get_config_item("header_color"))))
		header_color = YELLOW;
	if (!(fs_color = cl(get_config_item("fs_color"))))
		fs_color = CYAN;
	if (!(data_color = cl(get_config_item("data_color"))))
		data_color = NORMAL;
	if (!(perc_color = cl(get_config_item("perc_color"))))
		perc_color = CYAN;

	return 0;
}
Exemple #5
0
static unsigned long get_checked_value(struct collection_item *metadata,
                                       const char *key,
                                       int *err)
{

    int error = EOK;
    struct collection_item *item = NULL;
    unsigned long value;

    TRACE_FLOW_STRING("get_checked_value", "Entry");
    TRACE_INFO_STRING("Key", key);

    error = get_config_item(INI_META_SEC_ACCESS,
                            key,
                            metadata,
                            &item);
    if (error) {
        TRACE_ERROR_NUMBER("Internal collection error.", error);
        *err = error;
        return 0;
    }

    /* Entry is supposed to be there so it is an error
     * is the item is not found.
     */
    if (item == NULL) {
        TRACE_ERROR_NUMBER("Expected item is not found.", ENOENT);
        *err = ENOENT;
        return 0;
    }

    value = get_ulong_config_value(item, 1, -1, &error);
    if ((error) || (value == -1)) {
        TRACE_ERROR_NUMBER("Conversion failed", EINVAL);
        *err = EINVAL;
        return 0;
    }

    *err = 0;

    TRACE_FLOW_NUMBER("get_checked_value Returning", value);
    return value;

}
Exemple #6
0
/* Function to check uid or gid */
static int check_id(struct collection_item *metadata,
                    unsigned long id,
                    const char *key)
{
    int error = EOK;
    struct collection_item *item = NULL;
    unsigned long fid;

    TRACE_FLOW_STRING("check_id", "Entry");
    TRACE_INFO_STRING("Key", key);

    error = get_config_item(INI_META_SEC_ACCESS,
                            key,
                            metadata,
                            &item);
    if (error) {
        TRACE_ERROR_NUMBER("Internal collection error.", error);
        return error;
    }

    /* Entry is supposed to be there so it is an error
        * is the item is not found.
        */
    if (item == NULL) {
        TRACE_ERROR_NUMBER("Expected item is not found.", ENOENT);
        return ENOENT;
    }

    fid = get_ulong_config_value(item, 1, -1, &error);
    if ((error) || (fid == -1)) {
        TRACE_ERROR_NUMBER("Conversion failed", EINVAL);
        return EINVAL;
    }

    if (id != fid) {
        TRACE_ERROR_NUMBER("File ID:", fid);
        TRACE_ERROR_NUMBER("ID passed in.", id);
        TRACE_ERROR_NUMBER("Access denied.", EACCES);
        return EACCES;
    }

    TRACE_FLOW_STRING("check_id", "Exit");
    return EOK;
}
Exemple #7
0
    int get_meta_path(const int32_t disk_no, const bool current, char *path, const int32_t path_len)
    {
      int ret = OB_SUCCESS;
      if (disk_no <= 0 || NULL == path ||  path_len <= 0)
      {
        TBSYS_LOG(WARN, "get_meta_path invalid arguments, "
            "disk_no=%d,path=%p,path_len=%d", disk_no, path, path_len);
        ret = OB_INVALID_ARGUMENT;
      }

      if (OB_SUCCESS == ret)
      {
        const char *data_dir = NULL;
        const char *app_name = NULL;
        ret = get_config_item(data_dir, app_name);
        if (OB_SUCCESS == ret)
        {
          int bufsiz = 0;
          if (current) 
          {
            bufsiz = snprintf(path, path_len, "%s/%d/%s/sstable/idx_%d", 
                data_dir, disk_no, app_name, disk_no);
          }
          else
          {
            time_t t;
            ::time(&t);
            struct tm* tm = ::localtime(&t);
            bufsiz = snprintf(path, path_len, "%s/%d/%s/sstable/idx_%d.%04d%02d%02d%02d%02d%02d", 
                data_dir, disk_no, app_name, disk_no, 
                tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
                tm->tm_hour, tm->tm_min, tm->tm_sec);
          }
          if (bufsiz + 1 > path_len)
          {
            TBSYS_LOG(WARN, "get_meta_path, path_len=%d <= bufsiz=%d", path_len, bufsiz);
            ret = OB_SIZE_OVERFLOW;
          }
        }
      }

      return ret;
    }
Exemple #8
0
    int get_meta_path(const int64_t version, const int32_t disk_no, 
        const bool current, char *path, const int32_t path_len)
    {
      int ret = OB_SUCCESS;
      if (version <=0 || disk_no <= 0 || NULL == path ||  path_len <= 0)
      {
        TBSYS_LOG(WARN, "get_sstable_directory invalid arguments, "
            "version=%ld, disk_no=%d,path=%p,path_len=%d", 
            version, disk_no, path, path_len);
        ret = OB_INVALID_ARGUMENT;
      }

      if (OB_SUCCESS == ret)
      {
        // read from configure file
        const char *data_dir = NULL;
        const char *app_name = NULL;
        ret = get_config_item(data_dir, app_name);
        if (OB_SUCCESS == ret)
        {
          int bufsiz = 0;
          if (current) 
          {
            bufsiz = snprintf(path, path_len, "%s/%d/%s/sstable/idx_%ld_%d", 
                data_dir, disk_no, app_name, version, disk_no);
          }
          else
          {
            bufsiz = snprintf(path, path_len, "%s/%d/%s/sstable/bak_idx_%ld_%d", 
                data_dir, disk_no, app_name, version, disk_no);
          }
          if (bufsiz + 1 > path_len)
          {
            TBSYS_LOG(WARN, "get_sstable_directory, path_len=%d <= bufsiz=%d", path_len, bufsiz);
            ret = OB_SIZE_OVERFLOW;
          }
        }
      }

      return ret;
    }
Exemple #9
0
    int get_sstable_path(const ObSSTableId& sstable_id, char *path, const int64_t path_len)
    {
      int ret = OB_SUCCESS;
      if (sstable_id.sstable_file_offset_ < 0 || NULL == path || path_len < 0)
      {
        TBSYS_LOG(WARN, "get_sstable_path invalid arguments, "
            "offset=%ld, path=%p,path_len=%ld", 
            sstable_id.sstable_file_offset_, path, path_len);
        ret = OB_INVALID_ARGUMENT;
      }
      else
      {
        // read from configure file
        const char *data_dir = NULL;
        const char *app_name = NULL;
        ret = get_config_item(data_dir, app_name);
        if (OB_SUCCESS == ret)
        {
          int32_t disk_no =  (sstable_id.sstable_file_id_ & DISK_NO_MASK);
          if (disk_no < 0)
          {
            TBSYS_LOG(WARN, "get_sstable_path, sstable file id = %ld invalid", 
                sstable_id.sstable_file_id_);
            ret = OB_ERROR;
          }
          else
          {
            int bufsiz = snprintf(path, path_len, "%s/%d/%s/sstable/%ld",
                data_dir, disk_no, app_name, sstable_id.sstable_file_id_);
            if (bufsiz + 1 > path_len)
            {
              TBSYS_LOG(WARN, "get_sstable_path, path_len=%ld <= bufsiz=%d", 
                  path_len, bufsiz);
              ret = OB_SIZE_OVERFLOW;
            }
          }
        }
      }

      return ret;
    }
Exemple #10
0
static int __parse_oneitem_int(const char *k, int *v, struct collection_item *ini)
{
    struct collection_item *item;
    int error;

    if (get_config_item(NULL, k, ini, &item)) {
        logsimple(_("error reading value for %s\n"), k);
        return NODE_CONFIG_RET_ERR_CONF;
    }
    else {
        if (!item)
            return 0;

        *v = get_int_config_value(item,1, 10, &error);
        if (error) {
            logsimple(_("error getting %s\n"), k);
            return NODE_CONFIG_RET_ERR_CONF;
        }
    }

    return 0;
}
Exemple #11
0
    int get_tmp_meta_path(const int32_t disk_no, char *path, const int32_t path_len)
    {
      /**
       * sequence number of tablet index temporary file name,
       * it will be increment atomicity to be unique .
       * only used in get_tmp_meta_path.
       */
      static volatile uint64_t s_tmp_idx_file_name_seq_no = 1;

      int ret = OB_SUCCESS;
      if (disk_no <= 0 || NULL == path ||  path_len <= 0)
      {
        TBSYS_LOG(WARN, "get_tmp_meta_path invalid arguments, "
            "disk_no=%d,path=%p,path_len=%d", disk_no, path, path_len);
        ret = OB_INVALID_ARGUMENT;
      }

      if (OB_SUCCESS == ret)
      {
        const char *data_dir = NULL;
        const char *app_name = NULL;
        uint64_t curr_tmp_meta_no = atomic_inc(&s_tmp_idx_file_name_seq_no);
        ret = get_config_item(data_dir, app_name);
        if (OB_SUCCESS == ret)
        {
          int bufsiz = snprintf(path, path_len, "%s/%d/%s/sstable/tmp_idx_%d_%ld", 
              data_dir, disk_no, app_name, disk_no, curr_tmp_meta_no);

          if (bufsiz + 1 > path_len)
          {
            TBSYS_LOG(WARN, "get_meta_path, path_len=%d <= bufsiz=%d", path_len, bufsiz);
            ret = OB_SIZE_OVERFLOW;
          }
        }
      }

      return ret;
    }
Exemple #12
0
/* Function to check access */
int config_access_check(struct collection_item *metadata,
                        uint32_t flags,
                        uid_t uid,
                        gid_t gid,
                        mode_t mode,
                        mode_t mask)
{
    int error = EOK;
    struct collection_item *item = NULL;
    mode_t f_mode;

    TRACE_FLOW_STRING("config_access_check", "Entry");

    flags &= INI_ACCESS_CHECK_MODE |
             INI_ACCESS_CHECK_GID |
             INI_ACCESS_CHECK_UID;

    if ((metadata == NULL) || (flags == 0)) {
        TRACE_ERROR_NUMBER("Invalid parameter.", EINVAL);
        return EINVAL;

    }

    /* Check that metadata is actually metadata */
    if(!col_is_of_class(metadata, COL_CLASS_INI_META)) {
        TRACE_ERROR_NUMBER("Invalid collection.", EINVAL);
        return EINVAL;
    }

    /* Check mode */
    if (flags & INI_ACCESS_CHECK_MODE) {

        error = get_config_item(INI_META_SEC_ACCESS,
                                INI_META_KEY_PERM,
                                metadata,
                                &item);
        if (error) {
            TRACE_ERROR_NUMBER("Internal collection error.", error);
            return error;
        }

        /* Entry is supposed to be there so it is an error
            * is the item is not found.
            */
        if (item == NULL) {
            TRACE_ERROR_NUMBER("Expected item is not found.", ENOENT);
            return ENOENT;
        }

        f_mode = (mode_t)get_ulong_config_value(item, 1, WRONG_FMODE, &error);
        if ((error) || (f_mode == WRONG_FMODE)) {
            TRACE_ERROR_NUMBER("Conversion failed", error);
            return ENOENT;
        }

        TRACE_INFO_NUMBER("File mode as saved.", f_mode);
        f_mode &= S_IRWXU | S_IRWXG | S_IRWXO;
        TRACE_INFO_NUMBER("File mode adjusted.", f_mode);

        TRACE_INFO_NUMBER("Mode as provided.", mode);
        mode &= S_IRWXU | S_IRWXG | S_IRWXO;
        TRACE_INFO_NUMBER("Mode adjusted.", mode);

        /* Adjust mask */
        if (mask == 0) mask = S_IRWXU | S_IRWXG | S_IRWXO;
        else mask &= S_IRWXU | S_IRWXG | S_IRWXO;

        if ((mode & mask) != (f_mode & mask)) {
            TRACE_INFO_NUMBER("File mode:", (mode & mask));
            TRACE_INFO_NUMBER("Mode adjusted.", (f_mode & mask));
            TRACE_ERROR_NUMBER("Access denied.", EACCES);
            return EACCES;
        }
    }

    /* Check uid */
    if (flags & INI_ACCESS_CHECK_UID) {

        error = check_id(metadata, (unsigned long)uid, INI_META_KEY_UID);
        if (error) {
            TRACE_ERROR_NUMBER("Check for UID failed.", error);
            return error;
        }
    }

    /* Check gid */
    if (flags & INI_ACCESS_CHECK_GID) {

        error = check_id(metadata, (unsigned long)gid, INI_META_KEY_GID);
        if (error) {
            TRACE_ERROR_NUMBER("Check for UID failed.", error);
            return error;
        }
    }

    TRACE_FLOW_STRING("config_access_check", "Exit");
    return error;

}