Permission error with ASP Classic on IIS using copyFile - file

I'm writing a repository in ASP classic (using JScript) running on IIS 7.0 and I'm having some trouble with permission when moving files around. I have to following generic function that always gives me a permission denied error.
function moveFile(source, target){
fs = new ActiveXObject("Scripting.FileSystemObject");
newloc = target + "\\" + source.name;
debug("Copying file: " + source.path + " to " + newloc);
fs.copyFile(source.path, Server.MapPath( "repository/" ), true);
}
When I call the function with with source source.path being D:\Inetpub_EXT\wwwroot\builder\repo\dump\alicia.docx and target being D:\Inetpub_EXT\wwwroot\builder\repo\repository I get the following output:
Treating dumpfile: alicia
Copying file: D:\Inetpub_EXT\builder\repo\dump\alicia.docx to
D:\Inetpub_EXT\wwwroot\builder\repo\repository
Microsoft JScript runtime error '800a0046'
Permission denied
I've verified that both the folder and file exist and I gave full control to IIS_WPG, IUSR, Authenticated User, System and Administrators in builder.
Thanks for your help.

Double check your permissions. Be careful of assumptions.
For example you may be assuming that if the IIS user has permissions on the builder directory, then it has permissions on all subdirectories. This is not a good assumption.
If you set the ACL on the builder directory to give IIS permissions, after having created the subdirectories, then those subdirectories won't automatically inherit the permissions that you later applied to builder.
You can use icacls.exe from the command line to view the permissions:
%windir\system32\icacls.exe d:\inetpub\wwwroot\builder\foo\bar

Related

WPF - Attach Folder that has many files with clickonce deployment to be installed in user C drive

I am developing a WPF application, that has a function to run the "CMD" in user pc and navigate to one folder "platform-tools" that included in the application files and execute a command.
string Request = " /c" + "cd../../&cd platform-tools& adb reboot ";
Process procc = new Process();
ProcessStartInfo procStartInfo2 = new ProcessStartInfo(#"cmd.exe", Request);
As we know, when the user install the application in his PC, the application will be located in C:\Users\""UserName\AppData\Local\Apps\2.0\"random name like: JBJHV6HG7HG"
so its difficult to know where is exactly the "platform-tools" will be installed.
My question is: is there any way i can know how to reach the platform-tools folder by my "Request" in order to rung the adb command?
or
is there a way to install the "platform-tools" in different location like "User's desktop" then i can change the "CD" command in CMD to navigate to user's desktop or C drive?
Using the ClickOnce, you won't be able to change the destination install folder due some security features and so on...
you can find out more Here
You can get the path of your executing process, and concatenate the folder name to reach the "platform-tools" folder:
//There's two ways to get the current file address from your application (in the end both ends in the same):
//There's two ways to get the current file address from your application (in the end both ends in the same):
//getting the filename by the process
var cc = Process.GetCurrentProcess().MainModule.FileName;
//getting the filename by the executing assembly
var dd = System.Reflection.Assembly.GetExecutingAssembly().Location;
//getting the path for that file name
string assemblyPath = Path.GetDirectoryName(cc);
var platformTools = string.Concat(assemblyPath, #"/platform-tools/someprocess.exe");
Process.Start(platformTools);

Jenkins - cmd is not recognized

Environment:
Master Linux Jenkins server
Two Windows slave nodes
The windows slaves are running as a service
First Test
I create a Pipeline and use a use a "Execute Windows batch command" in the build section
In the Command box I put "C:\Jenkins\mytest.bat"
I checked the box "Restrict where this project can be run" and write down the name of the Windows slave
I built the pipeline and was successful
Second Test
I create a Declarative Pipeline as follows:
pipeline {
agent { label 'SiebelWindows' }
stages {
stage('Test Bat') {
steps {
bat 'C:\\Jenkins\\mytest.bat'
//bat 'start cmd.exe /c C:\\Jenkins\\mytest.bat'
//call C:\\Jenkins\\mytest.bat
}
}
}
}
In this case the build FAIL with error "cmd is not recognized as a internal o external command"
So, why can I run the .bat with a non-declarative pipeline, but fails with a declarative pipeline?
When I display the "Path" and the "PATH" variables, this was the result
Original_Path
The solution was redefine the PATH enviorement variable, like this
environment {
PATH = "C:\\WINDOWS\\SYSTEM32"
}
#JustAProgrammer aske me if C:\WINDOWS\SYSTEM32 was in the PATH of my Windows machine, and that is correct, but seems like Jenkins master do not know the slave's Windows Path.
I resolve my issue, but I still looking for a complete solution, I need to set the PATH enviorement variable with ALL the path, no only C:\WINDOWS\SYSTEM32
If someone has the problem too although the path variable looks correct, check the length of the PATH variable (echo %PATH%). Windows has some restriction of the length of an environment variable (see Microsoft DevBlog).
Remove some entries or set the PATH explicit like already mentioned.
Check also the configuration of the Environment Injector Plugin, which can override the default user and system PATH variable.

WMIC: Run Batch Script Remotely

I've been trying to get a Jenkins deploy job to work by running a batch script to do the install of an msi from the Jenkins build machine itself. I've given the appropriate access rights, but still am not able to run the following command remotely, using WMIC
wmic /node:myServerIp /user:"clientpc\my-user" /password:"my-password" process call create "D:\someDir\someOtherDir\test.bat"
The follow response from the above command:
Executing (Win32_Process)->Create()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
ReturnValue = 9;
};
After some research, it looks like return value of '9' is 'Path not found' according to https://msdn.microsoft.com/en-us/library/aa389388(v=vs.85).aspx, but I've verified that the path exists on the remote server.
The test.bat file that I'm trying to run is very simple, and should just write to a text file.
#echo This is a test.> test.txt
I've verified that both files exist on the server, and have granted 'EVERYONE' to the shared folder 'someDir'.
I have tried prefixing 'cmd.exe /c' to the path called:
wmic /node:myServerIp /user:"clientpc\my-user" /password:"my-password" process call create "cmd.exe /c D:\someDir\someOtherDir\test.bat"
...for which I receive:
Invalid Verb Switch.
I've verified that the user access is correct by providing a bad password, in which case permission is denied.
EDIT:
Changed the path from D:\someDir\someOtherDir\test.bat to D:\\someDir\\someOtherDir\\test.bat but now receive the following error:
ERROR:
Description = The RPC server is unavailable.
EDIT 2:
Looks like the RPC user I was using was the cause for the error. Still troubleshooting, but when I use my AD user, as opposed to the administrator I created to run this, I get the following AGAIN...
Executing (Win32_Process)->Create()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
ReturnValue = 9;
};
I was able to get the following to work on an Active Directory domain.
Wmic /node:"ComputerName" process call create "cmd.exe /c (net use o: /delete /y & net use o: \\Server\share /user:Domain\Administrator Password & o:\Dir\Subdir\test.cmd) >> c:\users\MyUser\testout2.txt"
The very simple contents of test.cmd:
echo Just a test >> c:\users\MyUser\testout.txt
date /t >> c:\users\MyUser\testout.txt
time /t >> c:\users\MyUser\testout.txt
The "job" is being sent to "ComputerName" on the domain. The batch/script file the job runs is on a network share. The job running on "ComputerName" will not see any mapped drives, so I delete and map a drive. I don't believe it is ever necessary to delete the drive, but I added that for completeness sake.
After execution, testout2.txt shows the batch file executing the commands and
testout.txt contains the results of the batch file commands as expected.
Things to watch out for:
As mentioned, mapped drives are not visible from the remote job
You are executing in the target machine's environment - drive letters need to make sense to that machine
Internal commands such as 'echo' require the job starts with 'CMD.EXE /c'
Group multiple commands inside parentheses and separate with ampersands (&)
Don't collide file access. I use testout.txt and testout2.txt files. If I had given them the same name, one set of outputs would have been lost.
Nothing you do this way will ever be visible to the user; the job is run in such a way that it can not display on the user's screen.
Sending a password in clear text as I show in the example is a security hazard and should be avoided. I'm not sure of a better way to map drives in this context however.

Revit Copy addin dll at shutdown

I am working on creating a revit addin and I want to have it automatically pull a copy ofthe .dll and.addin files at shutdown using a batch file. By themselves the code and the batch file routines work correctly but when I have them running with each other I get a have a sharing violation for copying the .dll file. Can anyone tell me how I can get around the sharing violation? The purpose is to deploy these two files to all users and copy the file updates to their computer when they shut down Revit.
public Result OnShutdown(UIControlledApplication application)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "S:\\Revit 2015\\Addins\\Revit Tabs\\2015_RevitTab.bat";
proc.StartInfo.WorkingDirectory = "S:\\Revit 2015\\Addins\\Revit Tabs\\";
proc.Start();
return Result.Succeeded;
}
And here is the copy syntax
xcopy "S:\Revit 2015\Addins\Revit Tabs\Revit Tabs.addin" "C:\ProgramData\Autodesk\Revit\Addins\2015" /y
xcopy "S:\Revit 2015\Addins\Revit Tabs\Revit Tabs\bin\Debug\Revit Tabs.dll" "C:\ProgramData\Autodesk\Revit\Addins\2015" /y
You could add a call to your own stand-alone utility exe that monitors whether the current Revit process is still alive, and thenexecutes the add-in DLL copy process once Revit really is gone.
I wanted to same auto-update process and after a bit of trial and error I found some code that worked for me. Hopefully, you can use it or improve it.
I have ribbon.addin, ribbon.dll ("Ribbon") and commands.dll ("Commands") files. All files are installed as part of the deployment into the "%appdata%\Autodesk\Revit\Addins\2016" folder ("Local"). It's important that these are installed in the "%appdata%" folder and not the "%programdata%\Autodesk\Revit\Addins\2016" folder because of write protection issues!
The Ribbon addin is only for checking which version of the Commands is currently in the Local folder and if that's out-of-date from the Commands file I have in a shared network folder ("Shared"). Because of security, I can't read the AssemblyVersion of the Local DLL or the Shared DLL. To get around this I have a TXT file in the Local folder that has the AssemblyVersion as the first line and, in the Shared folder I have another TXT file (where I actually have the "About" information of the Commands addin) which has the Shared Commands AssemblyVersion as the first line.
So my Ribbon OnStartup(UIControlledApplication a) code checks the TXT files using System.IO.StreamReader. If the Local file is out-of-date it updates the Local TXT and DLL files with this c#:
try
{
string AddinsDir = a.ControlledApplication.CurrentUserAddinsLocation + #"\";
string tempDir = System.IO.Path.GetTempPath();
StreamWriter myStream = new StreamWriter(tempDir + "Commands.txt", false, System.Text.Encoding.Default);
myStream.WriteLine(AssemblyVersion);
//AssemblyVersion is the first line of the Shared Commands TXT file we read
myStream.Close();
File.Copy(tempDir + "Commands.txt", AddinsDir + "Commands.txt", true);
File.Delete(tempDir + "Commands.txt");
File.Delete(AddinsDir + "Commands.dll");
File.Copy(SharedPath + "Commands.dll", AddinsDir + "Commands.dll", true);
//SharedPath is the Shared folder
}
catch (Exception e)
{
TaskDialog.Show("Error Loading Ribbon", "There was an error loading the Ribbon. Please contact the BIM Manager for assistance.\n\n" + e.Message);
return Result.Failed;
}
If, at this point the code is still running the file is up-to-date and it's time to load it:
Assembly Commands = Assembly.LoadFrom(AddinsDir + "Commands.dll");
Type type = Commands.GetType("Commands.App");
//Commands.App is my class where my Ribbon is created and Events are registered
object instanceOfCommands = Activator.CreateInstance(type, new object[] { a });
return Result.Succeeded;
My plan for Revit 2017 deployment is to create my custom Ribbon in the Ribbon.dll so I can have my "About" button there and accessible at all times. Then, I'll add a button in the "About" dialog box that would manually update the Local Commands DLL.
I hope that helps!!

Mkdir() permission denied C/linux programming

when I execute this code, I get the error Couldn't create backup sub-directory: Permission denied but I can't understand why since I give full permisions and I'm using a admin account on ubuntu.
umask(0777);
int folder_date_status = mkdir(filepath_W, 0777);
if(folder_date_status == -1){
perror("Couldn't create backup sub-directory");
return -1;
}
An admin account doesn't run with full privileges by default. This is so that programs you run don't unexpectedly act as privileged users (ie. you must explicitly give permission).
To give permission to the program to create a sub-directory in a directory which requires privileged access, try using sudo.
If the program name is called myprogram, try running:
sudo ./myprogram
Then type your password if it is requested.
Note that super-user access should only be required if it is trying to make a subdirectory in a write-restricted directory (eg. restricted directory owned by root, or another user). Also ensure that the parent directory exists (otherwise it could also throw an error).
Did you verify your filepath_w? Do you have permissio to read, write and execute on it? I suggest you to use a absolute pathname and point it to the tmp dir, something like this:
filepath_w = "/tmp/directory"

Resources