michael@0: // Copyright (c) 2010 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef SANDBOX_SRC_JOB_H_ michael@0: #define SANDBOX_SRC_JOB_H_ michael@0: michael@0: #include "base/basictypes.h" michael@0: #include "sandbox/win/src/restricted_token_utils.h" michael@0: michael@0: namespace sandbox { michael@0: michael@0: // Handles the creation of job objects based on a security profile. michael@0: // Sample usage: michael@0: // Job job; michael@0: // job.Init(JOB_LOCKDOWN, NULL); //no job name michael@0: // job.AssignProcessToJob(process_handle); michael@0: class Job { michael@0: public: michael@0: Job() : job_handle_(NULL) { } michael@0: michael@0: ~Job(); michael@0: michael@0: // Initializes and creates the job object. The security of the job is based michael@0: // on the security_level parameter. michael@0: // job_name can be NULL if the job is unnamed. michael@0: // If the chosen profile has too many ui restrictions, you can disable some michael@0: // by specifying them in the ui_exceptions parameters. michael@0: // If the function succeeds, the return value is ERROR_SUCCESS. If the michael@0: // function fails, the return value is the win32 error code corresponding to michael@0: // the error. michael@0: DWORD Init(JobLevel security_level, wchar_t *job_name, DWORD ui_exceptions); michael@0: michael@0: // Assigns the process referenced by process_handle to the job. michael@0: // If the function succeeds, the return value is ERROR_SUCCESS. If the michael@0: // function fails, the return value is the win32 error code corresponding to michael@0: // the error. michael@0: DWORD AssignProcessToJob(HANDLE process_handle); michael@0: michael@0: // Grants access to "handle" to the job. All processes in the job can michael@0: // subsequently recognize and use the handle. michael@0: // If the function succeeds, the return value is ERROR_SUCCESS. If the michael@0: // function fails, the return value is the win32 error code corresponding to michael@0: // the error. michael@0: DWORD UserHandleGrantAccess(HANDLE handle); michael@0: michael@0: // Revokes ownership to the job handle and returns it. The destructor of the michael@0: // class won't close the handle when called. michael@0: // If the object is not yet initialized, it returns 0. michael@0: HANDLE Detach(); michael@0: michael@0: private: michael@0: // Handle to the job referenced by the object. michael@0: HANDLE job_handle_; michael@0: michael@0: DISALLOW_COPY_AND_ASSIGN(Job); michael@0: }; michael@0: michael@0: } // namespace sandbox michael@0: michael@0: michael@0: #endif // SANDBOX_SRC_JOB_H_