Esempio n. 1
0
DWORD
VmKdcStopService(
    VOID
    )
{
    return VmDirRun(VMKDC_STOP_SERVICE);
}
Esempio n. 2
0
DWORD
VmDirCleanupData(
    VOID
    )
{
    return VmDirRun(VMDIR_CLEANUP_DATA);
}
Esempio n. 3
0
DWORD
VmKdcStartService(
    VOID
    )
{
    return VmDirRun(VMKDC_START_SERVICE);
}
Esempio n. 4
0
DWORD
VmDirStopService(
    VOID
    )
{
    return VmDirRun(VMDIR_STOP_SERVICE);
}
Esempio n. 5
0
DWORD
VmDirStartService(
    VOID
    )
{
    return VmDirRun(VMDIR_START_SERVICE);
}
Esempio n. 6
0
DWORD
VmDirCleanupData(
    VOID
    )
{
#ifndef _WIN32

    return VmDirRun(VMDIR_CLEANUP_DATA);

#else

    DWORD dwError = 0;
    PSTR  pszPath[MAX_PATH+1] = {0};
    PSTR  pszCmd = NULL;

    dwError = VmDirGetRegKeyValue( VMDIR_CONFIG_SOFTWARE_KEY_PATH,
                                        VMDIR_REG_KEY_DATA_PATH,
                                        (PSTR)pszPath,
                                        MAX_PATH );
    BAIL_ON_VMDIR_ERROR( dwError );

    dwError = VmDirAllocateStringAVsnprintf( &pszCmd, "del /q \"%s\"", pszPath );
    BAIL_ON_VMDIR_ERROR(dwError)

    dwError = VmDirRun( pszCmd );
    BAIL_ON_VMDIR_ERROR(dwError);

cleanup:
    VMDIR_SAFE_FREE_MEMORY(pszCmd);

    return dwError;

error:
    goto cleanup;

#endif
}
Esempio n. 7
0
DWORD
BackupDB(PCSTR srcDir, PCSTR tgtDir)
{
#define VMDIR_MDB_DATA_FILE_NAME "data.mdb"
#define VMDIR_LOCK_DATA_FILE_NAME "lock.mdb"

    DWORD       dwError = 0;
    char        dbLocalFilename[VMDIR_MAX_FILE_NAME_LEN] = {0};
    PSTR        pszLocalErrorMsg = NULL;
    char        cpFileCmdLine[4 /* max of "cp" and "copy" */ + 1 + VMDIR_MAX_FILE_NAME_LEN + 1 +
                              VMDIR_MAX_FILE_NAME_LEN] = {0};

#ifndef _WIN32
    const char * cpFileCmd = "cp";
    const char   fileSeperator = '/';
#else
    const char * cpFileCmd = "copy";
    const char   fileSeperator = '\\';
#endif

    printf( "BackupDB: Setting vmdir state to VMDIRD_READ_ONLY \n" );
    dwError = VmDirSetState( NULL, VMDIRD_STATE_READ_ONLY );
    BAIL_ON_VMDIR_ERROR_WITH_MSG( dwError, (pszLocalErrorMsg),
                                  "BackupDB: VmDirSetState() call failed with error: %d", dwError  );

    // Backup data.mdb

    dwError = VmDirStringPrintFA( dbLocalFilename, VMDIR_MAX_FILE_NAME_LEN, "%s%c%s", srcDir, fileSeperator,
                                  VMDIR_MDB_DATA_FILE_NAME );
    BAIL_ON_VMDIR_ERROR_WITH_MSG( dwError, (pszLocalErrorMsg),
                                  "BackupDB: VmDirStringPrintFA() call failed with error: %d", dwError );

    dwError = VmDirStringPrintFA( cpFileCmdLine, sizeof(cpFileCmdLine), "%s %s %s", cpFileCmd, dbLocalFilename, tgtDir  );
    BAIL_ON_VMDIR_ERROR_WITH_MSG( dwError, (pszLocalErrorMsg),
                                  "BackupDB: VmDirStringPrintFA() call failed with error: %d", dwError );

    printf( "BackupDB: Backing up: %s \n", dbLocalFilename );

    dwError = VmDirRun(cpFileCmdLine);
    BAIL_ON_VMDIR_ERROR_WITH_MSG( dwError, (pszLocalErrorMsg),
                                  "BackupDB: VmDirRun() call failed, cmd: %s", cpFileCmdLine );

    // Backup lock.mdb

    dwError = VmDirStringPrintFA( dbLocalFilename, VMDIR_MAX_FILE_NAME_LEN, "%s%c%s", srcDir, fileSeperator,
                                  VMDIR_LOCK_DATA_FILE_NAME );
    BAIL_ON_VMDIR_ERROR_WITH_MSG( dwError, (pszLocalErrorMsg),
                                  "BackupDB: VmDirStringPrintFA() call failed with error: %d", dwError );

    dwError = VmDirStringPrintFA( cpFileCmdLine, sizeof(cpFileCmdLine), "%s %s %s", cpFileCmd, dbLocalFilename, tgtDir  );
    BAIL_ON_VMDIR_ERROR_WITH_MSG( dwError, (pszLocalErrorMsg),
                                  "BackupDB: VmDirStringPrintFA() call failed with error: %d", dwError );

    printf( "BackupDB: Backing up: %s \n", dbLocalFilename );

    dwError = VmDirRun(cpFileCmdLine);
    BAIL_ON_VMDIR_ERROR_WITH_MSG( dwError, (pszLocalErrorMsg),
                                  "BackupDB: VmDirRun() call failed, cmd: %s", cpFileCmdLine );

cleanup:
    printf( "BackupDB: Setting vmdir state to VMDIRD_NORMAL \n" );

    if ((dwError = VmDirSetState( NULL, VMDIRD_STATE_NORMAL )) != 0)
    {
        fprintf(stderr, "BackupDB: Setting vmdir state to VMDIRD_NORMAL failed, error (%d) \n", dwError);
    }

    VMDIR_SAFE_FREE_MEMORY(pszLocalErrorMsg);

    return dwError;

error:
    fprintf( stderr, "%s\n", pszLocalErrorMsg ? pszLocalErrorMsg : "Hmmm ... no local error message."  );
    goto cleanup;
}
Esempio n. 8
0
/*
 * TODO, Should chg db dir to /var/lib/vmware/vmdir/db.
 * Then we can just swap partner to db directly.
 */
static
DWORD
_VmDirSwapDBInternal(
    PCSTR   pszdbHomeDir,   // e.g. /var/lib/vmware/vmdir
    PCSTR   pszSwapDir      // e.g. /var/lib/vmware/lightwave_tmp
    )
{
    DWORD   dwError = 0;
    int     errorCode = 0;
    CHAR    cmdBuf[VMDIR_MAX_FILE_NAME_LEN] = {0};
    CHAR    partnerDBdBuf[VMDIR_MAX_FILE_NAME_LEN] = {0};
    CHAR    swapDirBuf[VMDIR_MAX_FILE_NAME_LEN] = {0};

    // /var/lib/vmware/lightwave_tmp/partner
    dwError = VmDirStringPrintFA(swapDirBuf, VMDIR_MAX_FILE_NAME_LEN,
        "%s/%s", pszSwapDir, LOCAL_PARTNER_DIR);
    BAIL_ON_VMDIR_ERROR(dwError);

    // /var/lib/vmware/vmdir/partner
    dwError = VmDirStringPrintFA(partnerDBdBuf, VMDIR_MAX_FILE_NAME_LEN,
        "%s/%s", pszdbHomeDir, LOCAL_PARTNER_DIR);
    BAIL_ON_VMDIR_ERROR(dwError);

    // rm -rf /var/lib/vmware/lightwave_tmp/partner
    dwError = VmDirStringPrintFA(cmdBuf, VMDIR_MAX_FILE_NAME_LEN,
        "rm -rf %s", swapDirBuf);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirRun(cmdBuf);
    BAIL_ON_VMDIR_ERROR(dwError);

    // mv /var/lib/vmware/vmdir/partner /var/lib/vmware/lightwave_tmp/partner
    dwError = VmDirStringPrintFA(cmdBuf, VMDIR_MAX_FILE_NAME_LEN,
        "mv %s %s", partnerDBdBuf, swapDirBuf);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirRun(cmdBuf);
    BAIL_ON_VMDIR_ERROR(dwError);

    // rm -rf /var/lib/vmware/vmdir/*
    dwError = VmDirStringPrintFA(cmdBuf, VMDIR_MAX_FILE_NAME_LEN,
        "rm -rf %s/*", pszdbHomeDir);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirRun(cmdBuf);
    BAIL_ON_VMDIR_ERROR(dwError);

    // mv /var/lib/vmware/lightwave_tmp/partner/* /var/lib/vmware/vmdir/
    dwError = VmDirStringPrintFA(cmdBuf, VMDIR_MAX_FILE_NAME_LEN,
        "mv %s/* %s/", swapDirBuf, pszdbHomeDir);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirRun(cmdBuf);
    BAIL_ON_VMDIR_ERROR(dwError);

    VMDIR_LOG_INFO(VMDIR_LOG_MASK_ALL, "%s, DB Swapped", __FUNCTION__);

cleanup:

    return dwError;

error:
    VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "Error %d, errno %d", dwError, errorCode);
    goto cleanup;
}