Ejemplo n.º 1
0
DWORD
LsaInitCacheFolders(
    VOID
    )
{
    DWORD dwError = 0;
    PSTR  pszCachePath = NULL;
    BOOLEAN bExists = FALSE;

    dwError = LsaSrvGetCachePath(&pszCachePath);
    BAIL_ON_LSA_ERROR(dwError);

    dwError = LsaCheckDirectoryExists(
                        pszCachePath,
                        &bExists);
    BAIL_ON_LSA_ERROR(dwError);

    if (!bExists) {
        mode_t cacheDirMode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;

        dwError = LsaCreateDirectory(pszCachePath, cacheDirMode);
        BAIL_ON_LSA_ERROR(dwError);
    }

cleanup:

    LW_SAFE_FREE_STRING(pszCachePath);

    return dwError;

error:

    goto cleanup;
}
Ejemplo n.º 2
0
DWORD
LsaCopyDirectory(
    PCSTR pszSourceDirPath,
    uid_t ownerUid,
    gid_t ownerGid,
    PSELINUX pSELinux,
    PCSTR pszDestDirPath
    )
{
    DWORD dwError = 0;
    DIR*  pDir = NULL;
    struct dirent* pDirEntry = NULL;
    struct stat statbuf = {0};
    CHAR  szSrcPath[PATH_MAX+1];
    CHAR  szDstPath[PATH_MAX+1];
    PSTR  pszTargetPath = NULL;
    PSELINUX pSELinuxLocal = NULL;

    if (NULL == (pDir = opendir(pszSourceDirPath))) {
       dwError = LwMapErrnoToLwError(errno);
       BAIL_ON_LSA_ERROR(dwError);
    }

    if (pSELinux == NULL)
    {
        dwError = SELinuxCreate(&pSELinuxLocal);
        BAIL_ON_LSA_ERROR(dwError);

        pSELinux = pSELinuxLocal;
    }

    while (NULL != (pDirEntry = readdir(pDir)))
    {
        if (!strcmp(pDirEntry->d_name, ".") ||
            !strcmp(pDirEntry->d_name, "..")||
            !strcmp(pDirEntry->d_name, "lost+found"))
            continue;

        memset(&statbuf, 0, sizeof(statbuf));

        sprintf(szSrcPath, "%s/%s", pszSourceDirPath, pDirEntry->d_name);

        if (lstat(szSrcPath, &statbuf) < 0) {
            dwError = LwMapErrnoToLwError(errno);
            BAIL_ON_LSA_ERROR(dwError);
        }

        sprintf(szDstPath, "%s/%s", pszDestDirPath, pDirEntry->d_name);

        if (S_ISDIR(statbuf.st_mode)) {

            dwError = LsaCreateDirectory(
                            szDstPath,
                            statbuf.st_mode);
            BAIL_ON_LSA_ERROR(dwError);

            dwError = LsaChangeOwner(
                            szDstPath,
                            ownerUid,
                            ownerGid);
            BAIL_ON_LSA_ERROR(dwError);

            dwError = SELinuxSetContext(
                            szDstPath,
                            statbuf.st_mode,
                            pSELinux);
            BAIL_ON_LSA_ERROR(dwError);

            dwError = LsaCopyDirectory(
                            szSrcPath,
                            ownerUid,
                            ownerGid,
                            pSELinux,
                            szDstPath);
            BAIL_ON_LSA_ERROR(dwError);

        } else if (S_ISREG(statbuf.st_mode)) {

            dwError = LsaCopyFileWithPerms(
                            szSrcPath,
                            szDstPath,
                            statbuf.st_mode);
            BAIL_ON_LSA_ERROR(dwError);

            dwError = LsaChangeOwner(
                            szDstPath,
                            ownerUid,
                            ownerGid);
            BAIL_ON_LSA_ERROR(dwError);

            dwError = SELinuxSetContext(
                            szDstPath,
                            statbuf.st_mode,
                            pSELinux);
            BAIL_ON_LSA_ERROR(dwError);

        } else if (S_ISLNK(statbuf.st_mode)) {

            dwError = LsaGetSymlinkTarget(
                            szSrcPath,
                            &pszTargetPath);
            BAIL_ON_LSA_ERROR(dwError);

            dwError = LsaCreateSymlink(
                            pszTargetPath,
                            szDstPath);
            BAIL_ON_LSA_ERROR(dwError);

            dwError = LsaChangeOwner(
                            szDstPath,
                            ownerUid,
                            ownerGid);
            BAIL_ON_LSA_ERROR(dwError);

            dwError = SELinuxSetContext(
                            szDstPath,
                            0,
                            pSELinux);
            BAIL_ON_LSA_ERROR(dwError);

        }
    }

cleanup:

    if (pDir) {
        closedir(pDir);
    }

    if (pSELinuxLocal) {
        SELinuxFree(pSELinuxLocal);
        pSELinuxLocal = NULL;
    }

    LW_SAFE_FREE_STRING(pszTargetPath);

    return dwError;

error:

    goto cleanup;
}