Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliano108 committed Jul 29, 2013
0 parents commit 1bba007
Show file tree
Hide file tree
Showing 14 changed files with 718 additions and 0 deletions.
30 changes: 30 additions & 0 deletions SeBackupPrivilege.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.3
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeBackupPrivilegeUtils", "SeBackupPrivilegeUtils\SeBackupPrivilegeUtils.csproj", "{5DFD14E2-6F1F-444D-872F-C74952AE12CE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeBackupPrivilegeCmdLets", "SeBackupPrivilegeCmdLets\SeBackupPrivilegeCmdLets.csproj", "{F0F66876-0328-48AE-BFEA-545D7C6C21AF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeBackupPrivilegeTest", "SeBackupPrivilegeTest\SeBackupPrivilegeTest.csproj", "{43CC53E2-B096-4E44-9BBB-7B1DB1E3F0C0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5DFD14E2-6F1F-444D-872F-C74952AE12CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5DFD14E2-6F1F-444D-872F-C74952AE12CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5DFD14E2-6F1F-444D-872F-C74952AE12CE}.Release|Any CPU.Build.0 = Release|Any CPU
{5DFD14E2-6F1F-444D-872F-C74952AE12CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F0F66876-0328-48AE-BFEA-545D7C6C21AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F0F66876-0328-48AE-BFEA-545D7C6C21AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F0F66876-0328-48AE-BFEA-545D7C6C21AF}.Release|Any CPU.Build.0 = Release|Any CPU
{F0F66876-0328-48AE-BFEA-545D7C6C21AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43CC53E2-B096-4E44-9BBB-7B1DB1E3F0C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43CC53E2-B096-4E44-9BBB-7B1DB1E3F0C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43CC53E2-B096-4E44-9BBB-7B1DB1E3F0C0}.Release|Any CPU.Build.0 = Release|Any CPU
{43CC53E2-B096-4E44-9BBB-7B1DB1E3F0C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
EndGlobal
69 changes: 69 additions & 0 deletions SeBackupPrivilegeCmdLets/CmdLets.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Created by SharpDevelop.
* User: Giuliano Cioffi <giuliano@108.bz>
* Date: 27/07/2013
* Time: 19:04
*
*/
using System;
using System.Management;
using System.Management.Automation;

namespace bz.OneOEight.SeBackupPrivilege
{
public class FileUtils
{
public static string expandPath(string cwd, string fileName) {
bool absolute = false;
if (fileName.IndexOf('/') == 0) absolute = true;
if (fileName.IndexOf('\\') == 0) absolute = true;
if (fileName.IndexOf(':') == 1) absolute = true;
if(!absolute) {
//Console.WriteLine("+++ " + cwd + "/" + fileName);
return(cwd + "/" + fileName);
} else {
//Console.WriteLine("+++ " + fileName);
return(fileName);
}
}
}

[Cmdlet(VerbsCommon.Get, "SeBackupPrivilege")]
public class Get_SeBackupPrivilege : Cmdlet
{
protected override void EndProcessing() {
bool retVal = SeBackupPrivilegeUtils.isSeBackupPrivilegeEnabled();
Console.WriteLine("SeBackupPrivilege is " + (retVal ? "enabled" : "disabled" ));
}
}

[Cmdlet(VerbsCommon.Set, "SeBackupPrivilege")]
public class Set_SeBackupPrivige : Cmdlet
{
[Parameter(HelpMessage = "Disable SeBackupPrivilege instead of enabling it")]
public SwitchParameter Disable;
protected override void EndProcessing() {
bool retVal = SeBackupPrivilegeUtils.setSeBackupPrivilege(!Disable.ToBool());
}
}

[Cmdlet(VerbsCommon.Copy, "FileSeBackupPrivilege")]
public class Copy_FileSeBackupPrivilege : PSCmdlet
{
[Parameter(HelpMessage = "Input file name", Position = 1)]
public string InFile;
[Parameter(HelpMessage = "Output file name", Position = 2)]
public string OutFile;
[Parameter(HelpMessage = "Overwrite output file if it exists")]
public SwitchParameter Overwrite;
protected override void EndProcessing() {
uint bytesCopied = 0;
bool retVal;
string cwd = this.SessionState.Path.CurrentFileSystemLocation.Path;
retVal = SeBackupPrivilegeUtils.CopyFile(FileUtils.expandPath(cwd,InFile), FileUtils.expandPath(cwd,OutFile), ref bytesCopied, Overwrite.ToBool());
if(retVal) {
Console.WriteLine("Copied " + bytesCopied.ToString() + " bytes");
}
}
}
}
31 changes: 31 additions & 0 deletions SeBackupPrivilegeCmdLets/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#region Using directives

using System;
using System.Reflection;
using System.Runtime.InteropServices;

#endregion

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CmdLetTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CmdLetTest")]
[assembly: AssemblyCopyright("Copyright 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// This sets the default COM visibility of types in the assembly to invisible.
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible(false)]

// The assembly version has following format :
//
// Major.Minor.Build.Revision
//
// You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]
67 changes: 67 additions & 0 deletions SeBackupPrivilegeCmdLets/SeBackupPrivilegeCmdLets.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{F0F66876-0328-48AE-BFEA-545D7C6C21AF}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Library</OutputType>
<RootNamespace>CmdLetTest</RootNamespace>
<AssemblyName>SeBackupPrivilegeCmdLets</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<AppDesignerFolder>Properties</AppDesignerFolder>
<NoWin32Manifest>False</NoWin32Manifest>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<PlatformTarget>x64</PlatformTarget>
<BaseAddress>4194304</BaseAddress>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>True</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib">
<HintPath>..\..\..\..\..\..\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorlib.dll</HintPath>
</Reference>
<Reference Include="System.Data">
<HintPath>..\..\..\..\..\..\Windows\Microsoft.NET\Framework64\v2.0.50727\System.Data.dll</HintPath>
</Reference>
<Reference Include="System.Management.Automation">
<HintPath>..\..\..\..\..\..\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0\System.Management.Automation.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CmdLets.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SeBackupPrivilegeUtils\SeBackupPrivilegeUtils.csproj">
<Project>{5DFD14E2-6F1F-444D-872F-C74952AE12CE}</Project>
<Name>SeBackupPrivilegeUtils</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Binary file not shown.
Binary file not shown.
34 changes: 34 additions & 0 deletions SeBackupPrivilegeTest/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Created by SharpDevelop.
* User: Giuliano Cioffi <giuliano@108.bz>
* Date: 28/07/2013
* Time: 19:01
*
*/
using System;

namespace bz.OneOEight.SeBackupPrivilege
{
class Program
{
public static void Main(string[] args) {
bool retVal;


retVal = SeBackupPrivilegeUtils.isSeBackupPrivilegeEnabled();
Console.WriteLine(retVal ? "Yes!" : "no");
SeBackupPrivilegeUtils.setSeBackupPrivilege(true);
retVal = SeBackupPrivilegeUtils.isSeBackupPrivilegeEnabled();
Console.WriteLine(retVal ? "Yes!" : "no");
if(!retVal) {
Console.WriteLine("SeBackupPrivilege is not enabled, giving up");
return;
}
uint bytesCopied = 0;
retVal = SeBackupPrivilegeUtils.CopyFile("c:/temp/x.txt", "c:/temp/y.txt", ref bytesCopied, true);
if(retVal) {
Console.WriteLine("Copied " + bytesCopied.ToString() + " bytes");
}
}
}
}
31 changes: 31 additions & 0 deletions SeBackupPrivilegeTest/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#region Using directives

using System;
using System.Reflection;
using System.Runtime.InteropServices;

#endregion

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SeBackupPrivilegeTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SeBackupPrivilegeTest")]
[assembly: AssemblyCopyright("Copyright 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// This sets the default COM visibility of types in the assembly to invisible.
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible(false)]

// The assembly version has following format :
//
// Major.Minor.Build.Revision
//
// You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]
64 changes: 64 additions & 0 deletions SeBackupPrivilegeTest/SeBackupPrivilegeTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{43CC53E2-B096-4E44-9BBB-7B1DB1E3F0C0}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Exe</OutputType>
<RootNamespace>SeBackupPrivilegeTest</RootNamespace>
<AssemblyName>SeBackupPrivilegeTest</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<AppDesignerFolder>Properties</AppDesignerFolder>
<NoWin32Manifest>False</NoWin32Manifest>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<PlatformTarget>x64</PlatformTarget>
<BaseAddress>4194304</BaseAddress>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>True</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SeBackupPrivilegeUtils\SeBackupPrivilegeUtils.csproj">
<Project>{5DFD14E2-6F1F-444D-872F-C74952AE12CE}</Project>
<Name>SeBackupPrivilegeUtils</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib">
<HintPath>..\..\..\..\..\..\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorlib.dll</HintPath>
</Reference>
<Reference Include="System.Data">
<HintPath>..\..\..\..\..\..\Windows\Microsoft.NET\Framework64\v2.0.50727\System.Data.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
18 changes: 18 additions & 0 deletions SeBackupPrivilegeTest/SeBackupPrivilegeTest.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.3
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeBackupPrivilegeTest", "SeBackupPrivilegeTest.csproj", "{43CC53E2-B096-4E44-9BBB-7B1DB1E3F0C0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{43CC53E2-B096-4E44-9BBB-7B1DB1E3F0C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43CC53E2-B096-4E44-9BBB-7B1DB1E3F0C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43CC53E2-B096-4E44-9BBB-7B1DB1E3F0C0}.Release|Any CPU.Build.0 = Release|Any CPU
{43CC53E2-B096-4E44-9BBB-7B1DB1E3F0C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
EndGlobal
31 changes: 31 additions & 0 deletions SeBackupPrivilegeUtils/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#region Using directives

using System;
using System.Reflection;
using System.Runtime.InteropServices;

#endregion

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SeBackupCli")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SeBackupCli")]
[assembly: AssemblyCopyright("Copyright 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// This sets the default COM visibility of types in the assembly to invisible.
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible(false)]

// The assembly version has following format :
//
// Major.Minor.Build.Revision
//
// You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]
Loading

0 comments on commit 1bba007

Please sign in to comment.