static VOID OnInitDialog(HWND hwndDlg) { HWND hwndListView; /* Set user environment variables */ hwndListView = GetDlgItem(hwndDlg, IDC_USER_VARIABLE_LIST); (void)ListView_SetExtendedListViewStyle(hwndListView, LVS_EX_FULLROWSELECT); SetListViewColumns(hwndListView); GetEnvironmentVariables(hwndListView, HKEY_CURRENT_USER, _T("Environment")); (void)ListView_SetColumnWidth(hwndListView, 2, LVSCW_AUTOSIZE_USEHEADER); ListView_SetItemState(hwndListView, 0, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); (void)ListView_Update(hwndListView,0); /* Set system environment variables */ hwndListView = GetDlgItem(hwndDlg, IDC_SYSTEM_VARIABLE_LIST); (void)ListView_SetExtendedListViewStyle(hwndListView, LVS_EX_FULLROWSELECT); SetListViewColumns(hwndListView); GetEnvironmentVariables(hwndListView, HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment")); (void)ListView_SetColumnWidth(hwndListView, 2, LVSCW_AUTOSIZE_USEHEADER); ListView_SetItemState(hwndListView, 0, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); (void)ListView_Update(hwndListView, 0); }
main(int argc, char *argv[]) { CDWriter *cdwriterP; RECORDOPTIONS options; FILEHANDLE image_file; UWORD display_speed; ULONG offset, datalen, data_blkcnt; // Enable exception handling. EXCEPTION_HANDLER_START // Get the environment variables. GetEnvironmentVariables (); // Parse the command line arguments. ParseCommandLine (argc, argv); // Register the event callback function. EventRegisterCallback (ConsoleEventCallback); // Startup the ASPI manager. ASPIAdapter::StartupManager (FALSE, FALSE, TRUE); // Find a CD-R device... if (cdwriter_id_specified) { if ((cdwriterP = (CDWriter *)ASPIAdapter::FindDeviceObject ( ASPI_M_DEVTYPE_WORM, cdwriter_adapter, cdwriter_id, cdwriter_lun)) == NULL) { fprintf (stderr, "\nError: Specified device (%u:%u:%u) is not a CD-Recorder or is unknown!\n", cdwriter_adapter, cdwriter_id, cdwriter_lun); exit (1); } } else { if ((cdwriterP = (CDWriter *)ASPIAdapter::FindDeviceObject (ASPI_M_DEVTYPE_WORM)) == NULL) { fprintf (stderr, "\nError: Unable to find a known CD-Recorder device!\n"); exit (1); } } if (log_flag) { printf ("CD-Recorder device found...\n"); printf (" HA #%u - ASPI ID #%u - %-8s %-16s %-4s\n", cdwriterP->GetAdapter(), cdwriterP->GetId(), cdwriterP->GetVendorId(), cdwriterP->GetProductId(), cdwriterP->GetFirmwareLevel()); } // Prompt the user to continue? if (confirm_flag) { printf ("\n"); if (test_flag) printf ("TEST recording mode is enabled!\n"); printf ("Hit <ENTER> to begin recording (or CTRL/C to exit)..."); getchar(); } if (log_flag) printf ("\n"); // Initialize the recording options. MEMCLEAR (&options, sizeof(RECORDOPTIONS)); options.speed = record_speed; options.disc_datatype = DATATYPE_CDDA; options.close_session_flag = close_session_flag; options.multisession_flag = multisession_flag; options.test_flag = test_flag; options.underrun_protect_flag = underrun_protect_flag; options.beep_flag = beep_flag; options.eject_flag = eject_flag; options.log_flag = log_flag; // Record the image file using track-at-once recording. cdwriterP->RecordTrackAtOnce ( image_filnam, filetype, DATATYPE_CDDA, SECTOR_CDDA_BLKLEN, &options); // Success. if (log_flag) printf ("\nCD successfully recorded!\n"); // Shutdown the ASPI manager. ASPIAdapter::ShutdownManager(); // End exception handling. EXCEPTION_HANDLER_EXIT return (0); }
//-------------------------------------------------------------------------------------------------- static inline le_result_t StartProc ( proc_Ref_t procRef, ///< [IN] The process to start. const char* workingDirPtr, ///< [IN] The path to the process's working directory, relative /// to the sandbox directory. uid_t uid, ///< [IN] The user ID to start the process as. gid_t gid, ///< [IN] The primary group ID for this process. const gid_t* groupsPtr, ///< [IN] List of supplementary groups for this process. size_t numGroups, ///< [IN] The number of groups in the supplementary groups list. const char* sandboxDirPtr ///< [IN] The path to the root of the sandbox this process is to /// run in. If NULL then process will be unsandboxed. ) { if (procRef->pid != -1) { LE_ERROR("Process '%s' (PID: %d) cannot be started because it is already running.", procRef->name, procRef->pid); return LE_FAULT; } // Create a pipe for parent/child synchronization. int syncPipeFd[2]; LE_FATAL_IF(pipe(syncPipeFd) == -1, "Could not create synchronization pipe. %m."); // @Note The current IPC system does not support forking so any reads to the config DB must be // done in the parent process. // Get the environment variables from the config tree for this process. EnvVar_t envVars[LIMIT_MAX_NUM_ENV_VARS]; int numEnvVars = GetEnvironmentVariables(procRef, envVars, LIMIT_MAX_NUM_ENV_VARS); if (numEnvVars == LE_FAULT) { LE_ERROR("Error getting environment variables. Process '%s' cannot be started.", procRef->name); return LE_FAULT; } // Get the command line arguments from the config tree for this process. char argsBuffers[LIMIT_MAX_NUM_CMD_LINE_ARGS][LIMIT_MAX_ARGS_STR_BYTES]; char* argsPtr[NUM_ARGS_PTRS]; if (GetArgs(procRef, argsBuffers, argsPtr) != LE_OK) { LE_ERROR("Could not get command line arguments, process '%s' cannot be started.", procRef->name); return LE_FAULT; } // Get the smack label for the process. // Must get the label here because smack_GetAppLabel uses the config and we can not // use any IPC after a fork. char smackLabel[LIMIT_MAX_SMACK_LABEL_BYTES]; appSmack_GetLabel(app_GetName(procRef->appRef), smackLabel, sizeof(smackLabel)); // Create pipes for the process's standard error and standard out streams. int stderrPipe[2]; int stdoutPipe[2]; CreatePipe(procRef, stderrPipe, STDERR_FILENO); CreatePipe(procRef, stdoutPipe, STDOUT_FILENO); // Create the child process pid_t pID = fork(); if (pID < 0) { LE_EMERG("Failed to fork. %m."); return LE_FAULT; } if (pID == 0) { // Wait for the parent to allow us to continue by blocking on the read pipe until it // is closed. fd_Close(syncPipeFd[WRITE_PIPE]); ssize_t numBytesRead; int dummyBuf; do { numBytesRead = read(syncPipeFd[READ_PIPE], &dummyBuf, 1); } while ( ((numBytesRead == -1) && (errno == EINTR)) || (numBytesRead != 0) ); LE_FATAL_IF(numBytesRead == -1, "Could not read synchronization pipe. %m."); // The parent has allowed us to continue. // Redirect the process's standard streams. RedirectStdStream(stderrPipe, STDERR_FILENO); RedirectStdStream(stdoutPipe, STDOUT_FILENO); // Set the process's SMACK label. smack_SetMyLabel(smackLabel); // Set the umask so that files are not accidentally created with global permissions. umask(S_IRWXG | S_IRWXO); // Unblock all signals that might have been blocked. sigset_t sigSet; LE_ASSERT(sigfillset(&sigSet) == 0); LE_ASSERT(pthread_sigmask(SIG_UNBLOCK, &sigSet, NULL) == 0); SetEnvironmentVariables(envVars, numEnvVars); // Setup the process environment. if (sandboxDirPtr != NULL) { // Sandbox the process. sandbox_ConfineProc(sandboxDirPtr, uid, gid, groupsPtr, numGroups, workingDirPtr); } else { ConfigNonSandboxedProcess(workingDirPtr); } // Launch the child program. This should not return unless there was an error. LE_INFO("Execing '%s'", argsPtr[0]); // Close all non-standard file descriptors. fd_CloseAllNonStd(); execvp(argsPtr[0], &(argsPtr[1])); // The program could not be started. Log an error message. log_ReInit(); LE_FATAL("Could not exec '%s'. %m.", argsPtr[0]); } procRef->pid = pID; procRef->paused = false; // Don't need this end of the pipe. fd_Close(syncPipeFd[READ_PIPE]); // Set the scheduling priority for the child process while the child process is blocked. SetSchedulingPriority(procRef); // Send standard pipes to the log daemon so they will show up in the logs. SendStdPipeToLogDaemon(procRef, stderrPipe, STDERR_FILENO); SendStdPipeToLogDaemon(procRef, stdoutPipe, STDOUT_FILENO); // Set the resource limits for the child process while the child process is blocked. if (resLim_SetProcLimits(procRef) != LE_OK) { LE_ERROR("Could not set the resource limits. %m."); kill_Hard(procRef->pid); } LE_INFO("Starting process %s with pid %d", procRef->name, procRef->pid); // Unblock the child process. fd_Close(syncPipeFd[WRITE_PIPE]); return LE_OK; }
main(int argc, char *argv[]) { CDReader *cdreaderP; FILEHANDLE image_file; UWORD audio_blklen, mode1_blklen, mode2_blklen; TCHAR image_filnam[_MAX_PATH + 1]; TCHAR cue_filnam[_MAX_PATH + 1]; TCHAR cdtext_filnam[_MAX_PATH + 1]; TCHAR *image_filnamP = NULL, *cue_filnamP = NULL, *cdtext_filnamP = NULL; // Enable exception handling. EXCEPTION_HANDLER_START // Initialize and check the protection. ProtInitialize (NULL, FALSE); // Get the environment variables. GetEnvironmentVariables(); // Parse the command line arguments. ParseCommandLine (argc, argv); // Register the event callback function. EventRegisterCallback (ConsoleEventCallback); // Startup the ASPI manager. ASPIAdapter::StartupManager (FALSE, FALSE, TRUE); // Find a CDROM device... if (cdreader_id_specified) { if ((cdreaderP = (CDReader *)ASPIAdapter::FindDeviceObject ( ASPI_M_DEVTYPE_CDROM | ASPI_M_DEVTYPE_WORM, cdreader_adapter, cdreader_id, cdreader_lun)) == NULL) { fprintf (stderr, "\nError: Specified device (%u:%u:%u) is not a CDROM!\n", cdreader_adapter, cdreader_id, cdreader_lun); exit (1); } } else { if ((cdreaderP = (CDReader *)ASPIAdapter::FindDeviceObject ( ASPI_M_DEVTYPE_CDROM | ASPI_M_DEVTYPE_WORM)) == NULL) { fprintf (stderr, "\nError: Unable to find a known CDROM device!\n"); exit (1); } } if (log_flag) { printf ("CDROM device found...\n"); printf (" HA #%u - ASPI ID #%u - %-8s %-16s %-4s\n\n", cdreaderP->GetAdapter(), cdreaderP->GetId(), cdreaderP->GetVendorId(), cdreaderP->GetProductId(), cdreaderP->GetFirmwareLevel()); } if (cdreaderP->GetModel() == GENERIC_CDROM_SCSI) { fprintf (stderr, "Warning: CDROM device model is unknown to this program!\n"); fprintf (stderr, "The generic CDROM device driver will be used...\n\n"); } // If necessary, check that this device supports the reading of SUBCODEs. if ((scan_subcode_mode == SCAN_SUBCODE_QUICK) || (scan_subcode_mode == SCAN_SUBCODE_FULL)) { if (! cdreaderP->IsFlagSet(CDReader::crfReadSUBQ)) { fprintf (stderr, "Error: CDROM device does not support the reading of subcodes!\n"); exit (1); } } // If necessary, check that this device supports the reading of CD+G discs. if (cdg_flag && (! cdreaderP->IsFlagSet(CDReader::crfReadCDG))) { fprintf (stderr, "Error: CDROM device does not support the reading of CD+G discs!\n"); exit (1); } // Analyze the disc layout. auto_ptr<DiscLayout> disclayoutP(new DiscLayout ( cdreaderP, read_speed, scan_subcode_mode, mcn_isrc_flag, cdtext_flag, log_flag)); if (log_flag) { printf ("\nDisc Statistics:\n"); printf (" Audio track count - %u\n", disclayoutP->m_nAudioTrackCount); printf (" Mode1 data track count - %u\n", disclayoutP->m_nMode1TrackCount); printf (" Mode2 data track count - %u\n", disclayoutP->m_nMode2TrackCount); } // Is the disc too long? if (disclayoutP->m_nLastLBA > CDROM_80MIN_BLKCNT) fprintf (stderr, "\nWARNING: Disc is longer than 80 minutes!\n"); // Check the disc layout. if (! disclayoutP->Check()) { fprintf (stderr, "\nWARNING: Disc contains one or more tracks that are shorter than \n"); fprintf (stderr, "four seconds. This is a violation of the CDROM specification.\n"); } // Determine the block lengths. audio_blklen = (cdg_flag ? SECTOR_CDDA_SUBPW_BLKLEN : SECTOR_CDDA_BLKLEN); if (cooked_flag) {mode1_blklen = SECTOR_MODE1_BLKLEN; mode2_blklen = SECTOR_MODE2_BLKLEN;} else {mode1_blklen = SECTOR_RAW_BLKLEN; mode2_blklen = SECTOR_RAW_BLKLEN;} // Set the block length for each track. DiscInfo *discinfoP = disclayoutP->m_pDiscInfo; for (int i = 0; i < discinfoP->m_nTrackCount; i++) { TRACKINFO *trackinfoP = &discinfoP->m_TrackInfo[i]; switch (trackinfoP->datatype) { case DATATYPE_CDDA: trackinfoP->blklen = audio_blklen; break; case DATATYPE_CDROM: trackinfoP->blklen = mode1_blklen; break; case DATATYPE_CDROMXA: case DATATYPE_CDI: trackinfoP->blklen = mode2_blklen; break; } } // Build the cuesheet filename. StringCopy (cue_filnam, base_filnamP); FileAddExtension (cue_filnam, ".cue", (! cueonly_flag)); cue_filnamP = cue_filnam; // If we're not just writing a cuesheet, then build the image and CD-TEXT filenames. if (! cueonly_flag) { StringCopy (image_filnam, base_filnamP); FileAddExtension (image_filnam, ".bin", FALSE); image_filnamP = image_filnam; if (cdtext_flag && (discinfoP->m_pCDTextPackVec != NULL)) { StringCopy (cdtext_filnam, base_filnamP); FileAddExtension (cdtext_filnam, ".cdt", TRUE); cdtext_filnamP = cdtext_filnam; } // Display image file stats? if (log_flag) { // Compute the amount of disc space required. ULONG blkcnt = disclayoutP->m_nLastLBA + 1; printf ("\nImage file will require approximately %luMb of disk space.\n", CDIV (blkcnt * SECTOR_RAW_BLKLEN, 0x100000)); } // Prompt to begin copy? if (confirm_flag) { printf ("\nHit <ENTER> to copy disc (or CTRL/C to exit)..."); getchar (); printf ("\n"); } } // Generate the CUE SHEET file. disclayoutP->GenerateCuesheetFile (cue_filnamP, image_filnamP, cdtext_filnamP); // Generate the CD-TEXT data file? if (cdtext_filnamP != NULL) { FILEHANDLE handle; ULONG null = 0; if ((handle = FileCreate (cdtext_filnamP)) == NULL) SignalException (E_CreateFile, 1, 0, 0, HeapString(cdtext_filnamP)); FileWrite ( handle, discinfoP->m_pCDTextPackVec, discinfoP->m_nCDTextPackCount * sizeof(CDTEXTPACK)); FileWrite (handle, &null, 1); FileClose (handle); } // Generate the image file? if (image_filnamP != NULL) { // Make sure the device is ready. cdreaderP->LoadDisc (TRUE); // Create the output image file. if ((image_file = FileCreate (image_filnamP)) == NULL) { fprintf (stderr, "\nError creating image file \"%s\"\n", image_filnamP); exit (1); } // Loop through the "copy instructions"... for (int i = 0; i < disclayoutP->m_nCopyInstrCount; i++) { COPYINSTR *copyinstrP = &disclayoutP->m_CopyInstr[i]; // Set the block length. UWORD blklen = ((copyinstrP->datatype == DATATYPE_CDDA) ? audio_blklen : ((copyinstrP->datatype == DATATYPE_CDROM) ? mode1_blklen : mode2_blklen)); // Select operation... switch (copyinstrP->opcode) { // Read a range of audio/data sectors. case CI_READ_SECTORS: { if (copyinstrP->datatype == DATATYPE_CDDA) { // Set the reading speed. cdreaderP->SetSpindleSpeed (read_speed, FALSE, FALSE); // Extract the audio sectors. cdreaderP->ExtractSectorsToFile ( image_file, DATATYPE_CDDA, blklen, copyinstrP->lba, copyinstrP->blkcnt, jitter_mode, 0, error_mode, FALSE, log_flag); } else { // Set the reading speed to maximum. cdreaderP->SetSpindleSpeed (SPEED_MAX, TRUE, FALSE); // Extract the data sectors. cdreaderP->ExtractSectorsToFile ( image_file, copyinstrP->datatype, blklen, copyinstrP->lba, copyinstrP->blkcnt, JITTER_MODE_DISABLE, 0, error_mode, FALSE, log_flag); } break; } // Generate replacements for unreadable blocks at the end of a track. case CI_GENERATE_SECTORS: { WriteEmptySectors ( image_file, copyinstrP->datatype, blklen, copyinstrP->lba, copyinstrP->blkcnt); break; } // Ignore PREGAP instructions. case CI_GENERATE_PREGAP: case CI_GENERATE_PREGAP2: break; default: SignalException (E_BugCheck); } } // Reset the reading speed. cdreaderP->SetSpindleSpeed (SPEED_MAX, FALSE, FALSE); // Close the image file. FileClose (image_file); // Success! if (log_flag) printf ("\nCopy completed successfully!\n"); // Notify user of completion? if (beep_flag) BeepUser(); } // Shutdown the ASPI manager. ASPIAdapter::ShutdownManager(); // End exception handling. EXCEPTION_HANDLER_EXIT return (0); }