Ejemplo n.º 1
0
int
syscmd_check_actual_directory_exist(char * filename)
{
    int nIdx = 0;
    int nValLen = 0;
    int nCnt = sizeof(actual_root_dir)/sizeof(actual_root_dir[0]);
    rootdir_t  * rdir = NULL;

    for(nIdx = 0; nIdx < nCnt; nIdx ++)
    {
        rdir = & actual_root_dir[nIdx];
        nValLen = sal_strlen(filename);
        if(!sal_strncmp(filename, rdir->real_name, nValLen))
        {
            if(syscmd_is_directory(filename))
            {
                return 0;
            }
            else
            {
                return -1;
            }
        }
    }
    return 0;
}
Ejemplo n.º 2
0
/*******************************************************************************
 * Name:    gen_validate_relative_path
 * Purpose: validate relative path
 * Input:
 *   pszFullName: path name
 * Output:
 * Return:
 *   success: 0
 *   failed : -1
 * Note: Created by Percy Wang 2007-12-21
 ******************************************************************************/
int
gen_validate_relative_path(char *pszFullName)
{
    int nCnt = 0;
    int nRet = 0;
    int nIdx = 0;
    rootdir_t *rdir = NULL;
    char *pszTmpName;
    int nValLen = 0;

    if (NULL == pszFullName)
    {
        return -1;
    }

    if (sal_strlen(pszFullName) > M_FULLPATH_MAX_LEN)
    {
        return -1;
    }

    pszTmpName = pszFullName;

    if (sal_strchr (pszFullName, ':') != NULL)
    {
        nCnt = sizeof(actual_root_dir) / sizeof(actual_root_dir[0]);
        for (nIdx = 0; nIdx < nCnt; nIdx++)
        {
            rdir = &actual_root_dir[nIdx];
            nValLen = sal_strlen(rdir->show_name);
            if (!sal_strncmp(pszFullName, rdir->show_name,
                             sal_strlen(rdir->show_name)))
            {
                if (!sal_strcmp(pszFullName, rdir->show_name))
                {
                    return 0;
                }
                else
                {
                    pszTmpName = pszFullName + nValLen;
                    break;
                }

            }
        }

    }

    nRet = gen_validate_path(pszTmpName);

    return nRet;
}
Ejemplo n.º 3
0
Archivo: bsl.c Proyecto: ariavie/bcm
/* BSL vprintf which can extract meta data */
int
bsl_vprintf(const char *format, va_list args)
{
    const char *fmt = format;
    bsl_meta_t meta_data, *meta = &meta_data;

    bsl_meta_t_init(meta);

    if (*fmt == '<') {
        fmt++;
        while (1) {
            if (sal_strncmp(fmt, "u=%d", 4) == 0) {
                meta->unit = va_arg(args, int);
                fmt += 4;
            } else if (sal_strncmp(fmt, "p=%d", 4) == 0) {
Ejemplo n.º 4
0
/*******************************************************************************
 * Name:    gen_check_and_gen_showname
 * Purpose: check original path and build showing string
 * Input:
 *   szOrig: absolute path
 *   szShow: showing path
 * Output:
 * Return:
 *   success: 0
 *   failed : -1
 * Note:
 ******************************************************************************/
int
gen_check_and_gen_showname(char *szOrig, char *szShow)
{
    int nCnt = 0;
    int nIdx = 0;
    rootdir_t *rdir = NULL;

    if (NULL == szOrig || NULL == szShow)
    {
        return -1;
    }

    nCnt = sizeof(actual_root_dir) / sizeof(actual_root_dir[0]);
    for (nIdx = 0; nIdx < nCnt; nIdx++)
    {
        rdir = &actual_root_dir[nIdx];
        if (!sal_strncmp(szOrig, rdir->real_name,
                         sal_strlen(rdir->real_name)))
        {
            if (!sal_strcmp(szOrig, rdir->real_name))
            {
                sal_snprintf(szShow, M_FULLPATH_MAX_LEN,
                        "%s/", rdir->show_name);
            }
            else if ('/' == szOrig[sal_strlen(rdir->real_name)])
            {
                sal_snprintf(szShow, M_FULLPATH_MAX_LEN, "%s%s",
                        rdir->show_name,
                        szOrig + sal_strlen(rdir->real_name));
            }
            else
            {
                sal_snprintf(szShow, M_FULLPATH_MAX_LEN, "%s/%s",
                        rdir->show_name,
                        szOrig + sal_strlen(rdir->real_name));
            }
            return 0;
        }
    }

    return -1;

}
Ejemplo n.º 5
0
/*******************************************************************************
 * Name:    gen_check_and_get_filename
 * Purpose: check and return absolute filename
 * Input:
 *   filename: file name start with drive
 *   outsize: out buffer size
 * Output:
 *   outfile: output file name
 * Return:
 *   success: 0
 *   failed : -1
 * Note:
 ******************************************************************************/
int
gen_check_and_get_filename(char *filename, char *outfile, size_t outsize)
{
    char szFullName[M_FULLPATH_MAX_LEN];
    rootdir_t *rdir = NULL;
    int nValLen = 0;
    int nLen = 0;
    int nCnt = 0;
    int nIdx = 0;

    if (NULL == filename || NULL == outfile || 0 > outsize)
    {
        return -1;
    }

    if (sal_strlen(filename) >= M_FULLPATH_MAX_LEN)
    {
        ctc_cli_out("%% File or directory name length overflow.\n");
        return -1;
    }

    sal_snprintf(szFullName, M_FULLPATH_MAX_LEN, filename);

    if (gen_validate_relative_path(szFullName) != 0)
    {
        return -1;
    }

    gen_path_getparents(szFullName);
    nLen = sal_strlen(szFullName);

    nCnt = sizeof(actual_root_dir) / sizeof(actual_root_dir[0]);
    for (nIdx = 0; nIdx < nCnt; nIdx++)
    {
        rdir = &actual_root_dir[nIdx];
        nValLen = sal_strlen(rdir->show_name);
        if (!sal_strncmp(szFullName, rdir->show_name,
                         sal_strlen(rdir->show_name)))
        {
            if (!sal_strcmp(szFullName, rdir->show_name))
            {
                sal_snprintf(outfile, outsize, "%s",
                        rdir->real_name);
            }
            else if ('/' == szFullName[nValLen])
            {
                sal_snprintf(outfile, outsize, "%s%s",
                        rdir->real_name, szFullName + nValLen);
                if ((sal_strlen(rdir->real_name) + sal_strlen(szFullName + nValLen))
                        >= M_FULLPATH_MAX_LEN)
                {
                    ctc_cli_out("%% File or directory name length overflow.\n");
                    return -1;
                }
            }
            else
            {
                sal_snprintf(outfile, outsize, "%s/%s",
                        rdir->real_name, szFullName + nValLen);
                if ((sal_strlen(rdir->real_name) + sal_strlen(szFullName + nValLen) + 1)
                        >= M_FULLPATH_MAX_LEN)
                {
                    ctc_cli_out("%% File or directory name length overflow.\n");
                    return -1;
                }
            }
            if (gen_validate_path(outfile) != 0)
            {
                return -1;
            }
            return 0;
        }
    }

    /* is it .. or . or raw path
     * let connect it with current working directory and check it
     */
    szFullName[0] = '\0';
    szFullName[M_FULLPATH_MAX_LEN - 1] = '\0';
    if (getcwd(szFullName, M_FULLPATH_MAX_LEN) == NULL)
    {
        ctc_cli_out("%% Get current working directory failed: %s\n",
                    sal_strerror(errno));
        return -1;
    }

    nLen = sal_strlen(szFullName);
    if ('/' != filename[0])
    {
        sal_snprintf(szFullName + nLen, M_FULLPATH_MAX_LEN - nLen, "/%s", filename);
        if ((nLen + sal_strlen(filename) + 1) >= M_FULLPATH_MAX_LEN)
        {
            ctc_cli_out("%% File or directory name length overflow.\n");
            return -1;
        }
    }
    else
    {
        sal_snprintf(szFullName + nLen, M_FULLPATH_MAX_LEN - nLen, "%s", filename);
        if ((nLen + sal_strlen(filename)) >= M_FULLPATH_MAX_LEN)
        {
            ctc_cli_out("%% File or directory name length overflow.\n");
            return -1;
        }
    }
    gen_path_getparents(szFullName);
    nLen = sal_strlen(szFullName);
    nCnt = sizeof(actual_root_dir) / sizeof(actual_root_dir[0]);
    for (nIdx = 0; nIdx < nCnt; nIdx++)
    {
        rdir = &actual_root_dir[nIdx];
        nValLen = sal_strlen(rdir->real_name);
        if (!sal_strncmp(szFullName, rdir->real_name,
                         sal_strlen(rdir->real_name)))
        {
            sal_snprintf(outfile, outsize, szFullName);

            if (gen_validate_path(outfile) != 0)
            {
                return -1;
            }
            return 0;
        }
        if (!sal_strncmp(szFullName, rdir->real_name, nLen))
        {
            /* this directory not showing for user
             * setting it to root directory of this part
             */
            return -1;
        }
    }

    return -1;
}