Case of the Broken Website when Redirecting Desktop

In the middle of a Windows 7 deployment a customer was using an older version of a document management tool “Documentum” The client side relies on Java heavily and worked fine in IE8’s Compatibility View…until we redirected the desktop to a network location. Then although the site was accessible any attempt to open a document resulted in the following message

Failed to do substitution for “$env:{USERPROFILE}/Documentum/”

The mysterious error message didn’t offer any useful clues. Initially I used Process Monitor (http://live.sysinternals.com/ProcMon.exe) to see if any attempt to open files was failing, but this was not the case…

Through trial and error I proved that it was simply if HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Desktop was set to a UNC path (i.e. prefix \\) you would have the problem. Changing this key to a local folder would fix the issue. (Typically you should never modify this key manually – I reverted it back to default setting after changing)

How does that break a website?!!?!?!?!

So as this was a Java app I then enabled Java Console and debugging. In Windows 7 I simply launch it by typing “Java” into the Start Menu

image

On the Advanced tab of the control panel  I enabled tracing, logging, applet lifecycle exceptions and selected Show console. Show console will give us a little java icon in the system notification area we can click on when Java app is running to access the log.

image

So I kicked off the app and opened the Java Console…Hitting keys between 0-5 you can set verbosity of log. I hit 5 for most verbose. There are a few useful things here – on corporate networks the proxy= is often useful to know if Java is using correct proxy. Here we find our error along with a nice stack trace…

image

We also found a bit more details on the error here:

basic: PERF: AppletExecutionRunnable – applet.init() BEGIN ; jvmLaunch dt 4650093 us, pluginInit dt 21871797 us, TotalTime: 26521890 us

22/11/2011 2:00:28 PM FATAL: Executed command: “echo %USERPROFILE%”; output returned: “C:\Users\chentiangemalc”; error returned: “‘\\fileshare\offlinefiles$\chentiangemalc\Desktop’CMD.EXE was started with the above path as the current directory.UNC paths are not supported.  Defaulting to Windows directory.”

Ok so the user profile was being obtained by running

cmd /c echo %userprofile%

And parsing the output. Interestingly enough it had got the response – as we saw “output returned” had the correct user profile path. So why the error

CMD.EXE was started with the above path as the current directory.UNC paths are not supported. Defaulting to Windows directory.

This is the default error message if you launch a batch file directly from a UNC path. This doesn’t stop the batch file from running, but it will change the “current directory” from the UNC path to the Windows directory.

Why would this break the app though? This time I wanted to go deeper into what was going on so we could provide vendor as much info as possible to fix the app quickly

So to do this I reached for JD-GUI an absolutely excellent Java Decompiler, and it’s free! As long as the code is not obfuscated this will translate java bytecode to almost exact replica of original source. JD-GUI is available for Windows, Linux or Mac and doesn’t require Java at all, it’s written in C++ and can be downloaded here http://java.decompiler.free.fr/?q=jdgui

Legality etc of decompiling I’ll leave that discussion to lawyers. Obviously reversing to copy other’s code is not a good idea.

Because I had set trace level to 5 in Java Console I got all network requests. So I just scrolled up to network info before the error to get the location of the JAR file I needed to download

network: ResponseCode for https://dms/webtop/_0/146fer0gg-8o6j/wdk/system/ucfinit.jar : 304

network: Encoding for https://dms/webtop/_0/146fer0gg-8o6j/wdk/system/ucfinit.jar : null

network: Disconnect connection to https://dms/webtop/_0/146fer0gg-8o6j/wdk/system/ucfinit.jar

So I downloaded the JAR file and opened it in JD-GUI. I then looked for VariableResolver which was at the top of the stack trace in the console…

I found this code:

String[] args = { “$” + key };
CommandExecutor exe = new CommandExecutor();
exe.execute(“echo”, args, -1L, UCFClientInstallSystem.getUserHome());
String substValue = exe.getOutputBuffer();
String error = exe.getErrorBuffer();
logExceptionForUndefinedEnvironmentVariable(s, key, sb, substValue, args, error);
return substValue;

So I was thinking about this code and I could see what was wrong…

substValue retrieved the output from the command, the user profile. From the console we knew this had succeeded.

Command windows have an standard output buffer and an error output buffer. The error text was also retrieved. This was set due to the innocuous error “UNC paths not supported…”

Looking at the logExceptionForUndefinedEnvironmentVariable code we could see it would cause a fatal error to the application if error text was set.

image

Now unfortunately this is not really a good method to check a command has successfully run. For most Windows command prompt utilities an exit code of 0 ensures success. 

I think the code here needs to do one of two things

1) Check for exit code 0 instead of error text for failure on cmd.exe

2) If substValue is set to a profile path (or not blank) then don’t throw a fatal error

Thanks to Java Console and JD-GUI we can pinpoint exactly where & why app is broken so the developer should be able to promptly respond with a fix.

However we can also apply a fix to our systems to disable this UNC path error. This is because a UNC name can cause problems with child processes launched from such a console when the console is exited or halted.

To disable this error message set the following registry key

HKEY_CURRENT_USER\Software\Microsoft\Command Processor and add the value DisableUNCCheck REG_DWORD and set the value to 1

I used Group Policy Preferences to set this key, deployed it to test group, and the website now worked fine.

About chentiangemalc

specializes in end-user computing technologies. disclaimer 1) use at your own risk. test any solution in your environment. if you do not understand the impact/consequences of what you're doing please stop, and ask advice from somebody who does. 2) views are my own at the time of posting and do not necessarily represent my current view or the view of my employer and family members/relatives. 3) over the years Microsoft/Citrix/VMWare have given me a few free shirts, pens, paper notebooks/etc. despite these gifts i will try to remain unbiased.
This entry was posted in Application Compatibility, Internet Explorer, Java and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s