2

I'm running ColdFusion 9 add Windows Server Datacenter. I have written a batch file that creates a directory on the system. If I use cfexecute to call cmd.exe to run the batch file, who is the owner of the directory created? Is it the user that runs ColdFusion, or is it the user that created the batch file, or is it neither of those two?

I'm restricted from creating a Windows scheduled task, and I can't use cfdirectory to create the folders because the CF user has elevated permissions, and even mode=777 doesn't work. Any input or insight is appreciated.

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
js1983
  • 310
  • 2
  • 12

3 Answers3

5

any actions performed by Coldfusion are done in the context of the user under which the coldfusion service runs, so any files/folders will also be owned by that user. Since it is a windows server you cannot use unix commands to change permissions.

If you have access to cfexecute then you can pretty much do anything from command line, so it is pretty pointless for them to restrict cfdirectory, maybe you should point this out to them. If they want to restrict access then it would be better to do this using security sandboxes, and the permissions of the user under which the service runs.

snake
  • 732
  • 1
  • 6
  • 11
2

If using Windows, CFX_EXEC is an option that provides more features than ColdFusion's built-in CFExecute:

http://adiabata.com/cfx_exec.cfm

It's written in C++ and should work with all versions of ColdFusion that you can successfully install on Windows. It will enable you to run external processes under a specific account and even perform on-the-fly batch file creation.

<!--- Credential Check --->
<cf_exec fnc="USER" user="#user#" pwd="#pwd#" domain="#domain#">
<cfif status neq "OK">
    <cfoutput>Error: #MSG#<br>
    Error number: #ERRN#</cfoutput>
<cfelse>
    Credentials OK
</cfif>

<!--- On-the-fly BAT file --->
<cf_exec cmd="cmd.exe" user="#user#" pwd="#pwd#" domain="#domain#">
@echo off
netstat -e
cd c:\
dir "<cfoutput>#dir#</cfoutput>"
ipconfig /all
exit
</cf_exec>
James Moberg
  • 4,360
  • 1
  • 22
  • 21
0

As a brief addendum to snake's correct answer, you can check the ownership of a file/directory as of Java7+ using a bit of NIO:

    Paths = createObject("java", "java.nio.file.Paths");
    Files = createObject("java", "java.nio.file.Files");
    fileOrDirectoryToCheck = Paths.get("c:\path\someFolder\", []);
    owner = Files.getOwner(fileOrDirectoryToCheck, []);
    writeDump("Owner: " & owner.getName());
Community
  • 1
  • 1
Leigh
  • 28,765
  • 10
  • 55
  • 103