<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AskApache &#187; Search Results  &#187;  boot</title>
	<atom:link href="http://www.askapache.com/search/boot/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.askapache.com</link>
	<description>Advanced Web Development</description>
	<lastBuildDate>Thu, 26 Apr 2012 11:29:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>HOWTO: Uninstall CPANEL over SSH</title>
		<link>http://www.askapache.com/hacking/uninstall-cpanel.html</link>
		<comments>http://www.askapache.com/hacking/uninstall-cpanel.html#comments</comments>
		<pubDate>Mon, 04 Jul 2011 18:55:40 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4404</guid>
		<description><![CDATA[<p>The following is just a quick reference of some of the commands I used to successfully uninstall cpanel.  This is for advanced users of the shell.  If you aren't that advanced and you run a single one of these commands without fully understanding it, you will probably kill your server, probably lose everything on it permanently, probably not have a website or email for weeks..  So backup all your data FIRST.  Also, if you aren't 100% sure you won't run into problems, you should contact your hosts technical support - but be prepared for some MAJOR negativity..  cpanel makes things very easy for hosts, you are just a drop in their bucket.</p>

<blockquote cite="http://www.askapache.com/server-administration/uninstall-cpanel.html#comment-168222">
<p><strong>Wow!</strong></p>
<p>You sure gotta bigger set that *I* do. . . . - for real! I've been known to do some abysmally stupid things in my day - and actually had them work the way I wanted them to! - but this takes the <strong>titanium, gadolinium, rhodium alloy cake</strong>!</p>
<p>Me, I'd try something like that and find out later that the fire-trucks showed up right after I hit the "Enter" key. It's a REALLY interesting post, and a real eye-opener - especially for someone who is relatively new to the whole web-hosting-service paradigm.  I know, no guts, no glory - but THIS is WAY over the top!  I'm reading this and thinking <em>"Why not just put a couple of sticks of dynamite under the thing?"</em></p>
<p>Seriously now, this was an excellent read - and for someone who is just now looking into the whole web-hosting paradigm, it's a real eye-opener.  Though I think I'll just tiptoe past this <strong>REAL QUIETLY</strong> for now. . . .  (laughing!)</p>
<p><a href="http://www.qatechtips.com/">Jim</a></p>
</blockquote>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/hacking/uninstall-cpanel.html"></a><a href="http://www.askapache.com/hacking/uninstall-cpanel.html"><cite>AskApache.com</cite></a></p><p><strong>WARNING!</strong> This is for advanced users of the shell, this is NOT a howto or tutorial.  The thing is, I googled <strong>how to uninstall cpanel</strong> and for once in my life I came up empty.. And certainly the cpanel official sites themselves don't provide any instructions other than to say "Dont uninstall it, reinstall your entire operating system without it."..   they sure don't seem confident that they know exactly what their code is doing.  Cpanel is great for most people, perfect for many situations, so don't get me wrong.. this is just for fun.</p>

<h2>Why Uninstall?</h2>
<p>Why?  Because I have always built my servers, php installations, perl installs, ruby, iptables, everything from source.  I read the INSTALL/README docs, I read the man pages, and I read the info pages as well.  I google for configuration advice, I google for tips, and I don't need a web-based perl script messing my stuff up!</p>
<p>The main problems I had with cpanel, which really is a great bit of software for millions of website developers, is that it was incredibly sneaky!  I used it for about 6 months and spent that entire time trying to figure out what the heck it was doing.  A couple issues that I really disliked, it takes over your bind install, it takes over your apache install, it takes over your php install.  And although it does let you configure some things (very few) for custom configurations and the like, I just don't need any of that.  By removing the darn thing I am saving GIGS of space on my server, tons of bandwidth, and most importantly to me I am saving CPU and processing time along with RAM and IO speed.</p>
<h3>Anything Else</h3>
<p>Please.. I could go on for DAYS!  Another reason I have wanted to be rid of cpanel is that I like my servers to be as lean and mean as possible.  This means I like as few files and processes as possible.  There are many benefits to this, like it's much easier for my integrity checking software and rootkit/antivirus software to run and drastically reduces the false positives.  And there is that glaring security issue of constantly having cpanel run it's own software to create the WHM/Cpanel web interface, which is accessible online.  I haven't researched cpanel security at all, it's possible that it never has security problems that are published, but for me, why take the chance?</p>


<h2>Warning - Caution!</h2>
<p>The following is just a quick reference of some of the commands I used to uninstall cpanel.  This is for advanced users of the shell.  If you aren't that advanced and you run a single one of these commands without fully understanding it, you will probably kill your server, probably lose everything on it permanently, probably not have a website or email for weeks..  So backup all your data FIRST.  Also, if you aren't 100% sure you won't run into problems, you should contact your hosts technical support - but be prepared for some MAJOR negativity..  cpanel makes things very easy for hosts, and the last thing tech support wants is to fix a server broken by someone who doesn't know what they are doing.</p>

<h2>Last Warning!</h2>
<p>Unless you understand what theses commands do and the purpose they serve, do not try any of this.  These are not the exact commands I used verbatim, they are also not in order.  I only put them up here because I was so amazed that google didn't have any uninstall cpanel intructions.  Hopefully it's not a conspiracy that will get my site taken down.. ;)</p>
<p>That said and out of the way, it really only took me about 10 minutes to uninstall cpanel completely.  But keep in mind I have been closely monitoring and debugging cpanel for 6 months, so I knew what I was doing.  And finally, I do apologize for not having better instructions.. but hey, if you don't get this then you have no business trying to figure out how to uninstall cpanel!  It's great software and shouldn't be removed unless you are fully capable of managing email/dns/www/ftp and any/all other servers and services on your machine by hand.</p>

<h2>Do This First</h2>
<p>I have a few drafts I'm working on at the moment with specifics, but for now you will have to figure it out with google.  Basically you want to make sure you don't totally knock your machine offline without being able to reconnect.  What I do is compile a static version of openssh and a few other security-type shell tools, and configure this binary sshd to run by using inittab, which is the file run by init (pid 1) and makes sure if it dies it is restarted.  Here is my /etc/inittab to run the static sshd binary:</p>
<pre>hh:12345:respawn:/failover/os/sbin/aassh -D -q -u0 -f /failover/os/etc/aassh</pre>

<p>Another trick is to keep a detached screen logged in to root.  That way if you mess up your sudoers or securetty or pam or whatever, you can just reattach and fix it.</p>
<p>Finally, you may want to setup your syslog to start earlier than usual, and set up more than normal verbosity.  ( I take it to the max ).  Then you should setup a 2nd server or machine somewhere to act as a syslog server.  Lastly, configure your web server syslog to copy all messages to the remote syslog you set up.  I use a reverse ssh tunnel to encrypt the syslog packets, but when I do something serious like reboot after uninstalling cpanel, I prepare for it by adding additional networking routes on my machine to make sure I will get some logs even if sshd cant start or even if my network addresses aren't brought up correctly.</p>
<p>If that sounds easy to you, please continue.   If you are saying: Wha??? Continue in read-only mode.</p>

<p class="cnote">Also, you can't just uninstall cpanel, I have replaced a lot of cpanel already, like building my own bind, apache, php, syslog and making sure they work and aren't being tampered with by cpanel.  Basically cpanel runs everything on your server in most cases, so you should prepare by creating your own static software to replace cpanel, and make sure it works.</p>


<h2>Find files Accessing /var/cpanel</h2>
<p>More than likely these will need to be killed.</p>
<pre>lsof +w -Rg -nP +c15 -x f +D /var/cpanel
lsof +w -Rg -nP +c15 -x f +D /usr/local/cpanel</pre>

<h2>Killing cpanel</h2>
<p>Just an example, your machine may have a lot more than these, I have been slowly taking control of my machine back from cpanel for 6 months, so it was easier for me.</p>
<pre>for P in tailwatchd queueprocd cpanellogd exim; do pkill -9 $P; done</pre>

<h2>Commands and Shortcuts</h2>
<pre>alias NF=&#039;nice find $PWD -mount -depth ! -type d&#039;
alias NFF=&#039;nice find $PWD -mount -depth ! -type d | xargs -IF87 file F87&#039;
alias NA=&#039;nice find $PWD -mount -depth&#039;
alias NAF=&#039;nice find $PWD -mount -depth | xargs -IF87 file F87&#039;</pre>


<h2>Watch out for crontab</h2>
<p>An example of the sneakiness (from my POV, from most it's called builtin robustness) that cpanel does is automagically adding crontab entries that make it behave similarly to a self-propagating virus.  If you don't disable the cronjobs and kill the right processes within a short period of time, be prepared for a magic resurrection.</p>

<p>Here's my awesome crontab information function, you will need to check every file, it lists the default crons on my box, and every users crontab, but it can't account for other cron software like at and other crons.</p>
<pre>function askapache_crontab()
{
  local GG i;
  for i in `getent passwd|cut -d ":" -f1`;
  do
    GG=$(sudo crontab -u $i -l 2&gt;$N6 | tr -s &#039;\n\000&#039; | sed &#039;/^#/d&#039;);
    [[ ${#GG} -gt 3 ]] &amp;&amp; sleep 1 &amp;&amp; echo -e "$i \n\n${GG}"
  done;
   sleep 4;
   ls -aLls1ch --color=always /etc/cron.{hourly,daily,weekly,monthly,d} | sed &#039;/^total/d; /\ drwxr-xr-x/d&#039;;
}</pre>



<pre>grep -ir /var/spool cpan</pre>
<pre>#6 3 * * * /scripts/upcp
#0 1 * * * /scripts/cpbackup
#0 2 * * * /scripts/mailman_chown_archives
#35 * * * * /usr/bin/test -x /usr/local/cpanel/bin/tail-check &amp;&amp; /usr/local/cpanel/bin/tail-check
#11,26,41,56 * * * * /usr/local/cpanel/whostmgr/bin/dnsqueue &gt; /dev/null 2&gt;&amp;1
#30 */4 * * * /usr/bin/test -x /scripts/update_db_cache &amp;&amp; /scripts/update_db_cache
#45 */8 * * * /usr/bin/test -x /usr/local/cpanel/bin/optimizefs &amp;&amp; /usr/local/cpanel/bin/optimizefs
#*/5 * * * * /usr/local/cpanel/bin/dcpumon &gt;/dev/null 2&gt;&amp;1
#25 1 * * * /usr/local/cpanel/whostmgr/docroot/cgi/cpaddons_report.pl --notify</pre>



<h2>Delete Crontabs</h2>
<pre>sudo crontab -u mailman -r</pre>


<h2>Find INIT scripts with cpanel</h2>
<p>This is the main startup script: <code>/usr/local/cpanel/etc/init/startup</code></p>
<p>I had no idea ruby-on-rails was being controlled by cpanel.. sneaky bugger.  You can tell by all of these advanced unix commands just how difficult it would be to uninstall cpanel, its totally like the Alien!</p>
<pre>(1:3744)# find . ! -type d -print0|xargs -0 -I&#039;F87&#039; grep -Hi "cpan\|tailwat\|chkser" F87
./fastmail:# Author:       cPanel, Inc. &lt;nick@cpanel.net&gt;
./httpd:        HTTPD=/usr/local/cpanel/bin/chroothttpd
./cpanel:# cpanel8       Start Cpanel Services
./cpanel:# Author:       cPanel, Inc. &lt;nick@cpanel.net&gt;
./cpanel:# description: This is the cpanel webserver and chat.
./cpanel:# processname: cpaneld
./cpanel:# pidfile: /var/run/cpanel.pid
./cpanel:[ -f /usr/local/cpanel/etc/init/startup ] || exit 0
./cpanel:       if [ -f "/var/cpanel/smtpgidonlytweak" ]; then
./cpanel:       echo -n "Starting cPanel services: "
./cpanel:       daemon /usr/local/cpanel/etc/init/startcpsrvd
./cpanel:       echo -n "Starting cPanel brute force detector services: "
./cpanel:       daemon /usr/local/cpanel/etc/init/startcphulkd
./cpanel:    echo -n "Starting cPanel dav services: "
./cpanel:       daemon /usr/local/cpanel/etc/init/startcpdavd
./cpanel:               daemon /usr/local/cpanel/etc/init/startcppop
./cpanel:       echo -n "Starting cPanel Chat services: "
./cpanel:               daemon /usr/local/cpanel/entropychat/entropychat
./cpanel:               daemon /usr/local/cpanel/bin/startmelange
./cpanel:                       /usr/local/cpanel/bin/startinterchange
./cpanel:       echo -n "Starting cPanel ssl services: "
./cpanel:       daemon /usr/local/cpanel/startstunnel
./cpanel:    echo -n "Starting cPanel Queue services: "
./cpanel:       daemon /usr/local/cpanel/etc/init/startqueueprocd
./cpanel:    echo -n "Starting tailwatchd: "
./cpanel:    daemon /usr/local/cpanel/libexec/tailwatchd --start
./cpanel:       echo -n "Starting cPanel Log services: "
./cpanel:       daemon /usr/local/cpanel/cpanellogd
./cpanel:    action "Starting mailman services: " /usr/local/cpanel/etc/init/startmailman
./cpanel:    action "Stopping tailwatchd: " /usr/local/cpanel/libexec/tailwatchd --stop
./cpanel:    action "Stopping cPanel services: " /usr/local/cpanel/etc/init/stopcpsrvd
./cpanel:       action "Stopping cPanel dav services: " /usr/local/cpanel/etc/init/stopcpdavd
./cpanel:       action "Stopping cPanel queue services: " /usr/local/cpanel/etc/init/stopqueueprocd
./cpanel:       action "Stopping cPanel brute force detector services: " /usr/local/cpanel/etc/init/stopcphulkd
./cpanel:               action "Stopping pop3 services: " /usr/local/cpanel/etc/init/stopcppop
./cpanel:       echo -n "Stopping cPanel log services: "
./cpanel:       killproc cpanellogd
./cpanel:       echo -n "Stopping cPanel Chat services: "
./cpanel:       action "Stopping cPanel ssl services: " /usr/local/cpanel/etc/init/stopstunnel
./cpanel:       action "Stopping mailman services: " /usr/local/cpanel/etc/init/stopmailman
./cpanel:       if [ -e "/usr/local/cpanel/3rdparty/mailman/bin/mailmanctl" ]; then
./exim:if [ -e "/etc/chkserv.d" ]; then
./exim:        for file in `ls /etc/chkserv.d`
./exim:            if [ ! -e "/usr/local/cpanel/libexec/tailwatchd" ]; then
./exim:    if [ -x "/usr/local/cpanel/etc/init/startspamd" ]; then
./exim:        /usr/local/cpanel/etc/init/startspamd
./exim:        if [ ! -e "/usr/local/cpanel/libexec/tailwatchd" ]; then
./ror:  /usr/local/cpanel/bin/rormgr --startboot
./ror:  /usr/local/cpanel/bin/rormgr --stopall
./ror:  /usr/local/cpanel/bin/rormgr --stopall
./ror:  /usr/local/cpanel/bin/rormgr --startboot
./ror:  /usr/local/cpanel/bin/rormgr --statusall
./securetmp:# Author:       cPanel, Inc. &lt;copyright@cpanel.net&gt;</pre>

<h3>Turn off cpanel services</h3>
<p>You should remove the below delete command and start by just disabling the inits by turning them off.  Then reboot. Then delete.  If your machine won't reboot, I told you so, Cpanel told you so, and likely your host told you so.</p>
<pre>for S in cpanel ror securetmp fastmail exim; do R=$(command chkconfig --level 123456 $S off ||echo); R=$(command chkconfig --del $S ||echo); done</pre>


<h4>HTTPD</h4>
<p>If you are running chrooted httpd then you'll need to make sure you don't delete your entire webserver on accident.  Here's a relevant part from the /etc/init.d/httpd script.</p>
<pre># the path to your httpd binary, including options if necessary
if [ -e "/etc/chroothttpd" ]; then
        HTTPD=/usr/local/cpanel/bin/chroothttpd
else
        HTTPD=/usr/local/apache/bin/httpd
fi</pre>




<h2>Finding files owned by cpanel</h2>
<p>Some super cool bash commands in this post.. let's start with one to find all the files and folders on your machine owned by cpanel.  Check your /etc/passwd file for your machines specific usernames and groups.  This command saves all the filenames to ~/cpanel-files-backup.txt, which is used by tar next to create a backup of all of them.</p>
<pre>{ find / -mount -depth -maxdepth 150 \( -group cpanel -o   -group cpanel-phpmyadmin -o -group cpanel-phppgadmin   -o -group cpanelphpmyadmin   -o -group cpanelphppgadmin   -o -group cpanelhorde   -o -group cpanelroundcube \) -print; find / -mount -depth -maxdepth 150 \( -user cpanel -o   -user cpanel-phpmyadmin -o -user cpanel-phppgadmin   -o -user cpanelphpmyadmin   -o -user cpanelphppgadmin   -o -user cpanelhorde   -o -user cpanelroundcube \) -print; } &gt; ~/cpanel-files-backup.txt</pre>

<p>Here's another way to search directories.</p>
<pre> grep --color=always -Hir cpanel /var</pre>

<h2>Create the Backup</h2>
<p>Note that you must have the latest version of tar for this exact command, also you should backup /var/cpanel and /usr/local/cpanel and /etc and heck the whole machine why dontcha!</p>
<pre>tar -T ~/cpanel-files-backup.txt -cvz --checkpoint=1000 --checkpoint-action="ttyout=\rHit %s checkpoint #%u" -f /cpanel-files-backup.tgz --totals</pre>


<h2>Remove Files</h2>
<p>Once you do this your upstream without a paddle, you better make sure you know what you're doing with this.  This removes all those files.</p>
<pre>cat ~/cpanel-files-backup.txt | xargs -I&#039;F87&#039; rm -vfr F87</pre>

<p>Additionally you will want to remove /usr/local/cpanel and /var/cpanel - What I always do when running as root is alias my rm command to instead simply move the files to a .trash folder.  That way if something goes bork you have a better chance at fixing it.</p>


<h2>Find Group-Owned Files</h2>
<pre>find / -mount -depth -maxdepth 150 \
\(  -group cpanel -o \
  -group cpanel-phpmyadmin \
  -o -group cpanel-phppgadmin \
  -o -group cpanelphpmyadmin \
  -o -group cpanelphppgadmin \
  -o -group mailman \
  -o -group cpanelhorde \
  -o -group cpanelroundcube \
\) -fprintf /root/cpanel-group-files.log &#039;%#8k %#5m %11M %#10u:%-10g %-5U:%-5G %p %f %Y %F\n&#039;</pre>

<h2>Find User-Owned Files</h2>
<pre>find / -mount -depth -maxdepth 150 \(
  -user cpanel \
  -o -user cpanel-phpmyadmin \
  -o -user cpanel-phppgadmin \
  -o -user cpanelphpmyadmin \
  -o -user cpanelphppgadmin \
  -o -user mailman \
  -o -user cpanelhorde \
  -o -user cpanelroundcube
\) -fprintf /root/cpanel-users-files.log &#039;%#8k %#5m %11M %#10u:%-10g %-5U:%-5G %p %f %Y %F\n&#039;</pre>



<pre>       4  0755  drwxr-xr-x     cpanel:cpanel     32002:32004 /var/cpanel/userhomes/cpanel cpanel d reiserfs
       4  0700  drwx------ cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin/tmp tmp d reiserfs
       4  0644  -rw-r--r-- cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin/.cpanel/caches/featurelists/default.cache default.cache f reiserfs
       4  0700  drwx------ cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin/.cpanel/caches/featurelists featurelists d reiserfs
       4  0700  drwx------ cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin/.cpanel/caches caches d reiserfs
       4  0700  drwx------ cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin/.cpanel .cpanel d reiserfs
       4  0750  drwxr-x--- cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin/mail mail d reiserfs
       4  0711  drwx--x--x cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin cpanel-phpmyadmin d reiserfs
       4  0700  drwx------ cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin/sessions sessions d reiserfs
       4  0644  -rw-r--r-- cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin/.cpanel/caches/featurelists/default.cache default.cache f reiserfs
       4  0700  drwx------ cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin/.cpanel/caches/featurelists featurelists d reiserfs
       4  0700  drwx------ cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin/.cpanel/caches caches d reiserfs
       4  0700  drwx------ cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin/.cpanel .cpanel d reiserfs
       4  0750  drwxr-x--- cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin/mail mail d reiserfs
       4  0711  drwx--x--x cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin cpanelphppgadmin d reiserfs
       4  0750  drwxr-x--- cpanelroundcube:cpanelroundcube 514  :514   /var/cpanel/userhomes/cpanelroundcube/mail mail d reiserfs
       4  0700  drwx------ cpanelroundcube:cpanelroundcube 514  :514   /var/cpanel/userhomes/cpanelroundcube/sessions sessions d reiserfs
       4  0711  drwx--x--x cpanelroundcube:cpanelroundcube 514  :514   /var/cpanel/userhomes/cpanelroundcube cpanelroundcube d reiserfs
       4  0644  -rw-r--r--     cpanel:cpanel     32002:32004 /var/cpanel/.cpanel/caches/featurelists/default.cache default.cache f reiserfs
       4  0700  drwx------     cpanel:cpanel     32002:32004 /var/cpanel/.cpanel/caches/featurelists featurelists d reiserfs
       4  0700  drwx------     cpanel:cpanel     32002:32004 /var/cpanel/.cpanel/caches caches d reiserfs
       4  0700  drwx------     cpanel:cpanel     32002:32004 /var/cpanel/.cpanel .cpanel d reiserfs
       4  0700  drwx------ cpanelroundcube:cpanelroundcube 514  :514   /var/cpanel/roundcube/tmp tmp d reiserfs
       4  0700  drwx------ cpanelroundcube:cpanelroundcube 514  :514   /var/cpanel/roundcube/log log d reiserfs</pre>


<h3>Find Permissions</h3>
<pre>cat ~/cpanel-group-files.log ~/cpanel-users-files.log |tr -s &#039;\000 \t&#039;|cut -d&#039; &#039; -f3|sort -u</pre>






<h3>Find files tailwatchd</h3>
<pre>(1:3732)# $NICE find ${1:-`pwd`} -mount -name &#039;*tailwatch*&#039;
/usr/local/cpanel/libexec/tailwatchd
/usr/local/cpanel/libexec/tailwatch
/usr/local/cpanel/libexec/tailwatch/tailwatchd
/usr/local/cpanel/etc/init/scripts/freebsd/tailwatchd.sh
/usr/local/cpanel/etc/init/scripts/trustix/tailwatchd
/usr/local/cpanel/etc/init/scripts/centos/tailwatchd
/usr/local/cpanel/etc/init/scripts/suse/tailwatchd
/usr/local/cpanel/etc/init/scripts/caos/tailwatchd
/usr/local/cpanel/etc/init/scripts/whitebox/tailwatchd
/usr/local/cpanel/etc/init/scripts/mandrake/tailwatchd
/usr/local/cpanel/etc/init/scripts/debian/tailwatchd
/usr/local/cpanel/etc/init/scripts/redhat/tailwatchd
/usr/local/cpanel/etc/init/scripts/fedora/tailwatchd
/usr/local/cpanel/etc/init/stoptailwatchd
/usr/local/cpanel/etc/init/starttailwatchd
/usr/local/cpanel/bin/tailwatchd
/usr/local/cpanel/logs/tailwatchd_log
/var/log/cpanel/tailwatchd_log
/var/cpanel/log_rotation/cp_tailwatchd_log.cpanellogd
/var/cpanel/tailwatch.positions
/var/run/tailwatchd.pid
/etc/chkserv.d/tailwatchd
/scripts/restartsrv_tailwatchd</pre>


<h2>Delete cpanel Users/Groups</h2>
<pre>for U in cpanel-phpmyadmin cpanel-phppgadmin cpanelphpmyadmin cpanelphppgadmin cpanelhorde cpanelroundcube machbuild; do userdel -fr $U; groupdel $U; done</pre>

<h2>Check for broken symlinks</h2>
<pre>find / -mount -depth -type l -print0 |xargs -0 -P0 -I&#039;F87&#039; file -s &#039;F87&#039; | sed -n &#039;/: broken symbolic link to/p&#039;</pre>
<p>Especially check /etc</p>
<pre>$ find /etc -mount -depth -type l -print0 |xargs -0 -P0 -I&#039;F87&#039; file -s &#039;F87&#039; | sed -n &#039;/: broken symbolic link to/p&#039;
/etc/ftpd-rsa.pem                   broken symbolic link to `/var/cpanel/ssl/ftp/ftpd-rsa.pem&#039;
/etc/rc.d/rc1.d/K10chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc1.d/K30antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc1.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/rc.d/rc3.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/rc.d/rc3.d/S80chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc3.d/S80antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc6.d/K10chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc6.d/K30antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc6.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/rc.d/rc5.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/rc.d/rc5.d/S80chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc5.d/S80antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc2.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/rc.d/rc2.d/S80chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc2.d/S80antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc4.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/rc.d/rc4.d/S80chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc4.d/S80antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc0.d/K10chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc0.d/K30antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc0.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/authlib/authProg               broken symbolic link to `/usr/local/cpanel/bin/courier-auth&#039;</pre>

<p>And delete if you are sure</p>
<pre>find /etc -mount -depth -type l -print0 |xargs -0 -P0 -I&#039;F87&#039; file -s &#039;F87&#039; | sed -n &#039;/: broken symbolic link to/p&#039; |cut -d&#039; &#039; -f1|xargs -I&#039;F87&#039; rm -rvf &#039;F87&#039;</pre>


<h2>Reinstall CSF</h2>
<p>The only thing I actually used that came with cpanel is the CSF/LFD Firewall package, which is a fantastic piece of software.  I had to reinstall this, and to get it working without cpanel add the following line to the csf.conf</p>
<pre>GENERIC = "1"</pre>

<h2>Thats It</h2>
<p>Now once you've cleaned up everything, you should try everything conceivable to get an error before rebooting.  Like you should start and stop every service in /etc/init.d/, you should use telinit to check various runlevels (which keeps your sshd connection still live).  Go all out, should take at least a full hour.</p>
<p>Another thing I like to do is rebuild alot of my source-built software again in case anything got messed up.  I upgrade perl from cpanels 5.8.8 to 5.10, which is pretty thorough, and you know, reinstall anything else I think I might need.  One of the benefits of compiling your own software is all I have to do is cd to the source directory and type <code>make -B &amp;&amp; ( { make test || make check || make checks || make tests; } || echo  ) &amp;&amp; sudo make install</code> and that's it.  The tests/checks are optional of course.</p>


<p>If anyone actually ever reads this and does it, please share your advice here.. everybody knows we need it!  Good Luck</p><p><a href="http://www.askapache.com/hacking/uninstall-cpanel.html"></a><a href="http://www.askapache.com/hacking/uninstall-cpanel.html">HOWTO: Uninstall CPANEL over SSH</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/hacking/uninstall-cpanel.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Advanced Linux Debugging using a Bootloader (GRUB)</title>
		<link>http://www.askapache.com/linux/advanced-linux-grub.html</link>
		<comments>http://www.askapache.com/linux/advanced-linux-grub.html#comments</comments>
		<pubDate>Thu, 07 Apr 2011 16:35:41 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4846</guid>
		<description><![CDATA[<p>As an example, here is the boot line that I am using at the moment on an older Dell Desktop, just to illustrate module parameters and environment vars.  </p>
<pre>title  Arch Linux X-256
kernel /vmlinuz26 root=/dev/disk/by-label/ROOT ro rootwait pause_on_oops=5 panic=60 i915.modeset=1 no_console_suspend ipv6.disable=1 TERM=xterm-256color quiet 5
initrd /kernel26.img</pre>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/linux/advanced-linux-grub.html"></a><a href="http://www.askapache.com/linux/advanced-linux-grub.html"><cite>AskApache.com</cite></a></p><p>This is part of the <a href="https://wiki.archlinux.org/index.php/GRUB">GRUB article on the Arch Linux wiki that I contributed</a>.   As of now, just a copy.</p>

<p>The grub <code>menu.lst</code> provides for a convenient way to add a number of entries with <a href="http://www.kernel.org/doc/Documentation/kernel-parameters.txt" class="external text" rel="nofollow">extended kernel parameters</a> to configure all sorts of advanced settings to enable you to quickly and conveniently boot into your existing system with varying levels of debugging output.  It's very easy and useful to create several levels of debugging just by adding additional entries to your grub configuration. And if you ever have issues or problems down the road due to a power-failure or hardware failure, it can save you hours of trouble, and of course nothing can beat debugging output when it comes to learning about your system.</p>

<h2><span class="mw-headline" id="Useful_Menu.lst_Entries">Useful Menu.lst Entries</span></h2>
<p>If you are interested in debugging, then you deserve some grub entries for powerusers, here are a few that I like (just add to your <code>menu.lst</code>).</p>

<pre>title Shutdown the Computer
halt
&nbsp;
title Reboot the Computer
reboot
&nbsp;
title Command Line
commandline
&nbsp;
title Install GRUB to hd0 MBR
root (hd0,0)
setup (hd0)
&nbsp;
title Matrix
color green/black light-green/green
&nbsp;
title Scan for /boot/grub/menu.lst
find --set-root --ignore-floppies /boot/grub/menu.lst
configfile /boot/grub/menu.lst
&nbsp;
title Scan for /boot/menu.lst
find --set-root --ignore-floppies /menu.lst
configfile /boot/menu.lst
&nbsp;
# http://www.vortex.prodigynet.co.uk/x86test/
title    Run x86test (CPU Info)
kernel /boot/x86test_zImage.bin
#wget http://www.vortex.prodigynet.co.uk/x86test/x86test_zImage.bin
&nbsp;
# http://www.memtest.org/
title    Run memtest86+ (Memory Testing)
kernel /boot/memtest86+-1.70.bin</pre>

<h2> <span class="mw-headline" id="Light_Debug">Light Debug</span></h2>
<p>A quick way to see more verbose messages on your console is to bootup your normal grub entry after appending <strong>verbose</strong> to the kernel line.  This simple word added to your kernel line turns on more logging thanks to the <code>/etc/rc.sysinit</code> file, which at the top of the file runs:</p>
<pre>if /bin/grep -q " verbose" /proc/cmdline; then /bin/dmesg -n 8; fi</pre>
<p>Very simple way to get a bit more messages and debug output in your logs.</p>
<pre>title  Arch Linux DEBUG Light
kernel /vmlinuz26 root=/dev/disk/by-label/ROOT ro rootwait verbose
initrd /kernel26.img</pre>

<h2> <span class="mw-headline" id="Medium_Debug">Medium Debug</span></h2>
<p>This example <code>menu.lst</code> entry turns on real logging that is set by the kernel and not in an init script.  Adding the <strong>debug</strong> kernel parameter to your kernel line is recognized by a lot of linux internals and enables quite a bit of debugging compared to the default. </p>

<pre>title Arch Linux DEBUG Medium
kernel /vmlinuz26 root=/dev/disk/by-label/ROOT ro rootdelay=5 panic=10 debug
initrd /kernel26.img</pre>

<h2> <span class="mw-headline" id="Heavy_Debug">Heavy Debug</span></h2>
<p>An even more impressive kernel parameter is the <strong>ignore_loglevel</strong>, which causes the system to ignore any loglevel and keeps the internal loglevel at the maximum debugging level, basically rendering dmesg unable to lower the debug level.</p>
<pre>title Arch Linux DEBUG Heavy
kernel /vmlinuz26 root=/dev/disk/by-label/ROOT ro rootdelay=5 panic=10 debug ignore_loglevel
initrd /kernel26.img</pre>

<h2> <span class="mw-headline" id="Extreme_Debug">Extreme Debug</span></h2>
<p>If the "Heavy Debug" seemed like a lot of output, thats about 1/2 of the logging that occurs with this example.  This does a couple things, it uses the <strong>earlyprintk</strong> parameter to setup your kernel for "early" "printing" of messages to your "vga" screen.  The <strong>,keep</strong> just lets it stay on the screen longer.  This will let you see logs that normally are hidden due to the boot-up process.
This also changes the log buffer length to 10MB, and also instructs that any fatal signals be printed with <strong>print_fatal_signals</strong>.  The last one, <strong>sched_debug</strong>, you can look up in the very excellent kernel documentation on <a href="http://www.kernel.org/doc/Documentation/kernel-parameters.txt" class="external text" rel="nofollow">kernel parameters</a>.</p>

<pre>title Arch Linux DEBUG Extreme
kernel /vmlinuz26 root=/dev/disk/by-label/ROOT ro debug ignore_loglevel log_buf_len=10M print_fatal_signals=1 LOGLEVEL=8 earlyprintk=vga,keep sched_debug
initrd /kernel26.img</pre>

<h2> <span class="mw-headline" id="Insane_Debug">Insane Debug</span></h2>
<p>The first few debugging examples showed some really nice kernel parameters to turn on really verbose debugging.  This kind of debugging is absolutely critical if you want to max out your system or just learn more about what is going on behind the scenes.  But there is a final trick that is my favorite, it's the ability to set both environment variables, and more importantly, module parameters at boot.</p>

<p>As an example, here is the boot line that I am using at the moment on an older Dell Desktop, just to illustrate module parameters and environment vars.  </p>
<pre>title  Arch Linux X-256
kernel /vmlinuz26 root=/dev/disk/by-label/ROOT ro rootwait pause_on_oops=5 panic=60 i915.modeset=1 no_console_suspend ipv6.disable=1 TERM=xterm-256color quiet 5
initrd /kernel26.img</pre>
<p>Since it's low on both memory and CPU, I disable ipv6. I also turn on kernel modesetting for the i915 video card, set my terminal to be xterm-256color, and boot straight into <a href="https://wiki.archlinux.org/index.php/Xorg" title="Xorg">X</a>.  This lets me use a very optimized arch-linux configuration, amazing how fast thanks to using <a href="https://wiki.archlinux.org/index.php/SLiM" title="SLiM">slim</a> as the login manager, <a href="https://wiki.archlinux.org/index.php/Ratpoison" title="Ratpoison">ratpoison</a> as my <a href="https://wiki.archlinux.org/index.php/Display_Manager" title="Display Manager">window manager</a>, and terminal with <a href="https://wiki.archlinux.org/index.php/Tmux" title="Tmux">tmux</a> as my login shell, all from boot, as the pstree shows (plus <a href="https://wiki.archlinux.org/index.php/Synergy" title="Synergy">Synergy</a>!).</p>
<pre>init,1
  |-slim,3096
  |   |-X,3098 -nolisten tcp vt07 -auth /var/run/slim.auth
  |   `-ratpoison,3107,askapache
  |       |-terminal,5341 -x sh -c exec /usr/bin/tmux -2 -l -u -q attach -d -t tmux-askapache
  |       |   |-bash,11165
  |       |   |-tmux,5345 -2 -l -u -q attach -d -t tmux-askapache
  |       |   `-{terminal},5346
  |       `-xscreensaver,3113 -no-splash
  |-synergyc,6121,galileo -f --name galileo-fire --restart 10.66.66.2:26666
  |
  `-tmux,5348,askapache -2 -l -u -q attach -d -t tmux-askapache
      |-bash,5351
      |   `-ssh,9969 lug@askapache.com
      `-bash,5868
         `-vim,11149 -p sda1/grub/menu.lst /boot/grub/menu.lst</pre>
<p>That kind of optimized system is only possible if you first can figure out your system, by debugging both the kernel as previously illustrated, debugging the init process, and most importantly, by debugging the modules enabled for your system's hardware/firmware/software.  Debugging modules is challenging but worth the effort, and then you are able to do some truly insane debugging from grub like the following example, note that the actual grub entry is all on one line, but I split it into 4 lines so you could see it all.  This basically turns on every module on this little Dell desktop to be at the absolute max debug level.  There is so much logging when I boot this that the system grinds to a halt and is slower than a TI-89 calculator (See <a href="https://wiki.archlinux.org/index.php/Improve_Boot_Performance" title="Improve Boot Performance">Improve Boot Performance</a>).</p>
<pre>title  Arch Linux DEBUG INSANE
kernel /vmlinuz26 root=/dev/disk/by-label/ROOT ro rootwait ignore_loglevel debug debug_locks_verbose=1 sched_debug initcall_debug mminit_loglevel=4 udev.log_priority=8
       loglevel=8 earlyprintk=vga,keep log_buf_len=10M print_fatal_signals=1 apm.debug=Y i8042.debug=Y drm.debug=1 scsi_logging_level=1 usbserial.debug=Y
       option.debug=Y pl2303.debug=Y firewire_ohci.debug=1 hid.debug=1 pci_hotplug.debug=Y pci_hotplug.debug_acpi=Y shpchp.shpchp_debug=Y apic=debug
       show_lapic=all hpet=verbose lmb=debug pause_on_oops=5 panic=10 sysrq_always_enabled
initrd /kernel26.img</pre>
<p>A couple key items from that grub entry are <strong>sysrq_always_enabled</strong> which forces on the sysrq magic, which really is a lifesaver when debugging at this level as your machine will freeze/stop-responding sometimes and it's nice to use sysrq to kill all tasks, change the loglevel, unmount all filesystems, or do a hard reboot.  Another key parameter is the <strong>initcall_debug</strong>, which debugs the init process in excruciating detail.  Very useful at times.  The last parametery I find very useful is the <strong>udev.log_priority=8</strong> to turn on <a href="https://wiki.archlinux.org/index.php/Udev" title="Udev">udev</a> logging.  </p>


<h2><span class="mw-headline" id="Break_Into_Init">Break Into Init</span></h2>
<p>For instance, If you add <strong>break=y</strong> to your kernel cmdline, init will pause early in the <a href="https://wiki.archlinux.org/index.php/Arch_Boot_Process" title="Arch Boot Process">boot process</a> (after loading modules) and launch an interactive sh shell which can be used for troubleshooting purposes. (Normal boot continues after logout.)  This is very similar to the shell that shows up if your computer gets turned off before it is able to shutdown properly.  But using this parameter lets you enter into this mode differently at will.</p>
<pre>title  Arch Linux Init Break
kernel /vmlinuz26 root=/dev/disk/by-label/ROOT ro rootwait break=y
initrd /kernel26.img</pre>

<h2><span class="mw-headline" id="Debugging_init">Debugging init</span></h2>

<p>This awesome parameter <strong>udev.log_priority=8</strong> does the same thing as editing the file <code>/etc/udev/udev.conf</code> except it executes earlier, turning on debugging output for <a href="https://wiki.archlinux.org/index.php/Udev" title="Udev">udev</a>.  If you want to know your hardware, that is the key parameter right there.  Another trick is if you change the <code>/etc/udev/udev.conf</code> to be verbose, then you can make your initrd image include that file to turn on verbose udeb debugging by adding it to your {{Filename|/etc/mkinitcpio.conf} like:</p>
<pre>FILES="/etc/modprobe.d/modprobe.conf /etc/udev/udev.conf"</pre>
<p>, which on arch is as easy as </p>
<pre># mkinitcpio -p kernel26</pre>
<p>Debugging <a href="https://wiki.archlinux.org/index.php/Udev" title="Udev">udev</a> is key because the <a href="https://wiki.archlinux.org/index.php/Initrd" title="Initrd">initrd</a> performs a <a href="https://wiki.archlinux.org/index.php/Change_Root" title="Change Root">root change</a> at the end of its run to usually launch a program like /sbin/init as part of a chroot, and unless the new file system has a valid /dev directory, udev must be initialized before invoking chroot in order to provide <code>/dev/console</code>.  </p>
<pre>exec chroot . /sbin/init &lt;dev/console &gt;dev/console 2&gt;&amp;1</pre>
<p>So basically, you aren't able to view the logs that are generated before /dev/console is initialized by udev or by a special initrd you compiled yourself.  One method the kernel developers use to be able to still get the log messages generated before /dev/console is available is to provide an alternative console that you can enable or disable from grub.</p>



<h2><span class="mw-headline" id="Net_Console">Net Console</span></h2>
<p>If you read through the kernel documentation regarding debugging, you will hear about Netconsole, which can be loaded from the kernel line in GRUB, compiled into your kernel, or loaded at runtime as a module.  Having a netconsole entry in your <code>menu.lst</code> is most excellent for debugging slower computers like old laptops or thin-clients.  It's easy to use.  Just setup a 2nd computer (running arch) to accept syslog requests on a remote port, very fast and quick to do on arch-linux, 1 line to syslog.conf.  Then you could use a log-color-parser like ccze to view all syslog logs, or just tail your everything.log. Then on your laptop, boot up and select the netconsole entry from the grub menu, and you will start seeing as much logging as you want on your syslog system.  This logging lets you view even earlier log output than is available with the earlyprintk=vga kernel parameter, as netconsole is used by kernel hackers and developers, so it's very powerful.</p>
<pre>title  Arch Linux DEBUG Netconsole
kernel /vmlinuz26 root=/dev/disk/by-label/ROOT ro netconsole=514@10.0.0.2/12:34:56:78:9a:bc debug ignore_loglevel
initrd /kernel26.img</pre>

<h2><span class="mw-headline" id="Hijacking_cmdline">Hijacking cmdline</span></h2>
<p>If you do not have access to GRUB or the kernel boottime cmdline, like on a server or virtual machine, as long as you have root permissions you can still enable this kind of simplistic verbose logging using a neat hack.  While you cannot modify the <code>/proc/cmdline</code> even as root, you can place your own cmdline file on top of /proc/cmdline, so that accessing /proc/cmdline actually accesses your file.</p>
<p>For example if I <strong>cat /proc/cmdline</strong>, I have the following:</p>
<pre>root=/dev/disk/by-label/ROOT ro console=tty1 logo.nologo quiet</pre>
<p>So I use a simple sed command to replace <strong>quiet</strong> with <strong>verbose</strong> like:</p>
<pre>sed &#039;s/ quiet/ verbose/&#039; /proc/cmdline &gt; /root/cmdline</pre>
<p>Then I bind mount /root/cmdline so that it becomes /proc/cmdline, using the <strong>-n</strong> option to mount so that this mount won't be recorded in the systems mtab.</p>
<pre>mount -n --bind -o ro /root/cmdline /proc/cmdline</pre>
<p>Now if I <strong>cat /proc/cmdline</strong>, I have the following:</p>
<pre>root=/dev/disk/by-label/ROOT ro console=tty1 logo.nologo verbose</pre><p><a href="http://www.askapache.com/linux/advanced-linux-grub.html"></a><a href="http://www.askapache.com/linux/advanced-linux-grub.html">Advanced Linux Debugging using a Bootloader (GRUB)</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/linux/advanced-linux-grub.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AskApache Password Protection 4.7 Update in 2 Weeks</title>
		<link>http://www.askapache.com/wordpress/askapache-passpro-4-7.html</link>
		<comments>http://www.askapache.com/wordpress/askapache-passpro-4-7.html#comments</comments>
		<pubDate>Wed, 10 Nov 2010 02:51:25 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4732</guid>
		<description><![CDATA[<p><a class="IFL" href="http://www.askapache.com/wordpress-plugins/askapache-passpro-4-7-soon.html"><img src="http://uploads.askapache.com/2010/11/debugging-options-71x116.png" alt="AskApache Debug Viewer Options" title="AskApache Debug Viewer Options" width="71" height="116" class="alignnone size-thumbnail wp-image-4739" /></a>I am now about 1 week away from publishing the much-anticipated 4.7 update to the AskApache Password Protection WordPress plugin.  It's an upgrade I've been working on for almost 2 years (off and on)!  I have been using the new version for quite some time now, and have made a lot of improvements to it, and finally I decided enough users have suffered with the old version.  I am very excited for this release, it fixes all known bugs in the older versions, and brings some heavy-duty improvements to all facets of this plugin.. not to mention way better security modules (Lots more COOKIE use) based on code I use with clients.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/wordpress/askapache-passpro-4-7.html"></a><a href="http://www.askapache.com/wordpress/askapache-passpro-4-7.html"><cite>AskApache.com</cite></a></p><p><a class="IFL" href="http://wordpress.org/extend/plugins/askapache-debug-viewer/"><img src="http://uploads.askapache.com/2010/11/debug-viewer-capabilities.png" alt="AskApache Debug Viewer Capabilities" title="AskApache Debug Viewer Capabilities" width="445" height="341" class="alignnone size-full wp-image-4738" /></a>I am now about 1 week away from publishing the much-anticipated 4.7 update to the AskApache Password Protection WordPress plugin.  It's an upgrade I've been working on for almost 2 years (off and on)!  I have been using the new version for quite some time now, and have made a lot of improvements to it, and finally I decided enough users have suffered with the old version.  I am very excited for this release, it fixes all known bugs in the older versions, and brings some heavy-duty improvements to all facets of this plugin.. not to mention way better security modules (Lots more COOKIE use) based on code I use with clients.<br class="C" /></p>

<h2>Plugins for Practice</h2>
<p>I wrote 3 plugins to learn the skills I knew I needed for this plugin to do what I envisioned.  The first was a plugin that displayed all WP's builtin RewriteRules.  The next 2 plugins helped me to learn a great about PHP and WP, so that now my plugins are PHP 4/5 compatible and use PHP classes.  Just like all the other code I am into, I am finally achieving 100% E_STRICT conformance.  PHP isn't tough at all once you learn the syntax.</p>


<h3>AskApache Google 404</h3>
<p><a href="http://wordpress.org/extend/plugins/askapache-google-404/">This is my favorite plugin</a>.  I started developing it in order to learn what I needed to know to continue developing the AskApache PassPro plugin.  It's a super-stable plugin and very fast.  <a href="http://wordpress.org/extend/plugins/askapache-google-404/">Check it out</a> and look at the source code if you want to get a preview of the kind of coding used on the AA PassPro 4.7 code.</p>
<p>I use it on every site I develop.  Part of the error handling code in that plugin (HTTP Error Handling) is used in the passpro release to provide advanced HTTP 1.1 capabilities and help with the pre-setup testing.  Currently it is not working 100% on this site, but the problem is because I use the development version of WP and the latest version breaks wordpress 404 usage (again scribus!).</p>

<h3>AskApache Debug Viewer</h3>
<p>This is my newest plugin that was created for the same reason as the AskApache 404 plugin, to figure out some things for the PassPro plugin.  Mainly, to figure out the best ways to debug php, file permissions, and learn as much as I can to prevent anyone getting locked out of their site with 4.7.<br class="C" /></p>
<p><a  class="IFL" href="http://uploads.askapache.com/2010/11/debugging-options.png"><img src="http://uploads.askapache.com/2010/11/debugging-options-215x350.png" alt="AskApache Debug Viewer Options" title="AskApache Debug Viewer Options" width="215" height="350" class="alignnone size-medium wp-image-4739" /></a>One of the last bits of code I want to add to my 4.7 code, which I have been using for over a year, is super logging capabilities to debug any problems the 4.7 plugin may encounter.  The latest release of the Debug Viewer, version 2.0, really has strong logging capabilities, and debugging capabilities.  Of course I try to push those capabilities to the max and beyond.  Currently the usability isn't the greatest, but if you are interested in debugging it is a goldmine of simple, fast, powerful debugging functions.<br class="C" /></p>

<h2>Everyone Who had Trouble</h2>
<p>To those thousands who inadvertantly locked themselves out of their sites with the PassPro plugin, or even worse shut-down ther sites temporarily, I bet that even though it was annoying, or worse than annoying, you came out of it knowing more about your server, your hosting environment, and it showed you a glimpse of the problems malware face when attempting to crack into a blog protected correctly.</p>
<p>Although part of me knows that there is no better way to learn how to secure your site than dealing with getting locked out yourself, I went all out with making sure this version won't lock you out.  Similar to the wordpress plugin bootstrap installation, this version creates a test and verifies it works in a test directory before going live.  The new version has the most advanced Apache Version and Apache Module Detection every published online, well not yet..  And if you don't have apache, lighthttpd, or a similar server that supports htaccess, I'm adding a pure-php auth so you can at least still have password protection.. but you can bet I will stronly advise such a user to upgrade their hosting to a <a href="http://www.wiredtree.com/298.html">Linux+Apache host with skill</a>.</p>

<h2>Back to work</h2>
<p>I've been extremely swamped at work the past 8 months working on a big project, so I only have days here and there to work on it.  I know that I am free either Thursday or Fri this week, so I will have a good shot at getting a BETA release out 4.7.0 one of those days or sometime next week.  If you have any ideas for the plugin, nows the time to let me know about it.. If you are a php master (I am not) and would like to help over the next 2 weeks, please email me.</p><p><a href="http://www.askapache.com/wordpress/askapache-passpro-4-7.html"></a><a href="http://www.askapache.com/wordpress/askapache-passpro-4-7.html">AskApache Password Protection 4.7 Update in 2 Weeks</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/wordpress/askapache-passpro-4-7.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ultimate Htaccess Part II</title>
		<link>http://www.askapache.com/htaccess/apache-htaccess-2.html</link>
		<comments>http://www.askapache.com/htaccess/apache-htaccess-2.html#comments</comments>
		<pubDate>Sat, 16 Oct 2010 16:11:33 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Htaccess]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4693</guid>
		<description><![CDATA[<p><a href="http://www.askapache.com/htaccess/apache-htaccess-2.html"><img src="http://uploads.askapache.com/2010/10/htaccess-editing-350x243.png" alt="Editing an Apache .htaccess file in VIM." title="htaccess editing" width="350" height="243" class="size-medium wp-image-4700" /></a>  Here is even more information from the <a href="http://www.askapache.com/htaccess/htaccess.html">Ultimate Htaccess Part I</a>.  For now this is very rough and you will want to come back later to read it.</p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/htaccess/apache-htaccess-2.html"></a><a href="http://www.askapache.com/htaccess/apache-htaccess-2.html"><cite>AskApache.com</cite></a></p><p><a class="IFL" href="http://www.askapache.com/htaccess/apache-htaccess-2.html"><img src="http://uploads.askapache.com/2010/10/htaccess-editing-350x243.png" alt="Editing an Apache .htaccess file in VIM." title="htaccess editing" width="350" height="243" class="size-medium wp-image-4700" /></a>  Here is even more information from the <a href="http://www.askapache.com/htaccess/htaccess.html">Ultimate Htaccess Part I</a>.  For now this is very rough and you will want to come back later to read it.</p>



<p><a id="htaccess-merging-order"></a></p><h3>Merging Notes</h3>
<p>The order of merging is:</p>
<ol>
<li><code>&lt;Directory&gt;</code> (except regular expressions) and .htaccess done simultaneously (with .htaccess, if allowed, overriding <code>&lt;Directory&gt;</code>)</li>
<li><code>&lt;DirectoryMatch&gt;</code> (and <code>&lt;Directory ~&gt;</code>)</li>
<li><code>&lt;Files&gt;</code> and <code>&lt;FilesMatch&gt;</code> done simultaneously</li>
<li><code>&lt;Location&gt;</code> and <code>&lt;LocationMatch&gt;</code> done simultaneously</li>
</ol>
<p>Below is an artificial example to show the order of merging. Assuming they all apply to the request, the directives in this example will be applied in the order:</p>
<p><code>A &gt; B &gt; C &gt; D &gt; E</code></p>.
<pre>&lt;Location /&gt;
E
&lt;/Location&gt;
&lt;Files askapache.txt&gt;
D
&lt;/Files&gt;
&lt;VirtualHost *&gt;
&lt;Directory /a/b&gt;
B
&lt;/Directory&gt;
&lt;/VirtualHost&gt;
&lt;DirectoryMatch "^.*b$"&gt;
C
&lt;/DirectoryMatch&gt;
&lt;Directory /a/b&gt;
A
&lt;/Directory&gt;</pre>







<p><a id="htaccess-software"></a></p><h2>Htaccess Software</h2>
<p>Apache HTTP Server comes with the following <a href="http://httpd.apache.org/docs/trunk/programs/">programs</a>.</p>
<dl><dt><code>httpd</code></dt><dd>Apache hypertext transfer protocol server</dd><dt><code>apachectl</code></dt><dd>Apache HTTP server control interface</dd><dt><code>ab</code></dt><dd>Apache HTTP server benchmarking tool</dd><dt><code>apxs</code></dt><dd>APache eXtenSion tool</dd><dt><code>dbmmanage</code></dt><dd>Create and update user authentication files in DBM format for basic authentication</dd><dt><code>fcgistarter</code></dt><dd>Start a FastCGI program</dd><dt><code>htcacheclean</code></dt><dd>Clean up the disk cache</dd><dt><code>htdigest</code></dt><dd>Create and update user authentication files for digest authentication</dd><dt><code>htdbm</code></dt><dd>Manipulate DBM password databases.</dd><dt><code>htpasswd</code></dt><dd>Create and update user authentication files for basic authentication</dd><dt><code>httxt2dbm</code></dt><dd>Create dbm files for use with RewriteMap</dd><dt><code>logresolve</code></dt><dd>Resolve hostnames for IP-addresses in Apache logfiles</dd><dt>log_server_status</dt><dd>Periodically log the server's status</dd><dt><code>rotatelogs</code></dt><dd>Rotate Apache logs without having to kill the server</dd><dt>split-logfile</dt><dd>Split a multi-vhost logfile into per-host logfiles</dd><dt><code>suexec</code></dt><dd>Switch User For Exec</dd></dl>


<pre>Options All
AuthType "Basic"
AuthName "Protected Access"
&nbsp;
#SetEnv APPLICATION_ENV production
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
&nbsp;
ErrorDocument 404 /index.php
&nbsp;
AddType text/html url
&nbsp;
order allow,deny
allow from all
Options +ExecCGI
&nbsp;
AddHandler python-program .py
PythonHandler mod_python.publisher
PythonDebug On
PythonAutoReload On
&nbsp;
RewriteEngine on
RewriteRule .* - [E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}]
RewriteRule .* - [E=HTTP_IF_NONE_MATCH:%{HTTP:If-None-Match}]
&nbsp;
# updating tab.ser takes lots of memory
php_value memory_limit 64000000
&nbsp;
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
&nbsp;
php_flag magic_quotes_gpc Off
php_flag magic_quotes_runtime Off
&nbsp;
# redirect moved files
RedirectMatch Permanent ^/fop/anttask(.*) http://xmlgraphics.apache.org/fop/0.20.5/anttask$1
RedirectMatch Permanent ^/fop/compiling(.*) http://xmlgraphics.apache.org/fop/0.20.5/compiling$1
RedirectMatch Permanent ^/fop/configuration(.*) http://xmlgraphics.apache.org/fop/0.20.5/configuration$1
RedirectMatch Permanent ^/fop/embedding(.*) http://xmlgraphics.apache.org/fop/0.20.5/embedding$1
&nbsp;
&lt;IfModule mod_expires.c&gt;
ExpiresActive On
ExpiresDefault "access plus 52 weeks"
&lt;/IfModule&gt;
&nbsp;
# $Id: .htaccess 1255 2003-12-21 05:30:57Z rufustfirefly $
# $Author: rufustfirefly $
#
# Since sometimes Apache isn&#039;t properly configured to view the
# proper PHP script, we do this instead, but only if PHP4 is
&nbsp;
&lt;IfModule mod_access.c&gt;
&lt;Files ~ "^wanewsletter"&gt;
Order Allow,Deny
Allow from 127.0.0.1
RewriteEngine On
# map phocoa framework wwwroot - enabled PHOCOA Versioning
RewriteRule ^/www/framework(/[0-9\.]*)?/?(.*) /wwwroot/www/framework/$2 [L]
#enable a normal wwwroot
&nbsp;
RewriteEngine on
RewriteRule Boot/(.*) Boot/$1 [QSA,L]
&nbsp;
RewriteEngine on
RewriteRule ^xbl.js build/xbl.php
RewriteRule ^ie-dom.js build/ie-dom.php
&nbsp;
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
&nbsp;
# Rewrite rules for Zend Framework
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1 [L]
&nbsp;
AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "You are not welcomed here"
AuthType Basic
&lt;Limit GET POST&gt;
&nbsp;
AddHandler application/x-httpd-php-source php
&nbsp;
DirectoryIndex index.html index.php
AddDefaultCharset UTF-8
RewriteEngine off
# Web Optimizer options
&nbsp;
ErrorDocument 404 /~george/blog/index.php
AddType application/x-httpd-php .php .rdf
&nbsp;
# redirect moved files
RedirectMatch Permanent ^/fop/anttask(.*) http://xmlgraphics.apache.org/fop/0.20.5/anttask$1
RedirectMatch Permanent ^/fop/compiling(.*) http://xmlgraphics.apache.org/fop/0.20.5/compiling$1
RedirectMatch Permanent ^/fop/configuration(.*) http://xmlgraphics.apache.org/fop/0.20.5/configuration$1
RedirectMatch Permanent ^/fop/embedding(.*) http://xmlgraphics.apache.org/fop/0.20.5/embedding$1
AddHandler x-httpd-php504 .php
AddType application/x-httpd-php .html
&nbsp;
RewriteEngine on
# Remember to change RewriteBase to where your site really is - for example if
# you access the site by www.somesite.com/~myname/thesite, you do as so:
# RewriteBase /~myname/thesite/
&nbsp;
&lt;Files "config.php"&gt;
Order deny,allow
Deny From All
&lt;/Files&gt;
&nbsp;
#
# Apache/PHP/Drupal settings:
#
# Protect files and directories from prying eyes.
&nbsp;
DirectoryIndex membersite.pl
Options +ExecCGI
AddHandler cgi-script .pl
&nbsp;
#AddType application/x-httpd-php .php3 .phtml .php .php4 .php5 .html .html .xml
Options -Indexes
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
&nbsp;
# Comment/uncomment the lines below depending of your needs
# To deny any access to this directory
Deny from all
&nbsp;
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
&nbsp;
&lt;FilesMatch "\.(php|inc)$"&gt;
Order allow,deny
Deny from all
&lt;/FilesMatch&gt;
&nbsp;
AddHandler application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
AddHandler application/x-httpd-php5 .snow
AddType application/x-httpd-php5 .snow
AddHandler image/jpeg me
Redirect permanent /~hoge/hns-lite/i/ http://www.example.ne.jp/~hoge/hns-lite/
&nbsp;
# Make index.php the default
DirectoryIndex index.php
Options -Indexes
&nbsp;
# In case it&#039;s on, turn off magic quotes:
php_value magic_quotes_gpc off
# On production servers, uncomment these lines and update the path
# to a suitable log file:
&nbsp;
Deny from all
Satisfy All
&nbsp;
##############################
# MicroMVC Apache settings
# .htaccess v1.0.0 9/29/2007
##############################
&nbsp;
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
&nbsp;
&lt;filesmatch \.(thtml|ctp)$=""&gt;
DENY FROM ALL
&lt;/filesmatch&gt;
&nbsp;
RewriteEngine on
#RewriteCond %{REMOTE_HOST} ^yupi-cms*
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
&nbsp;
RewriteEngine On
RewriteBase /
# Rewrite www.domain.com to domain.com
RewriteCond %{HTTP_HOST} ^www\.(.*)
&nbsp;
#
# OntoWiki requires Apache&#039;s rewrite engine to work
#
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine Off
&lt;IfModule mod_rewrite.c&gt;
# Turn on URL rewriting
RewriteEngine On
&nbsp;
RewriteEngine on
# Remember to change RewriteBase to where your site really is - for example if
# you access the site by www.somesite.com/~myname/thesite, you do as so:
# RewriteBase /~myname/thesite/
&nbsp;
# this file is placed here to restrict the access to this directory
# for non authorized users
# Note that the AllowOverride directive (in the Apache&#039;s access.conf) must be
# set to "Limit" or "All"
&nbsp;
# This folder does not require access over HTTP
Order deny,allow
Deny from all
Allow from none
&nbsp;
RewriteEngine on
# Remember to change RewriteBase to where your site really is - for example if
# you access the site by www.somesite.com/~myname/thesite, you do as so:
# RewriteBase /~myname/thesite/
&nbsp;
#
# Latitude .htaccess Rules
# Special thanks to Drupal for a template (http://drupal.org/)
#
&nbsp;
AddHandler php5-script .php
Options +FollowSymLinks +ExecCGI
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
&nbsp;
Options +Indexes
IndexOptions FancyIndexing
IndexOptions +NameWidth=*
IndexOptions +DescriptionWidth=*
&nbsp;
RewriteEngine off
Options -Indexes
&nbsp;
############
# SECURITY #
###########################################################
&lt;files *.php&gt;
Options +Indexes
IndexOptions FancyIndexing
IndexOptions +NameWidth=*
IndexOptions +DescriptionWidth=*
&nbsp;
AddHandler fcgid-script .abc
#update this path according to your setup
#you can place the executable fcgishell anywhere on your server
&nbsp;
AddEncoding x-compress Z
AddEncoding x-gzip gz
&nbsp;
AddHandler cgi-script rb
# Send any page with a slow.html suffix with a delay
AddHandler slow-down .slow
Action slow-down @PATH_PREFIX@/cgi/send-delayed.rb
&nbsp;
DirectoryIndex index.htm
AddHandler server-parsed .htm
&nbsp;
# for current work
&lt;IfModule mod_php5.c&gt;
php_value memory_limit 128M
php_value max_execution_time 150
php_flag magic_quotes_gpc off
&nbsp;
&lt;Files password.xml&gt;
Deny from all
&lt;/Files&gt;
&nbsp;
ErrorDocument 404 /cgi-bin/error.cgi
&nbsp;
deny from all
&lt;Files *.php&gt;
order allow,deny
deny from all
&lt;/Files&gt;
&nbsp;
Options -Indexes
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# General Apache options
AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI
&nbsp;
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule !\.(js|ico|gif|jpg|png|css|txt)$ - [C]
RewriteRule (.*) http://127.0.0.1:8080/$1 [P]
&nbsp;
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
&nbsp;
Order Deny,Allow
Deny from all
#dozwoleni userzy
Allow from localhost
&nbsp;
# deny access to private folders and files, start with prefix "_"
&lt;FilesMatch "(^|/)_"&gt;
deny from all
&lt;/FilesMatch&gt;
# deny access to all executable files (.php)
&nbsp;
php_flag register_globals off
php_flag magic_quotes_gpc off
php_flag short_open_tag off
php_flag allow_call_time_pass_reference off
php_flag safe_mode on
&nbsp;
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine on
RewriteBase /jblog/
RewriteCond %{REQUEST_FILENAME} !-f
&nbsp;
deny from all
Satisfy all
&nbsp;
#
# Apache/PHP/Drupal settings:
#
# Protect files and directories from prying eyes.
&nbsp;
RewriteEngine On
RewriteRule ^(\w*)/post$ index.php?at=$1&amp;do=post [L,QSA]
RewriteRule ^edit/(\d*)$ index.php?do=edit&amp;to=$1 [L,QSA]
RewriteRule ^comment/(\d*)$ index.php?do=comment&amp;to=$1 [L,QSA]</pre>



<p><a id="technical-htaccess"></a></p>
<h2>Technical Look at .htaccess</h2>
<p><a href="http://httpd.apache.org/docs/1.3/misc/API.html">Source: Apache API notes</a></p>
<h3>Per-directory configuration structures</h3>
<p>Let's look out how all of this plays out in mod_mime.c, which defines the file typing handler which emulates the NCSA server's behavior of determining file types from suffixes. What we'll be looking at, here, is the code which implements the AddType and AddEncoding commands. These commands can appear in .htaccess files, so they must be handled in the module's private per-directory data, which in fact, consists of two separate tables for MIME types and encoding information, and is declared as follows:</p>

<pre>table *forced_types;      /* Additional AddTyped stuff */
table *encoding_types;    /* Added with AddEncoding... */
mime_dir_config;</pre>

<p>When the server is reading a configuration file, or <directory> section, which includes one of the MIME module's commands, it needs to create a mime_dir_config structure, so those commands have something to act on. It does this by invoking the function it finds in the module's `create per-dir config slot', with two arguments: the name of the directory to which this configuration information applies (or NULL for srm.conf), and a pointer to a resource pool in which the allocation should happen.</p>

<p>(If we are reading a .htaccess file, that resource pool is the per-request resource pool for the request; otherwise it is a resource pool which is used for configuration data, and cleared on restarts. Either way, it is important for the structure being created to vanish when the pool is cleared, by registering a cleanup on the pool if necessary).</p>

<p>For the MIME module, the per-dir config creation function just ap_pallocs the structure above, and a creates a couple of tables to fill it. That looks like this:</p>

<pre>void *create_mime_dir_config (pool *p, char *dummy)
mime_dir_config *new = (mime_dir_config *) ap_palloc (p, sizeof(mime_dir_config));
&nbsp;
new-&gt;forced_types = ap_make_table (p, 4);
new-&gt;encoding_types = ap_make_table (p, 4);</pre>


<p>Now, suppose we've just read in a .htaccess file. We already have the per-directory configuration structure for the next directory up in the hierarchy. If the .htaccess file we just read in didn't have any AddType or AddEncoding commands, its per-directory config structure for the MIME module is still valid, and we can just use it. Otherwise, we need to merge the two structures somehow.</p>

<p>To do that, the server invokes the module's per-directory config merge function, if one is present. That function takes three arguments: the two structures being merged, and a resource pool in which to allocate the result. For the MIME module, all that needs to be done is overlay the tables from the new per-directory config structure with those from the parent:</p>

<pre>void *merge_mime_dir_configs (pool *p, void *parent_dirv, void *subdirv)
mime_dir_config *parent_dir = (mime_dir_config *)parent_dirv;
mime_dir_config *subdir = (mime_dir_config *)subdirv;
mime_dir_config *new =  (mime_dir_config *)ap_palloc (p, sizeof(mime_dir_config));
new-&gt;forced_types = ap_overlay_tables (p, subdir-&gt;forced_types, parent_dir-&gt;forced_types);
new-&gt;encoding_types = ap_overlay_tables (p, subdir-&gt;encoding_types, parent_dir-&gt;encoding_types);</pre>


<p>As a note --- if there is no per-directory merge function present, the server will just use the subdirectory's configuration info, and ignore the parent's. For some modules, that works just fine (e.g., for the includes module, whose per-directory configuration information consists solely of the state of the XBITHACK), and for those modules, you can just not declare one, and leave the corresponding structure slot in the module itself NULL.</p>

<h3>Command handling</h3>
<p>Now that we have these structures, we need to be able to figure out how to fill them. That involves processing the actual AddType and AddEncoding commands. To find commands, the server looks in the module's command table. That table contains information on how many arguments the commands take, and in what formats, where it is permitted, and so forth. That information is sufficient to allow the server to invoke most command-handling functions with pre-parsed arguments. Without further ado, let's look at the AddType command handler, which looks like this (the AddEncoding command looks basically the same, and won't be shown here):</p>
<pre>char *add_type(cmd_parms *cmd, mime_dir_config *m, char *ct, char *ext)
if (*ext == &#039;.&#039;) ++ext;
ap_table_set (m-&gt;forced_types, ext, ct);</pre>

<p>This command handler is unusually simple. As you can see, it takes four arguments, two of which are pre-parsed arguments, the third being the per-directory configuration structure for the module in question, and the fourth being a pointer to a cmd_parms structure. That structure contains a bunch of arguments which are frequently of use to some, but not all, commands, including a resource pool (from which memory can be allocated, and to which cleanups should be tied), and the (virtual) server being configured, from which the module's per-server configuration data can be obtained if required.</p>

<p>Another way in which this particular command handler is unusually simple is that there are no error conditions which it can encounter. If there were, it could return an error message instead of NULL; this causes an error to be printed out on the server's stderr, followed by a quick exit, if it is in the main config files; for a .htaccess file, the syntax error is logged in the server error log (along with an indication of where it came from), and the request is bounced with a server error response (HTTP error status, code 500).</p>

<p>The MIME module's command table has entries for these commands, which look like this:</p>
<pre>command_rec mime_cmds[] =
{ "AddType", add_type, NULL, OR_FILEINFO, TAKE2, "a mime type followed by a file extension" },
{ "AddEncoding", add_encoding, NULL, OR_FILEINFO, TAKE2, "an encoding (e.g., gzip), followed by a file extension" },</pre>


<p>The entries in these tables are:</p>
<ul>
<li>The name of the command</li>
<li>The function which handles it a (void *) pointer, which is passed in the cmd_parms structure to the command handler --- this is useful in case many similar commands are handled by the same function.</li>
<li>A bit mask indicating where the command may appear. There are mask bits corresponding to each AllowOverride option, and an additional mask bit, RSRC_CONF, indicating that the command may appear in the server's own config files, but not in any .htaccess file.</li>
<li>A flag indicating how many arguments the command handler wants pre-parsed, and how they should be passed in. TAKE2 indicates two pre-parsed arguments. Other options are TAKE1, which indicates one pre-parsed argument, FLAG, which indicates that the argument should be On or Off, and is passed in as a boolean flag, RAW_ARGS, which causes the server to give the command the raw, unparsed arguments (everything but the command name itself). There is also ITERATE, which means that the handler looks the same as TAKE1, but that if multiple arguments are present, it should be called multiple times, and finally ITERATE2, which indicates that the command handler looks like a TAKE2, but if more arguments are present, then it should be called multiple times, holding the first argument constant.</li>
<li>Finally, we have a string which describes the arguments that should be present. If the arguments in the actual config file are not as required, this string will be used to help give a more specific error message. (You can safely leave this NULL).</li>
</ul>

<p>Finally, having set this all up, we have to use it. This is ultimately done in the module's handlers, specifically for its file-typing handler, which looks more or less like this; note that the per-directory configuration structure is extracted from the request_rec's per-directory configuration vector by using the ap_get_module_config function.</p>

<h3>Side notes --- per-server configuration, virtual servers, etc.</h3>
<p>The basic ideas behind per-server module configuration are basically the same as those for per-directory configuration; there is a creation function and a merge function, the latter being invoked where a virtual server has partially overridden the base server configuration, and a combined structure must be computed. (As with per-directory configuration, the default if no merge function is specified, and a module is configured in some virtual server, is that the base configuration is simply ignored).</p>

<p>The only substantial difference is that when a command needs to configure the per-server private module data, it needs to go to the cmd_parms data to get at it. Here's an example, from the alias module, which also indicates how a syntax error can be returned (note that the per-directory configuration argument to the command handler is declared as a dummy, since the module doesn't actually have per-directory config data):</p><p><a href="http://www.askapache.com/htaccess/apache-htaccess-2.html"></a><a href="http://www.askapache.com/htaccess/apache-htaccess-2.html">Ultimate Htaccess Part II</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/apache-htaccess-2.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Advanced Windows Batch File Scripting</title>
		<link>http://www.askapache.com/windows/advanced-batch-scripting.html</link>
		<comments>http://www.askapache.com/windows/advanced-batch-scripting.html#comments</comments>
		<pubDate>Fri, 03 Sep 2010 18:14:02 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4577</guid>
		<description><![CDATA[<p><a class="IFL" href="http://www.askapache.com/windows/advanced-batch-scripting.html"><img src="http://uploads.askapache.com/2010/09/windows-batch-file-example-116x45.png" alt="Windows Batch Programming Example" title="Windows Batch Programming Example" width="116" height="45" /></a>If for some reason you need to use windows .bat batch file scripting to do some task, or you just want to learn the most universal batch programming language on Windows machines, you lucked out and found the AskApache example.  My expertise is the shell, in this article the shell is Windows <code>cmd.exe</code>.  It has some pretty advanced windows shell usage, including pipes and redirection, but it's the modular linux-like coding approach that earns this script it's "advanced" title.</p>
<pre>:SETPROMPT
set PROMPT=$_[%USERNAME%@%USERDOMAIN%]$S[$P]$_$M$G &#38;&#38; EXIT /B</pre>

<p><a class="IFL" href="http://uploads.askapache.com/2010/09/Untitled-1.png"><img src="http://uploads.askapache.com/2010/09/Untitled-1-116x38.png" alt="Create an AT job to run as system in Notepad++ IDE" title="Create an AT job to run as system in Notepad++ IDE" width="116" height="38" class="size-thumbnail wp-image-4618" /></a>My favorite tool (and I've tried sooo many) for editing most Windows files and especially .bat files is the free and open-source <a href="http://notepad-plus-plus.org/">Notepad++</a>.  Set that up and you will have a color-syntax-highlighted editor for Batch Scripting that works very very well.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/windows/advanced-batch-scripting.html"></a><a href="http://www.askapache.com/windows/advanced-batch-scripting.html"><cite>AskApache.com</cite></a></p><p><a href="http://www.askapache.com/windows/advanced-batch-scripting.html/untitled-1/" rel="attachment wp-att-4618"><img src="http://uploads.askapache.com/2010/09/Untitled-1.png" alt="Create an AT job to run as system in Notepad++ IDE" title="Create an AT job to run as system in Notepad++ IDE" width="993" height="326" class="size-full wp-image-4618" /></a></p>
<p><a class="IFL" href="http://uploads.askapache.com/2010/09/windows-batch-file-example.png"><img src="http://uploads.askapache.com/2010/09/windows-batch-file-example-116x45.png" alt="Windows Batch Programming Example" title="Windows Batch Programming Example" width="116" height="45" /></a>First off, this is a single windows <code>.bat</code> file that I have written to do advanced batch scripting the easy way, meaning it's mostly a series of functions you can call from the script or within other functions for extremely modular code.  Before you get all bent out of shape by my choice of words ("easy, modular"), when I say this is advanced I mean for Windows .bat files, one of the worlds worst scripting languages, but it works on all windows versions so it's ideal for things like autorun, autoplay, custom startups, usb drives, etc..  If you are looking for information on how to use and program windows .bat files to do anything cool, this is the right place!  I tried my best to mimic linux shell-scripting, so it's likely different than other batch files you have seen.<br class="C" /></p>



<h2>Batch File IDE and Script Source</h2>
<p><a class="IFL" href="http://uploads.askapache.com/2010/09/Untitled-1.png"><img src="http://uploads.askapache.com/2010/09/Untitled-1-116x38.png" alt="Create an AT job to run as system in Notepad++ IDE" title="Create an AT job to run as system in Notepad++ IDE" width="116" height="38" class="size-thumbnail wp-image-4618" /></a>My favorite tool (and I've tried sooo many) for editing most Windows files and especially .bat files is the free and open-source <a href="http://notepad-plus-plus.org/">Notepad++</a>.  Set that up and you will have a color-syntax-highlighted editor for Batch Scripting that works very very well.<br class="C" /></p>
<p><a class="IFL" href='http://uploads.askapache.com/2010/09/advanced-batch-askapache.txt'><img src="http://uploads.askapache.com/2010/09/windows-batch-file.png" width="46" height="60" title="windows batch file windows" alt="Advanced Windows Batch File Scripting" /></a>The next thing to do is <a href='http://uploads.askapache.com/2010/09/advanced-batch-askapache.txt'>download the source code</a>, which includes comments and formatting I had to remove for this online article.  Then rename from <code>.txt</code> to <code>.bat</code> and open in your IDE/text-editor of choice.<br class="C" /></p>


<h2>Quick Batch File Example</h2>
<p>This is a simple batch file named ping-check.bat that I use when rebooting remote servers.  The reboot is issued from an SSH session and causes the server to go down and then come back up.  When the server goes down the network goes down too so I fire this script up to continually ping the remote server until it responds, at which point I can ssh back in.</p>
<p>One of the first hacks for batch files is line 1, the PUSHD command cd's the scripts working environment to the directory of the script itself.</p>
<pre>@ECHO OFF &amp;&amp; PUSHD "%~dp0" &amp;&amp; SETLOCAL
&nbsp;
CALL :PINGCHECK "%~1"
&nbsp;
nircmd.exe speak text "PING RECEIVED.  HOST BACK ONLINE" 7 60
ENDLOCAL &amp;&amp; POPD &amp;&amp; GOTO :EOF
&nbsp;
:PINGCHECK
ECHO CHECKING %~1
ping.exe -n 1 %~1 -w 5000 | FIND /C "Reply from %~1" | FIND "1" &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 CALL :PINGCHECK "%~1" ELSE EXIT /B</pre>


<h2>Super-hero like even</h2>
<p>Just added this as an after thought, moving the main example further down this page.  This is an easier file to understand the scope of.  It effectively creates SSH-encrypted SOCK5 tunnels that stay connected and auto-reconnect if the link goes down.  I wanted to try and write a pure batch method to do that.   I wrote this to run automatically from a USB key so that I could keep my tools with me portably.  The thing of this script that is the most revolutionary is the method it uses to create auto-reconnecting <em>SSH-encrypted SOCKS5 tunnels</em> using the windows SYSTEM account to do it all in the background with plink.exe.  The hack to run it as a system account is by using the built-in <strong>AT</strong> command to run interactively, which lets you interactively do whatever you want as the builtin <code>NT AUTHORITY/SYSTEM</code> account.  The other part I am proud of with this is how lean I got the code, specifically how lean the function is that creates the at job to run every 5 minutes, while still doing connection-testing, all by parsing the cmd.exe processors builtin in DATE and TIME variables.  Do a google search for "windows batch file date and time" and you will appreciate just how lean this sucker is.</p>
<p>Almost forgot, check out the ways to keep a plink.exe (putty.exe for cmd.exe) SOCKS5 tunnel hidden and safe and continuously connected to a remote server in minimal lines od code.  This was a fun one to work on!  Enjoy (and remember this is just the warm-up example to glance at).</p>
<pre>@ECHO OFF &amp;&amp; PUSHD "%~dp0" &amp;&amp; SETLOCAL &amp;&amp; SETLOCAL ENABLEDELAYEDEXPANSION &amp;&amp; SETLOCAL ENABLEEXTENSIONS
&nbsp;
SET _CRYPTDRIVE=%~d0\
SET PATH=%_CRYPTDRIVE%PP;%_CRYPTDRIVE%PP\bin;%PATH%
SET _PUTTYBIN=%_CRYPTDRIVE%P\PP\putty.exe
&nbsp;
SET _PSERVER=solar.power.com
SET _PPORT=22
SET _PSESSION=newclean-tunnel
&nbsp;
SET _ADMINUSER=admin
SET _RUNUSER=life
&nbsp;
REM SAY CHECKING PLINK OUT LOUD
CALL :SPEAK "Checking Putty"
ECHO "CHECKING PUTTY"
&nbsp;
REM
IF NOT EXIST "%_CRYPTDRIVE%" (
  CALL :SPEAK "Crypt Not Mounted"
  AT|FOR /F "tokens=1" %%i IN (&#039;FIND /I "%~f0"&#039;) DO AT %%i /delete /yes &gt;nul 2&gt;&amp;1
  pskill.exe -t putty &gt;nul 2&gt;&amp;1
  pskill.exe -t thunderbird &gt;nul 2&gt;&amp;1
  pskill.exe -t ThunderbirdPortable &gt;nul 2&gt;&amp;1
  pskill.exe -t Firefox &gt;nul 2&gt;&amp;1
  pskill.exe -t FirefoxPortable &gt;nul 2&gt;&amp;1
  pskill.exe -t GC &gt;nul 2&gt;&amp;1
  EXIT
)
&nbsp;
REM CREATE AT JOB TO RUN THIS SCRIPT EVERY 5 MINUTES
CALL :CREATEATJOB
&nbsp;
pslist putty &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 psexec.exe -i 0 -e -d -u %_RUNUSER% %_PUTTYBIN% -load %_PSESSION%
&nbsp;
REM KILL MULTIPLE PSEXEC&#039;s
CALL :KILLDUPES "psexec.exe"
&nbsp;
REM KILL MULTIPLE CMD.EXE&#039;s
CALL :KILLDUPES "cmd.exe"
&nbsp;
REM REACHABLE SERVER CHECK
CALL :PINGCHECK %_PSERVER%
&nbsp;
REM CHECK FOR INACTIVE PUTTY
CALL :PUTTYCHECK
&nbsp;
REM CHECK PORT IS LISTENING (FOR SOCKISFIED TUNNEL)
CALL :PORTCHECK %_PPORT%
&nbsp;
REM CALL :SPEAK "OK"
SLEEP 100 &amp;&amp; ECHO "OK" &amp;&amp; SLEEP 1 &amp;&amp; ENDLOCAL &amp;&amp; POPD &amp;&amp; EXIT
&nbsp;
REM =======================================================================================
REM =   SPEAK - Speak text
REM =======================================================================================
:SPEAK
nircmd.exe speak text "%~1" 5 60
ECHO "%~1"
EXIT /B
&nbsp;
REM =======================================================================================
REM =   RESTARTPLINK - Sleeps for %1 number of seconds
REM =======================================================================================
:RESTARTPLINK
CALL :SPEAK "%~1 ReSTARTing Plink"
REM runas /savecred /user:admin "%_PUTTYBIN% -load %_PSESSION%"
psexec.exe -i 0 -e -d -u %_RUNUSER% %_PUTTYBIN% -load %_PSESSION%
EXIT
EXIT /B
&nbsp;
REM =======================================================================================
REM =   PORTCHECK - Check that Port is being used (for tunnels)
REM =======================================================================================
:PORTCHECK
netstat.exe -n -v -a -p TCP | FIND "ESTABLISHED" | FIND ":%~1" &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 CALL :RESTARTPLINK "PORT CHECK FAILED"
EXIT /B
&nbsp;
REM =======================================================================================
REM =   INACTIVEPUTTYCHECK - Check for inactive putty windows
REM =======================================================================================
:PUTTYCHECK
tasklist.exe /V /NH /FI "WINDOWTITLE eq PuTTY (inactive)" 2&gt;nul|FIND "INFO: " &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 taskkill.exe /T /F /FI "WINDOWTITLE eq PuTTY (inactive)" &gt;nul 2&gt;&amp;1
&nbsp;
:: MAKE SURE ONLY 1 putty is running that is connected to the remote server
netstat.exe -n -a -o -p TCP | FIND ":%_PPORT%" | FIND /C ":%_PPORT%" | FIND "1" &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 (
  tasklist.exe /V /FO TABLE /NH /FI "IMAGENAME eq putty.exe" 2&gt;nul | FIND /C "Running" | FIND "1" &gt;nul 2&gt;&amp;1
  IF ERRORLEVEL 1 (
    REM kill all running puttys (owned by system)
    FOR /F "usebackq tokens=2 skip=2" %%p IN (`tasklist.exe /V /FO TABLE /NH /FI "IMAGENAME eq putty.exe"`) DO taskkill.exe /F /PID %%p /T &gt;nul 2&gt;&amp;1
    CALL :RESTARTPLINK "EXTRA PUTTY FOUND"
  )
)
EXIT /B
&nbsp;
REM =======================================================================================
REM =   PINGCHECK - PING address to make sure it is reachable
REM =======================================================================================
:PINGCHECK
PING %~1 -n 1 -w 5000 | FIND "TTL=" &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 (
  PING google.com -n 1 -w 500 | FIND "TTL=" &gt;nul 2&gt;&amp;1
  IF ERRORLEVEL 1 ( CALL :SPEAK "CHECK INTERNET CONNECTION" &amp;&amp; SLEEP 60 )
&nbsp;
  PING google.com -n 1 -w 5000 | FIND "TTL=" &gt;nul 2&gt;&amp;1
  IF ERRORLEVEL 1 ( CALL :SPEAK "CHECK INTERNET CONNECTION" &amp;&amp; SLEEP 60 )
&nbsp;
  PING google.com -n 1 -w 5000 | FIND "TTL=" &gt;nul 2&gt;&amp;1
  IF ERRORLEVEL 1 (
    CALL :SPEAK "KILL SOCKS PROGRAMS"
  SLEEP 100
  pskill.exe -t putty &gt;nul 2&gt;&amp;1
  pskill.exe -t thunderbird &gt;nul 2&gt;&amp;1
  pskill.exe -t ThunderbirdPortable &gt;nul 2&gt;&amp;1
  )
)
EXIT /B
&nbsp;
REM =======================================================================================
REM =   KILLDUPES - kills duplicate processes, except for the one with lowest pid
REM =======================================================================================
:KILLDUPES
REM Check that more than 1 process is running
tasklist.exe /V /NH /FI "IMAGENAME eq %~1" /FI "USERNAME eq SYSTEM" 2&gt;nul | FIND /C "K Running" | FIND "1" &gt;nul 2&gt;&amp;1
IF NOT ERRORLEVEL 1 EXIT /B
&nbsp;
REM Create Filename in current dir (of this script)
SET _T=%TIME: =0%&amp;&amp;SET _T=!_T::=-!&amp;&amp;SET _T=%~dp0%!_T:~0,-2!log
&nbsp;
REM Create the file in the same dir as this script named for date and sorted by PID
tasklist.exe /V /NH /FI "IMAGENAME eq %~1" /FI "USERNAME eq SYSTEM" 2&gt;nul | SORT /+29 &gt; "%_T%"
&nbsp;
REM Check that the file was created or exit
IF NOT EXIST "%_T%" ( CALL :SPEAK "FILE CREATION FAILED" &amp;&amp; EXIT /B )
&nbsp;
REM kill all the processes found except for 1, do not kill the process with the lowest pid number
FOR /F "tokens=2 skip=2" %%p IN (%_T%) DO taskkill.exe /F /PID %%p /T
&nbsp;
REM erase the file
REM ERASE /Q "%_T%" &gt;nul 2&gt;&amp;1
&nbsp;
REM check that the file was erased
REM IF EXIST "%_T%" ( CALL :SPEAK "ERASE FILE FAILED" &amp;&amp; EXIT /B )
&nbsp;
EXIT /B
&nbsp;
REM =======================================================================================
REM =   CREATEATJOB - runs job (START this file) every 5 minutes
REM =======================================================================================
:CREATEATJOB
:: delete all putty AT jobs
AT | FIND /C "%~f0" | FIND "1" &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 ( AT|FOR /F "tokens=1" %%i IN (&#039;FIND /I "%~f0"&#039;) DO AT %%i /delete /yes &gt;nul 2&gt;&amp;1 )
SET /A H=!TIME:~0,2!&amp;&amp; SET M=!TIME:~3,2!
SET Y=%H%:%M%&amp;&amp; SET /A M+=5
IF !M! GEQ 61 ( SET /A H+=1&amp;&amp;SET /A M-=61 )
IF !H! GEQ 24 SET /A H-=24
SET M=0!M!&amp;&amp; SET H=0!H!
:: create AT job
AT %H:~-2%:%M:~-2% /INTERACTIVE %ComSpec% /E:ON /D /Q /C START /B /MIN %ComSpec% /E:ON /D /Q /C "%~f0" &gt;nul
EXIT /B</pre>







<h2>Advanced Batch File</h2>
<p>This is the main batch file example which you can <a href="http://uploads.askapache.com/2010/09/advanced-batch-askapache.txt">download here</a>.  Other than some minor changes this is the actual script I use at work when I logon to my PC.  The first thing it does is mount an encrypted TrueCrypt Drive where all of my files and settings are located.  It also starts a putty session named "1" that I configured to start a few encrypted tunnels and socks proxies so that my email Thunderbird and Website IDE Dreamweaver and other network apps can communicate 100% encrypted and my real location becomes hidden (thanks socks!).</p>
<p>I might come back later and add comments if I get any kind of response for this article, and because it's such a unique and low-traffic topic, I will try to answer any questions added with the comment form.</p>


<h2>Starting the Script</h2>
<p>The first line is of my own design and is perhaps the coolest hack in the script.  I use this 1 line to start pretty much all of my .bat files.</p>
<pre>@ECHO OFF&amp;&amp; SETLOCAL&amp;&amp; PUSHD "%~dp0"&amp;&amp; SETLOCAL ENABLEDELAYEDEXPANSION&amp;&amp; SETLOCAL ENABLEEXTENSIONS&amp;&amp; SET V=5&amp;&amp; IF NOT "!V!"=="5" (ECHO DelayedExpansion Failed&amp;&amp; GOTO :EOF)</pre>


<h2>SCRIPT VARIABLES</h2>
<p>These are all local to this script thanks to the SETLOCAL above, so they won't exist outside the scripts execution environment.</p>
<pre>REM ** Various vars for output used by functions
SET P1=^^^&gt;^^^&gt;^^^&gt;
SET P2=++
SET P3=::
SET L1=+==============================================================================================================+
SET L2=+--------------------------------------------------------------------------------------------------------------+
&nbsp;
REM ** administrator username, unless changed for more security, its Administrator
SET ADMINUSER=admin
&nbsp;
REM ** runuser is the username you use when running this script
SET RUNUSER=bill
&nbsp;
REM ** Custom COMSPEC for running cmd.exe
SET _SCOM=%COMSPEC% /E:ON /F:ON /D /Q /T:0C /C
&nbsp;
REM ** Custom START command
SET _START=START /WAIT /MIN /B %_SCOM%</pre>




<h2>MAIN PROGRAM EXECUTION</h2>
<p>This is where the main code starts, note how small it is thanks to the use of functions (labels/call/goto).  Read the comments in this area (start with :: or REM ) to see the extent of this script.  The gold is in the functions.</p>
<pre>:: Only allow certain users to run this script or die (prevents global STARTup or service running it)
CALL :CHECKUSERVALID %RUNUSER% %ADMINUSER%
&nbsp;
:: Mount the truecrypt container
CALL :CRYPTMOUNT "L" "%SYSTEMDRIVE%\CRYPT\LEONARDO" "%SYSTEMDRIVE%\CRYPT\LEONARDO_KEY"
&nbsp;
:: Start Mozilla Firefox
CALL :RUNONE "C:\Program Files\Mozilla Firefox\firefox.exe"
&nbsp;
:: Start Thunderbird Portable
CALL :RUNONE "L:\P\PP\putty.exe" "/MIN" -load 1
&nbsp;
:: Start Thunderbird Portable
CALL :RUNONE "L:\P\TB\ThunderbirdPortable.exe" "/MIN"
&nbsp;
:: Start Adobe Dreamweaver CS4
CALL :RUNONE "C:\Program Files\Adobe\Adobe Dreamweaver CS4\Dreamweaver.exe" "/MIN"
&nbsp;
:: Start LightScreen Portable
CALL :RUNONE "L:\P\LP\LightscreenPortable.exe" /B /B
&nbsp;
:: Start Google Chrome Portable ( GREAT to use for pandora/last.fm as its so low mem )
CALL :RUNONE "L:\P\GC\GC.exe" "/NORMAL"
&nbsp;
:: Start Adobe Photoshop CS4
CALL :RUNONE "%ProgramFiles%\Adobe\Adobe Photoshop CS4\Photoshop.exe" "/MAX"</pre>

<h3>Exit Script</h3>
<p>This is the last line executed in the Main, it forces the script to exit cleanly at this point, otherwise the functions below would all get executed.  This is what allows the use of all the functions below.  I end all my scripts MAIN with this.</p>
<pre>REM ** EXIT Script
CALL :MDYE "EOF" &amp;&amp; POPD &amp;&amp; ENDLOCAL &amp;&amp; GOTO :EOF</pre>







<h2>SCRIPT FUNCTIONS</h2>
<p>Now then, onto the MEAT of the script, all the functions.  These functions are designed for global use in other batch files, so that the only modification when you make a new batch is the above variables and main execution..  If you know much about batch files you will realize that creating these functions was a very painful process in some cases.. I freakin hate windows!  Anyway, enjoy!</p>
<h3>CRYPTMOUNT - mounts a truecrypt container and returns to CALLer. On fail, quit</h3>
<pre>REM
REM     CALL :CRYPTMOUNT "%LEONARDO%" "%LEONARDO_FILE%" "%LEONARDO_KEY%"
REM     CALL :CRYPTMOUNT "L" "%SYSTEMDRIVE%\CRYPT\LEONARDO" "%SYSTEMDRIVE%\CRYPT\LEONARDO_KEY"
REM
REM :: print the settings
REM :: CALL :MP 3 "DRIVE: %DRIVE%"&amp;&amp;CALL :MP 3 " FILE: %FILE%"&amp;&amp;CALL :MP 3 "  KEY: %KEY%"&amp;&amp;CALL :MP 3 "  VOL: %VOL%"</pre>
<pre>:CRYPTMOUNT
SET DRIVE=%~1&amp;&amp; SET FILE=%~2&amp;&amp; SET KEY=%~3&amp;&amp; SET VOL=!FILE:~0,3!
CALL :MP 1 "Mounting TrueCrypt on %DRIVE% from %FILE%"
&nbsp;
:: Check for Truecrypt or die
CALL :EXISTORQUIT "%ProgramFiles%\TrueCrypt\TrueCrypt.exe" &amp;&amp; CALL :EXISTORQUIT "%FILE%" &amp;&amp; CALL :EXISTORQUIT "%KEY%"
&nbsp;
:: checks that MOUNTVOL works and the drive containing the truecrypt container file is present or dies
MOUNTVOL %VOL% /L 2&gt;NUL | FIND "\\?\Volume{" &gt;NUL 2&gt;&amp;1
IF ERRORLEVEL 1 CALL :MDYE "%VOL% NOT FOUND"
&nbsp;
REM ** Converts G:\ to its \\?\Volume{234234}\ equivalent for greater portability
FOR /F %%i IN (&#039;MOUNTVOL %VOL% /L&#039;) DO @SET VOL=%%i%FILE:~3%
&nbsp;
:: IF the drive is already mounted then continue, otherwise try to mount
MOUNTVOL %DRIVE%:\ /L &gt;NUL 2&gt;&amp;1
IF NOT ERRORLEVEL 1 (
  CALL :MP 2 "%DRIVE% ALREADY MOUNTED" &amp;&amp; EXIT /B
) ELSE (
  START "Mounting TrueCrypt" /D"%ProgramFiles%\TrueCrypt" /MIN /B TrueCrypt.exe /c n /b /q background /h n /k %KEY% /l %DRIVE% /p /v %VOL% &amp;&amp; SLEEP 10
)
&nbsp;
:: try again in case of bad password and accidental keypress
MOUNTVOL %DRIVE%:\ /L &gt;NUL 2&gt;&amp;1
IF ERRORLEVEL 1 (START "Mounting TrueCrypt" /D"%ProgramFiles%\TrueCrypt" /MIN /B TrueCrypt.exe /c n /b /q background /h n /k %KEY% /l %DRIVE% /p /v %VOL% &amp;&amp; SLEEP 10)
&nbsp;
:: IF it still doesnt exist then quit
MOUNTVOL %DRIVE%:\ /L &gt;NUL 2&gt;&amp;1
IF ERRORLEVEL 1 CALL :MDYE "Failed to mount %FILE% on %DRIVE%"
&nbsp;
CALL :MF &amp;&amp; ENDLOCAL &amp;&amp; EXIT /B
EXIT /B</pre>




<h3>RUNONE - Starts one instance of executable after verifying it exists and is not already running.</h3>
<pre>REM     %~1 is location of executatable
REM     %~2 is optional (unless %~3 is used) START parameters
REM     %~3 is optional parameters for executable
REM
REM     CALL :RUNONE "L:\P\LP\LightscreenPortable.exe" "/MAX" "/HIDE"</pre>
<pre>:RUNONE
SETLOCAL
CALL :MP 1 "Starting %~n1"
&nbsp;
:: SLEEP FOR NICENESS, LOCAL VARS _P2 and _P3
SLEEP 2 &amp;&amp; SETLOCAL
&nbsp;
SET P=%~1
ECHO %P%|FIND " " &gt;NUL 2&gt;&amp;1
IF NOT ERRORLEVEL 1 ( PUSHD "%~dp1" &amp;&amp; SET P=%~nx1 )
&nbsp;
:: SET _P2 TO DEFAULT TO "/MIN" IF EMPTY
SET _P2=/MIN
IF NOT " %~2" == " " SET _P2=%~2
IF NOT " %~3" == " " SET _P3=%~3
IF NOT " %~4" == " " SET _P4=%~4
&nbsp;
:: CHECK THAT EXECUTABLE EXISTS
CALL :EXISTORQUIT "%~1"
&nbsp;
REM ECHO START %_P2% /D"%~dp1" %P% %_P3% %_P4%&amp;&amp; PAUSE&amp;&amp;
:: CHECK FOR EXISTING PROCESSNAME ( %~n1 is file name without ext, %~nx1 is the file name and extension. )
pslist.exe /e %~n1 &gt;NUL 2&gt;&amp;1
IF ERRORLEVEL 1 (START %_P2% /D"%~dp1" %P% %_P3% %_P4% ) ELSE (CALL :MP 2 "%~n1 already running!" )
&nbsp;
ENDLOCAL &amp;&amp; EXIT /B</pre>







<h3>ADMINRUNONE - Runs %1 with admin rights IF neccessary</h3>
<pre>:ADMINRUNONE
CALL :MP 3 "Exec %~1 as %ADMINUSER%"
&nbsp;
:: Check that file exists
CALL :EXISTORQUIT "%~1"
&nbsp;
:: test for rights to the task scheduler
:: %SYSTEMDRIVE%\WINDOWS\system32\cmd.exe /E:ON /D /Q /T:0C /C START /WAIT /MIN /B %SYSTEMDRIVE%\WINDOWS\system32\cmd.exe /E:ON /D /Q /T:0C /C %~1
AT &gt;NUL 2&gt;&amp;1
IF ERRORLEVEL 1 (
  RUNAS /noprofile /user:%USERDOMAIN%\%ADMINUSER% "%~1"
) ELSE (
  %COMSPEC% /E:ON /D /Q /T:0C /C "%~1"
)
SLEEP 2 &amp;&amp; CALL :MF &amp;&amp; EXIT /B</pre>






<h3>CHECKUSERVALID - checks that defined username equals %ADMINUSER% or %RUNUSER%, then returns to CALLer</h3>
<pre>:CHECKUSERVALID
:: EXIT IF USERNAME IS NOT DEFINED, CATCHES SYSTEM ACCOUNTS TRYING TO RUN WHEN IN GLOBAL STARTUP
IF NOT DEFINED USERNAME EXIT
&nbsp;
SETLOCAL
SET UP=no
SET _P1= %~1
SET _P2= %~2
IF NOT "%_P1%" == " " ( IF /I "%~1" == "%USERNAME%" SET UP=yes)
IF NOT "%_P1%" == " " ( IF /I "%~1" == "%USERNAME%" SET UP=yes)
IF NOT "%_P1%" == " " ( IF /I "%~1" == "%USERNAME%" SET UP=yes)
IF /I "bill" == "%USERNAME%" SET UP=yes
IF /I "newbill" == "%USERNAME%" SET UP=yes
IF /I "max" == "%USERNAME%" SET UP=yes
IF /I NOT "%UP%" == "yes" EXIT
ENDLOCAL
EXIT /B</pre>



<h3>SETPROMPT - sets prompt, then returns to CALLer</h3>
<pre>REM =   [user@MACHINE] [C:\DR\PEPPER\SCRIPTS]
REM =   &gt; REG /?</pre>
<pre>:SETPROMPT
set PROMPT=$_[%USERNAME%@%USERDOMAIN%]$S[$P]$_$M$G &amp;&amp; EXIT /B</pre>


<h3>BEEP - beeps once, then returns to CALLer</h3>
<p>The character after the echo is the actual BEL char, so unless you have my source file, you will need to copy a literal BEL char here to make it beep.</p>
<pre>:BEEP
@ECHO # &amp;&amp; EXIT /B</pre>


<h3>MSETCOLOR - SET colors for screen, then returns to CALLer</h3>
<pre>REM
REM     0 = Black       8 = Gray
REM     1 = Blue        9 = Light Blue
REM     2 = Green       A = Light Green
REM     3 = Aqua        B = Light Aqua
REM     4 = Red         C = Light Red
REM     5 = Purple      D = Light Purple
REM     6 = Yellow      E = Light Yellow
REM     7 = White       F = Bright White
REM</pre>
<pre>:MSETCOLOR
COLOR %~1 &amp;&amp; EXIT /B</pre>


<h3>MSETCONSOLE - sets the cols and lines of current screen buffer, then returns to CALLer</h3>
<pre>:MSETCONSOLE
MODE CON COLS=%~1 LINES=%~2 &amp;&amp; EXIT /B</pre>



<h3>PARAMTEST - tests params, then returns to CALLer</h3>
<pre>:PARAMTEST
ECHO. &amp;&amp; CALL :MP 1 "PARAMTEST CALLED WITH: %*" &amp;&amp; ECHO %L1%
SET _P= %~1
IF NOT "%_P%" == " " ( ECHO %%1          = %1 &amp;&amp; ECHO %%~f1        = %~f1 &amp;&amp; ECHO %%~d1        = %~d1 &amp;&amp; ECHO %%~p1        = %~p1
  ECHO %%~n1        = %~n1 &amp;&amp; ECHO %%~x1        = %~x1 &amp;&amp; ECHO %%~s1        = %~s1 &amp;&amp; ECHO %%~dp1       = %~dp1
  ECHO %%~nx1       = %~nx1 &amp;&amp; ECHO %%~$PATH:1   = %~$PATH:1 &amp;&amp; ECHO %%~dp$PATH:1 = %~dp$PATH:1 &amp;&amp; ECHO %L1% )
SET _P= %~2
IF NOT "%_P%" == " " ( ECHO %%2          = %2 &amp;&amp; ECHO %%~f2        = %~f2 &amp;&amp; ECHO %%~d2        = %~d2 &amp;&amp; ECHO %%~p2        = %~p2
  ECHO %%~n2        = %~n2 &amp;&amp; ECHO %%~x2        = %~x2 &amp;&amp; ECHO %%~s2        = %~s2 &amp;&amp; ECHO %%~dp2       = %~dp2
  ECHO %%~nx2       = %~nx2 &amp;&amp; ECHO %%~$PATH:2   = %~$PATH:2 &amp;&amp; ECHO %%~dp$PATH:2 = %~dp$PATH:2 &amp;&amp; ECHO %L1% )
SET _P= %~3
IF NOT "%_P%" == " " ( ECHO %%3          = %3 &amp;&amp; ECHO %%~f3        = %~f3 &amp;&amp; ECHO %%~d3        = %~d3 &amp;&amp; ECHO %%~p3        = %~p3
  ECHO %%~n3        = %~n3 &amp;&amp; ECHO %%~x3        = %~x3 &amp;&amp; ECHO %%~s3        = %~s3 &amp;&amp; ECHO %%~dp3       = %~dp3
  ECHO %%~nx3       = %~nx3 &amp;&amp; ECHO %%~$PATH:3   = %~$PATH:3 &amp;&amp; ECHO %%~dp$PATH:3 = %~dp$PATH:3 &amp;&amp; ECHO %L1% )
SET _P= %~4
IF NOT "%_P%" == " " ( ECHO %%4          = %4 &amp;&amp; ECHO %%~f4        = %~f4 &amp;&amp; ECHO %%~d4        = %~d4 &amp;&amp; ECHO %%~p4        = %~p4
  ECHO %%~n4        = %~n4 &amp;&amp; ECHO %%~x4        = %~x4 &amp;&amp; ECHO %%~s4        = %~s4 &amp;&amp; ECHO %%~dp4       = %~dp4
  ECHO %%~nx4       = %~nx4 &amp;&amp; ECHO %%~$PATH:4   = %~$PATH:4 &amp;&amp; ECHO %%~dp$PATH:4 = %~dp$PATH:4 &amp;&amp; ECHO %L1% )
SET _P= %~5
IF NOT "%_P%" == " " ( ECHO %%5          = %5 &amp;&amp; ECHO %%~f5        = %~f5 &amp;&amp; ECHO %%~d5        = %~d5 &amp;&amp; ECHO %%~p5        = %~p5
  ECHO %%~n5        = %~n5 &amp;&amp; ECHO %%~x5        = %~x5 &amp;&amp; ECHO %%~s5        = %~s5 &amp;&amp; ECHO %%~dp5       = %~dp5
  ECHO %%~nx5       = %~nx5 &amp;&amp; ECHO %%~$PATH:5   = %~$PATH:5 &amp;&amp; ECHO %%~dp$PATH:5 = %~dp$PATH:5 &amp;&amp; ECHO %L1% )
SET _P= %~6
IF NOT "%_P%" == " " ( ECHO %%6          = %6 &amp;&amp; ECHO %%~f6        = %~f6 &amp;&amp; ECHO %%~d6        = %~d6 &amp;&amp; ECHO %%~p6        = %~p6
  ECHO %%~n6        = %~n6 &amp;&amp; ECHO %%~x6        = %~x6 &amp;&amp; ECHO %%~s6        = %~s6 &amp;&amp; ECHO %%~dp6       = %~dp6
  ECHO %%~nx6       = %~nx6 &amp;&amp; ECHO %%~$PATH:6   = %~$PATH:6 &amp;&amp; ECHO %%~dp$PATH:6 = %~dp$PATH:6 &amp;&amp; ECHO %L1% )
SET _P= %~7
IF NOT "%_P%" == " " ( ECHO %%7          = %7 &amp;&amp; ECHO %%~f7        = %~f7 &amp;&amp; ECHO %%~d7        = %~d7 &amp;&amp; ECHO %%~p7        = %~p7
  ECHO %%~n7        = %~n7 &amp;&amp; ECHO %%~x7        = %~x7 &amp;&amp; ECHO %%~s7        = %~s7 &amp;&amp; ECHO %%~dp7       = %~dp7
  ECHO %%~nx7       = %~nx7 &amp;&amp; ECHO %%~$PATH:7   = %~$PATH:7 &amp;&amp; ECHO %%~dp$PATH:7 = %~dp$PATH:7 &amp;&amp; ECHO %L1% )
SLEEP 3
CALL :MF
EXIT /B</pre>




<h3>PARAMTESTHELP - show params help, then returns to CALLer</h3>
<pre>:PARAMTESTHELP
ECHO %%~1 Expands %%1 and removes any surrounding quotation marks
ECHO %%~f1 Expands %%1 to a fully qualified path name.
ECHO %%~d1 Expands %%1 to a drive letter.
ECHO %%~p1 Expands %%1 to a path.
ECHO %%~n1 Expands %%1 to a file name.
ECHO %%~x1 Expands %%1 to a file extension.
ECHO %%~s1 Expanded path contains short names only.
ECHO %%~a1 Expands %%1 to file attributes.
ECHO %%~t1 Expands %%1 to date and time of file.
ECHO %%~z1 Expands %%1 to size of file.
ECHO %%~dp1 Expands %%1 to a drive letter and path.
ECHO %%~nx1 Expands %%1 to a file name and extension.
ECHO %%~ftza1 Expands %%1 to a dir-like output line.
ECHO %%~$PATH:1 Searches the dirs in PATH expanding %%1 to fully qualified name of first found. If var name isn&#039;t defined or the files not found, expands to empty string.
ECHO %%~dp$PATH:1 Searches the directories listed in the PATH environment variable for %%1 and expands to the drive letter and path of the first one found.
CALL :MF
EXIT /B</pre>







<h3>EXAMINEFILE - FINDs useful strings in file, then returns to CALLer</h3>
<pre>:EXAMINEFILE
CALL :MP 1 "Examine File %~1"
CALL :EXISTORQUIT "%~1"
STRINGS "%~1" | FINDSTR /R /C:"[A-Z][A-Z]\="
CALL :MF
EXIT /B</pre>


<h3>ADMINSHELL - sets prompt, then returns to CALLer</h3>
<pre>:ADMINSHELL
CALL :MP 1 "Creating Admin Shell"
CALL :EXISTORQUIT "%SYSTEMROOT%\system32\runas.exe"
START %SYSTEMROOT%\system32\runas.exe /profile /savecred /user:%ADMINUSER% "%COMSPEC% /T:0C /E:ON /F:ON /K cmd.exe /K cd C:\CRYPT\BIN"
CALL :MF
EXIT /B</pre>


<h3>EXISTORQUIT - checks %~1 exists, IF it does returns to CALLer, otherwise, quit</h3>
<pre>:EXISTORQUIT
:: CALL :MP 1 "Checking for %~1"
IF NOT EXIST "%~1" CALL :MDYE "%~1 NOT FOUND"
EXIT /B</pre>


<h3>RR - IF file %1 EXISTs then :MT "Removing %1" then :MF, then ( or IF %1 not EXISTs)  returns to CALLer</h3>
<pre>:RR
CALL :MP 1 "Removing %~1"
IF EXIST "%~1" ERASE /q "%~1"
CALL :MF &amp;&amp; EXIT /B</pre>








<h3>LOCKDOWN  - locks workstation, then returns to CALLer (pointless)</h3>
<pre>:LOCKDOWN
RUNDLL32 USER32.DLL,LockWorkStation &amp;&amp; EXIT /B</pre>



<h3>SHUTDOWNIN - initiates shutdown, then returns to CALLer (pointless)</h3>
<pre>REM shutdown /a aborts</pre>
<pre>:SHUTDOWNIN
SHUTDOWN -r -t "%~1" &amp;&amp; EXIT /B</pre>



<h3>LISTSERVICES - lists services, then returns to CALLer</h3>
<pre>:LISTSERVICES
SC query state= all type= all | FOR /F "tokens=2" %%i IN (&#039;FIND /I "SERVICE_NAME"&#039;) DO @ECHO %%i
SC query | FOR /F "tokens=2" %%i IN (&#039;FIND /I "SERVICE_NAME"&#039;) DO @ECHO %%i
EXIT /B</pre>




<h3>TASKS - Advanced Tasklisting</h3>
<pre>:TASKS
SET _P=%~1
SET _PP= %~1
IF "%_PP%" == " " EXIT /B
&nbsp;
REM SORTABLES
IF /I "%_P%" == "pid" ( tasklist.exe /V /NH | SORT /+29 &amp;&amp; EXIT /B )
IF /I "%_P%" == "size" ( tasklist.exe /V /NH | SORT /+59 &amp;&amp; EXIT /B )
IF /I "%_P%" == "user" ( tasklist.exe /V /NH | SORT /+89 &amp;&amp; EXIT /B )
IF /I "%_P%" == "time" ( tasklist.exe /V /NH | SORT /+138 &amp;&amp; EXIT /B )
IF /I "%_P%" == "window" ( tasklist.exe /V /NH | SORT /+152 &amp;&amp; EXIT /B )
&nbsp;
REM FILTERS
IF /I "%_P%" == "image" ( tasklist.exe /V /NH /FI "IMAGENAME eq %~2" &amp;&amp; EXIT /B )
IF /I "%_P%" == "username" ( tasklist.exe /V /NH /FI "USERNAME eq %~2" &amp;&amp; EXIT /B )
IF /I "%_P%" == "running" ( tasklist.exe /V /NH /FI "STATUS eq Running" &amp;&amp; EXIT /B )
IF /I "%_P%" == "status" ( tasklist.exe /V /NH /FI "STATUS eq %~2" &amp;&amp; EXIT /B )
CALL :MF
EXIT /B</pre>



<h3>SPEAK - Speak text</h3>
<pre>:SPEAK
REM ECHO "%~1"
nircmd.exe speak text "%~1" 5 60 &amp;&amp; EXIT /B</pre>



<h3>MF - SLEEPs for 1 second, then prints out completed message, followed by 2 blank lines, then returns to CALLer</h3>
<pre>:MF
SLEEP 1 &amp;&amp; ECHO  [COMPLETED] &amp;&amp; ECHO. &amp;&amp; ECHO. &amp;&amp; EXIT /B</pre>


<h3>MM - prints blank line, L1, changes title of the interpreter window to %~1, prints >>> %~1..., L2, blank line, then returns to CALLer</h3>
<pre>:MM
SLEEP 1 &amp;&amp; ECHO. &amp;&amp; ECHO %L1% &amp;&amp; title +++ %~1... &amp;&amp; ECHO %P1% %~1... &amp;&amp; ECHO %L2% &amp;&amp; ECHO. &amp;&amp; EXIT /B</pre>


<h3>MT - prints blank line, L1, changes title of the interpreter window to %~1, prints >>> %~1..., L2, blank line, then returns to CALLer</h3>
<pre>:MT
CALL :MM "%~1" &amp;&amp; CALL :SPEAK "%~1" &amp;&amp; EXIT /B</pre>


<h3>MP - Print Output, then returns to CALLer</h3>
<pre>:MP
IF "%~1" == "1" ECHO %P1% %~2 &amp;&amp; EXIT /B
IF "%~1" == "2" ECHO %P2% %~2 &amp;&amp; ECHO. &amp;&amp; EXIT /B
IF "%~1" == "3" ECHO %P3% %~2 &amp;&amp; EXIT /B
EXIT /B</pre>


<h3>MP3 - ECHO %~1, speak %~1 with nircmd.exe, then returns to CALLer</h3>
<pre>:MP3
CALL :MP 1 "%~1" &amp;&amp; CALL :SPEAK "%~1" &amp;&amp; EXIT /B</pre>



<h3>MDYE - exit script with message %~1, then returns to CALLer</h3>
<pre>:MDYE
SETLOCAL
SET _M= %~1
IF NOT "%_M%" == " " SET _M=REASON: %~1
CALL :MP 1 "EXITING SCRIPT...  %_M%" &amp;&amp; ECHO. &amp;&amp; ECHO.
ENDLOCAL &amp;&amp; EXIT /B</pre>



<h3>MKILL - exit cmd processor with message %~1</h3>
<pre>:MKILL
SETLOCAL
SET _M= %~1
IF NOT "%_M%" == " " SET _M=REASON: %~1
ECHO. &amp;&amp; ECHO. &amp;&amp; CALL :MP 1 "EXITING CMD WINDOW IN 3 SECONDS...  %_M%" &amp;&amp; ECHO. &amp;&amp; ECHO. &amp;&amp; SLEEP 3
ENDLOCAL &amp;&amp; EXIT &amp;&amp; EXIT &amp;&amp; EXIT</pre>



<h2>EOF: Thoughts</h2>
<p>So what did you think?  I have around 20 batch scripts that utilize these and other functions to do all sorts of cool things.  One takes a screenshot of my desktop every 10 minutes and saves it for a real-cool archive of my activity.  Another lets me edit a boot.ini file with 1 command.. And another runs when I insert a USB drive to automatically mount a truecrypt volume and create SSH tunnels in the background by using Plink, AT, and the runas.exe command.</p>
<p>If you want to program, please use linux...  If you need to write a Windows batch file, I hope this helps.</p><p><a href="http://www.askapache.com/windows/advanced-batch-scripting.html"></a><a href="http://www.askapache.com/windows/advanced-batch-scripting.html">Advanced Windows Batch File Scripting</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/windows/advanced-batch-scripting.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Debugging Tools for Windows</title>
		<link>http://www.askapache.com/windows/debugging-tools.html</link>
		<comments>http://www.askapache.com/windows/debugging-tools.html#comments</comments>
		<pubDate>Thu, 24 Jun 2010 23:43:47 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4137</guid>
		<description><![CDATA[<p>I am almost ready to publish the final tutorial on using ssh tunnels from a truecrypt partition on a Windows machine.  Of course I choose to go way overboard in my research and the tutorial is full of some pretty awesome windows tricks.. I will come back to this post soon and post all the other advanced tools I use for debugging windows, for now though you MUST know how to debug the kernel and use these basic debugging tools.</p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/windows/debugging-tools.html"></a><a href="http://www.askapache.com/windows/debugging-tools.html"><cite>AskApache.com</cite></a></p><p>I am almost ready to publish the final tutorial on using ssh tunnels from a truecrypt partition on a Windows machine.  Of course I choose to go way overboard in my research and the tutorial is full of some pretty awesome windows tricks.. I will come back to this post soon and post all the other advanced tools I use for debugging windows, for now though you MUST know how to debug the kernel and use these basic debugging tools.</p>





<a href="http://technet.microsoft.com/en-us/library/cc757323%28WS.10%29.aspx">WINDOWS NETWORKING !!!!!</a>
<div>
<div>Debugging Tools for Windows</div>
<div>Target Computer and Host Computer</div>
<!--Content type: PSDK_3. Transform: webcollection2mtps.xslt.-->
<div><!----></div>
<a id="r02_setup_1_3ababa5c-2202-4141-b689-a847cbfc3cb1.xml"><!----></a>Kernel-mode debugging requires a <a id="ctl00_MTCS_main_ctl01" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl01',this);" href="http://msdn.microsoft.com/en-us/library/cc265771.aspx#592a23b6-7f7d-434c-b4f6-5e1470b41393"><em>target computer</em></a> and a <em>host computer</em>. The target computer is used to run the kernel-mode application. The host computer is used to run the debugger.

The following diagram shows the typical Microsoft Windows setup that you can use to perform kernel debugging and diagnose system failures.

<!--src=[dbg_2000.png]--><img src="http://i.msdn.microsoft.com/Cc266325.dbg_2000(en-us,MSDN.10).png" alt="Debugging Tools for Windows"  title="Cc266325.dbg 2000(en us,MSDN.10) windows" />

<strong>Typical Windows debugging setup</strong>

This diagram shows the typical setup. However, the current versions of KD and WinDbg (which you installed with this documentation) are flexible. KD and WinDbg can do the following
<ul>
	<li>Debug a target computer that is running Windows.</li>
	<li>Debug a target computer that is running on an x86-based platform, an Itanium-based platform, or an x64-based platform.</li>
	<li>Can be started from a host computer that is running Windows.</li>
	<li>Can be started from a host computer that is on an x86-based platform, an Itanium-based platform, or an x64-based platform.</li>
</ul>
<!---->

The target computer and host computer do not have to use the same platform or the same version of Windows.

Kernel debugging does not require specific combinations of the free or checked builds. You can debug a free system from a free or checked system, and you can debug a checked system from a free or checked system. However, typically, there is no reason for the host computer to run the slower checked build.

<strong>Note</strong> If you are running the debuggers from an Itanium-based host computer, make sure that you are using the correct version of the binaries. For more information about which version of the debugger package to use, see <a id="ctl00_MTCS_main_ctl03" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl03',this);" href="http://msdn.microsoft.com/en-us/library/cc266331.aspx">Choosing a 32-bit or 64-bit Debugger Package</a>.

</div>
<div></div>
<div></div>
<div></div>
<div>Debugging Tools for Windows</div>
<div>List of Tools and Documentation</div>
<!--Content type: PSDK_3. Transform: webcollection2mtps.xslt.-->
<div><!----></div>
<a id="TOC_Debuggers_a3feedd0-1691-4c43-bdaa-992355a82b05.xml"><!----></a>

<!---->

Microsoft Debugging Tools for Windows includes a number of debuggers and other tools. Some of them are described in this documentation, and others are described elsewhere. The following list briefly describes each tool and where its documentation can be found.
<h4>Debuggers</h4>
Debugging Tools for Windows includes the following debuggers. These are described throughout this documentation, and are referred to by their individual names or collectively as "the debugger":

<dl> <dt>WinDbg  (<em>Windbg.exe</em>)</dt> <dd>A user-mode and kernel-mode debugger with a graphical interface.</dd> <dt>KD  (<em>Kd.exe</em>)</dt> <dd>A kernel-mode debugger with a console interface.</dd> <dt>CDB  (<em>Cdb.exe</em>)</dt> <dd>A user-mode debugger with a console interface.</dd> <dt>NTSD  (<em>Ntsd.exe</em>)</dt> <dd>A user-mode debugger with a console interface. CDB and NTSD are virtually identical. In this documentation, whenever a reference is made to "CDB", it applies to both CDB and NTSD. When these two debuggers differ, it is noted. (See <a id="ctl00_MTCS_main_ctl01" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl01',this);" href="http://msdn.microsoft.com/en-us/library/cc266320.aspx">CDB</a> and <a id="ctl00_MTCS_main_ctl02" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl02',this);" href="http://msdn.microsoft.com/en-us/library/cc266320.aspx#f7997e21-d84a-4224-af71-bc393265af91">NTSD</a> for details.)</dd> </dl>
<table id="tblContentMiddle" border="0" cellspacing="0" cellpadding="0" width="785">
<tbody>
<tr>
<td>
<div>
<h1>Debugging Tools for Windows - Overview</h1>
<!-- begin pchlp top test code --> <a href="http://www.microsoft.com/whdc/pchlp.mspx#top">Looking for updates and drivers for your personal computer?</a>

<!-- end pchlp top test code -->

You can use Debugging Tools for Windows to debug drivers, applications, and services on systems that are running Windows NT 4.0, Windows 2000, Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows Server 2008 R2, or Windows 7. You can also use Debugging Tools for Windows to debug the operating system itself. Versions of the Debugging Tools for Windows package are available for 32-bit x86, native Intel Itanium, and native x64 platforms.

The latest release of Debugging Tools for Windows is available as part of the <a href="http://www.microsoft.com/whdc/DevTools/WDK/WDKpkg.mspx">Windows Driver Kit (WDK)</a>.

<strong>Note:</strong> If you have a system with a 64-bit processor and you are debugging an application on it, you must use one of the native 64-bit packages.

</div></td>
</tr>
</tbody>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0" width="785">
<tbody>
<tr>
<td>
<div>

<strong>Using Debugging Tools for Windows</strong>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_tool.gif" border="0" alt="Tools" title="icon tool windows" /></td>
<td align="left" valign="top"><a href="http://www.microsoft.com/whdc/devtools/debugging/symbolpkg.mspx#d">Download Windows Symbol Packages</a><img src="http://www.microsoft.com/whdc/images/shared/common/space.gif" border="0" alt="Debugging Tools for Windows" width="1" height="1" title="space windows" />
Symbol packages for a variety of Windows versions.</td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_text.gif" border="0" alt="White Paper" title="icon text windows" /></td>
<td align="left" valign="top"><a href="http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx#a">Install Debugging Tools for Windows 32-bit Version</a> <img src="http://www.microsoft.com/whdc/images/fileType/new.gif" border="0" alt="Debugging Tools for Windows"  title="new windows" />
Download page for the latest 32-bit packages.</td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_text.gif" border="0" alt="White Paper" title="icon text windows" /></td>
<td align="left" valign="top"><a href="http://www.microsoft.com/whdc/devtools/debugging/install64bit.mspx#">Install Debugging Tools for Windows 64-bit Versions</a> <img src="http://www.microsoft.com/whdc/images/fileType/new.gif" border="0" alt="Debugging Tools for Windows"  title="new windows" />
Download page for the latest 64-bit packages.</td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_text.gif" border="0" alt="White Paper" title="icon text windows" /></td>
<td align="left" valign="top"><a href="http://www.microsoft.com/whdc/devtools/debugging/whatsnew.mspx#">What's New for Debugging Tools for Windows</a> <img src="http://www.microsoft.com/whdc/images/fileType/new.gif" border="0" alt="Debugging Tools for Windows"  title="new windows" /></td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_nod.gif" border="0" alt="WHDC Portal/Nodal" title="icon nod windows" /></td>
<td align="left" valign="top"><a href="http://www.microsoft.com/whdc/devtools/debugging/debugstart.mspx#a">Debugging Tools and Symbols: Getting Started</a><img src="http://www.microsoft.com/whdc/images/shared/common/space.gif" border="0" alt="Debugging Tools for Windows" width="1" height="1" title="space windows" />
Tips for using Debugging Tools for Windows, with links to presentations and papers on best practices</td>
</tr>
</tbody>
</table>
<strong>Debugger How-Tos</strong>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_text.gif" border="0" alt="White Paper" title="icon text windows" /></td>
<td align="left" valign="top"><a href="http://www.microsoft.com/whdc/driver/tips/debug_vista.mspx#">Driver Tip: Debugging Windows Vista</a><img src="http://www.microsoft.com/whdc/images/shared/common/space.gif" border="0" alt="Debugging Tools for Windows" width="1" height="1" title="space windows" /></td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_text.gif" border="0" alt="White Paper" title="icon text windows" /></td>
<td align="left" valign="top"><a href="http://www.microsoft.com/whdc/devtools/debugging/debugtips.mspx">Improve Driver Debugability</a><img src="http://www.microsoft.com/whdc/images/shared/common/space.gif" border="0" alt="Debugging Tools for Windows" width="1" height="1" title="space windows" /></td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_powerpoint.gif" border="0" alt="Microsoft Powerpoint (.ppt)" title="icon powerpoint windows" /></td>
<td align="left" valign="top"><a href="http://download.microsoft.com/download/1/8/f/18f8cee2-0b64-41f2-893d-a6f2295b40c8/DW04001_WINHEC2004.ppt">1394 Kernel Debugging Tips and Tricks [WinHEC 2004; 373 KB]</a><img src="http://www.microsoft.com/whdc/images/shared/common/space.gif" border="0" alt="Debugging Tools for Windows" width="1" height="1" title="space windows" /></td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_powerpoint.gif" border="0" alt="Microsoft Powerpoint (.ppt)" title="icon powerpoint windows" /></td>
<td align="left" valign="top"><a href="http://download.microsoft.com/download/f/0/5/f05a42ce-575b-4c60-82d6-208d3754b2d6/Adv-Drv_Debug.ppt">Advanced Driver Debugging [336 KB]</a><img src="http://www.microsoft.com/whdc/images/shared/common/space.gif" border="0" alt="Debugging Tools for Windows" width="1" height="1" title="space windows" /></td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_powerpoint.gif" border="0" alt="Microsoft Powerpoint (.ppt)" title="icon powerpoint windows" /></td>
<td align="left" valign="top"><a href="http://download.microsoft.com/download/a/f/d/afdfd50d-6eb9-425e-84e1-b4085a80e34e/DVR-T410_WH07.pptx">Driver Debugging Basics [WinHEC 2007; 633 KB]</a><img src="http://www.microsoft.com/whdc/images/shared/common/space.gif" border="0" alt="Debugging Tools for Windows" width="1" height="1" title="space windows" /></td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_nod.gif" border="0" alt="WHDC Portal/Nodal" title="icon nod windows" /></td>
<td align="left" valign="top"><a href="http://www.microsoft.com/whdc/devtools/debugging/kmdf.mspx">Debugging Kernel-Mode Driver Framework Drivers</a><img src="http://www.microsoft.com/whdc/images/shared/common/space.gif" border="0" alt="Debugging Tools for Windows" width="1" height="1" title="space windows" /></td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_nod.gif" border="0" alt="WHDC Portal/Nodal" title="icon nod windows" /></td>
<td align="left" valign="top"><a href="http://www.microsoft.com/whdc/devtools/debugging/umdftraining.mspx">Debugging User-Mode Driver Framework Drivers Training Sessions</a><img src="http://www.microsoft.com/whdc/images/shared/common/space.gif" border="0" alt="Debugging Tools for Windows" width="1" height="1" title="space windows" /></td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_ms.gif" border="0" alt="Microsoft.com" title="icon ms windows" /></td>
<td align="left" valign="top"><a href="http://msdn.microsoft.com/en-us/library/cc267445.aspx" target="_blank">Debugging Tools for Windows (MSDN)</a><img src="http://www.microsoft.com/whdc/images/shared/common/space.gif" border="0" alt="Debugging Tools for Windows" width="1" height="1" title="space windows" /></td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_ms.gif" border="0" alt="Microsoft.com" title="icon ms windows" /></td>
<td align="left" valign="top"><a href="http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q314743" target="_blank">HOWTO: Enable Verbose Debug Tracing in Various Drivers and Subsystems (314743)</a><img src="http://www.microsoft.com/whdc/images/shared/common/space.gif" border="0" alt="Debugging Tools for Windows" width="1" height="1" title="space windows" /></td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_ms.gif" border="0" alt="Microsoft.com" title="icon ms windows" /></td>
<td align="left" valign="top"><a href="http://msdn.microsoft.com/en-us/library/ms797165.aspx" target="_blank">WDK Online: Tools for Debugging Drivers</a><img src="http://www.microsoft.com/whdc/images/shared/common/space.gif" border="0" alt="Debugging Tools for Windows" width="1" height="1" title="space windows" /></td>
</tr>
</tbody>
</table>
<strong>Resources</strong>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_text.gif" border="0" alt="White Paper" title="icon text windows" /></td>
<td align="left" valign="top"><a href="http://www.microsoft.com/whdc/DevTools/WDK/WDKdocs.mspx#">WDK Documentation Download</a><img src="http://www.microsoft.com/whdc/images/shared/common/space.gif" border="0" alt="Debugging Tools for Windows" width="1" height="1" title="space windows" /></td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_nod.gif" border="0" alt="WHDC Portal/Nodal" title="icon nod windows" /></td>
<td align="left" valign="top"><a href="http://www.microsoft.com/whdc/resources/default.mspx">Driver Developer Community Resources</a><img src="http://www.microsoft.com/whdc/images/shared/common/space.gif" border="0" alt="Debugging Tools for Windows" width="1" height="1" title="space windows" /></td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_nod.gif" border="0" alt="WHDC Portal/Nodal" title="icon nod windows" /></td>
<td align="left" valign="top"><a href="http://www.microsoft.com/whdc/winlogo/drvsign/drvsign.mspx">Driver Signing Requirements for Windows</a><img src="http://www.microsoft.com/whdc/images/shared/common/space.gif" border="0" alt="Debugging Tools for Windows" width="1" height="1" title="space windows" /></td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_nod.gif" border="0" alt="WHDC Portal/Nodal" title="icon nod windows" /></td>
<td align="left" valign="top"><a href="http://www.microsoft.com/whdc/driver/foundation/DevNotes.mspx">Notes from Windows Development Teams</a><img src="http://www.microsoft.com/whdc/images/shared/common/space.gif" border="0" alt="Debugging Tools for Windows" width="1" height="1" title="space windows" /></td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_nod.gif" border="0" alt="WHDC Portal/Nodal" title="icon nod windows" /></td>
<td align="left" valign="top"><a href="http://www.microsoft.com/whdc/devtools/toolsupport.mspx">Support for Developer Kits and Tools</a><img src="http://www.microsoft.com/whdc/images/shared/common/space.gif" border="0" alt="Debugging Tools for Windows" width="1" height="1" title="space windows" /></td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_other.gif" border="0" alt="Other" title="icon other windows" /></td>
<td align="left" valign="top"><a href="http://www.microsoft.com/whdc/resources/blogs.mspx">Driver Developer Blogs</a><img src="http://www.microsoft.com/whdc/images/shared/common/space.gif" border="0" alt="Debugging Tools for Windows" width="1" height="1" title="space windows" /></td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_other.gif" border="0" alt="Other" title="icon other windows" /></td>
<td align="left" valign="top"><a href="http://www.microsoft.com/whdc/devtools/wdk/RelNotesW7.mspx">Windows Driver Kit (WDK) Version 7.1.0 Release Notes</a> <img src="http://www.microsoft.com/whdc/images/fileType/new.gif" border="0" alt="Debugging Tools for Windows"  title="new windows" /></td>
</tr>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_ms.gif" border="0" alt="Microsoft.com" title="icon ms windows" /></td>
<td align="left" valign="top"><a href="http://msdn.microsoft.com/en-us/library/aa972908.aspx#" target="_blank">WDK Documentation on MSDN</a> <img src="http://www.microsoft.com/whdc/images/fileType/new.gif" border="0" alt="Debugging Tools for Windows"  title="new windows" /></td>
</tr>
</tbody>
</table>
<strong>See Also</strong>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="16" height="19" align="left" valign="top"><img src="http://www.microsoft.com/whdc/images/fileType/icon_ms.gif" border="0" alt="Microsoft.com" title="icon ms windows" /></td>
<td align="left" valign="top"><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c4a25ab9-649d-4a1b-b4a7-c9d8b095df18&amp;displaylang=en" target="_blank">Microsoft Application Verifier</a><img src="http://www.microsoft.com/whdc/images/shared/common/space.gif" border="0" alt="Debugging Tools for Windows" width="1" height="1" title="space windows" /></td>
</tr>
</tbody>
</table>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<!---->
<h4>Additional Tools and Utilities</h4>
Debugging Tools for Windows also includes the following tools and utilities:

<dl> <dt>Logger  (<em>Logger.exe</em> and <em>Logexts.dll</em>)</dt> <dd>A tool and an extension DLL that record the function calls and other actions of a program. Logger is described in this documentation; see <a id="ctl00_MTCS_main_ctl03" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl03',this);" href="http://msdn.microsoft.com/en-us/library/cc266303.aspx">Logger and LogViewer</a>.</dd> <dt>LogViewer  (<em>Logviewer.exe</em>)</dt> <dd>A tool that displays the logs created by Logger. LogViewer is described in this documentation; see <a id="ctl00_MTCS_main_ctl04" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl04',this);" href="http://msdn.microsoft.com/en-us/library/cc266303.aspx">Logger and LogViewer</a>.</dd> <dt>ADPlus  (Autodump+, <em>Adplus.vbs</em>)</dt> <dd>A console-based Microsoft Visual Basic script that can automatically create memory dump files and log files with debug output from one or more processes. ADPlus is described in this documentation; see <a id="ctl00_MTCS_main_ctl05" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl05',this);" href="http://msdn.microsoft.com/en-us/library/cc265629.aspx">ADPlus</a>.</dd> <dt>DbgRpc  (<em>Dbgrpc.exe</em>)</dt> <dd>A tool used to display Microsoft Remote Procedure Call (RPC) state information. DbgRpc is described in this documentation; see <a id="ctl00_MTCS_main_ctl06" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl06',this);" href="http://msdn.microsoft.com/en-us/library/cc267800.aspx">RPC Debugging</a> and <a id="ctl00_MTCS_main_ctl07" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl07',this);" href="http://msdn.microsoft.com/en-us/library/cc267804.aspx">Using the DbgRpc Tool</a>.</dd> <dt>KDbgCtrl  (Kernel Debugging Control, <em>Kdbgctrl.exe</em>)</dt> <dd>A tool that controls and configures the kernel debugging connection. KDbgCtrl is described in this documentation; see <a id="ctl00_MTCS_main_ctl08" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl08',this);" href="http://msdn.microsoft.com/en-us/library/cc501182.aspx">Using KDbgCtrl</a>.</dd> <dt>SrcSrv  (<em>Srcsrv.dll</em>)</dt> <dd>A source server that can be used to deliver source files while debugging. SrcSrv is described in this documentation; see <a id="ctl00_MTCS_main_ctl09" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl09',this);" href="http://msdn.microsoft.com/en-us/library/cc901440.aspx">SrcSrv</a>. </dd> <dt>SymSrv  (<em>Symsrv.dll</em>)</dt> <dd>A symbol server that the debugger can use to connect to a symbol store. SymSrv is described in this documentation; see <a id="ctl00_MTCS_main_ctl10" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl10',this);" href="http://msdn.microsoft.com/en-us/library/cc266470.aspx">SymSrv</a>.</dd> <dt>SymStore  (<em>Symstore.exe</em>)</dt> <dd>A tool used to create a symbol store. SymSrv is described in this documentation; see <a id="ctl00_MTCS_main_ctl11" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl11',this);" href="http://msdn.microsoft.com/en-us/library/cc266480.aspx">Using SymStore</a>.</dd> <dt>SymProxy</dt> <dd>A tool used to create a single HTTP symbol server on your network that all your debuggers can point to. This has the benefit of pointing to multiple symbol servers (both internal and external) with a single symbol path, handling all authentication, and increasing performance via symbol caching. SymProxy is described in this documentation; see <a id="ctl00_MTCS_main_ctl12" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl12',this);" href="http://msdn.microsoft.com/en-us/library/cc901417.aspx">SymProxy</a>. </dd> <dt>AgeStore  (<em>Agestore.exe</em>)</dt> <dd>A tool that removes old entries in the <a id="ctl00_MTCS_main_ctl13" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl13',this);" href="http://msdn.microsoft.com/en-us/library/cc265785.aspx#ac594c2f-1bc6-4ee9-a628-bc146d313672">downstream store</a> of a symbol server or a source server. AgeStore is described in this documentation; see <a id="ctl00_MTCS_main_ctl14" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl14',this);" href="http://msdn.microsoft.com/en-us/library/cc501193.aspx">AgeStore</a>.</dd> <dt>DBH  (<em>Dbh.exe</em>)</dt> <dd>A tool that displays information about the contents of a symbol file. DBH is described in this documentation; see <a id="ctl00_MTCS_main_ctl15" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl15',this);" href="http://msdn.microsoft.com/en-us/library/cc501201.aspx">DBH</a>.</dd> <dt>PDBCopy  (<em>Pdbcopy.exe</em>)</dt> <dd>A tool that removes private symbol information from a symbol file, and controls which public symbols are included in the file. PDBCopy is described in this documentation; see <a id="ctl00_MTCS_main_ctl16" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl16',this);" href="http://msdn.microsoft.com/en-us/library/cc501196.aspx">PDBCopy</a>.</dd> <dt>DumpChk  (Dump File Checking Utility, <em>Dumpchk.exe</em>)</dt> <dd>A tool used to validate a memory dump file. DumpChk is described in this documentation; see <a id="ctl00_MTCS_main_ctl17" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl17',this);" href="http://msdn.microsoft.com/en-us/library/cc901388.aspx">DumpChk</a>. </dd> <dt>DbgSrv  (<em>Dbgsrv.exe</em>)</dt> <dd>A process server used for remote debugging. DbgSrv is described in this documentation; see <a id="ctl00_MTCS_main_ctl18" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl18',this);" href="http://msdn.microsoft.com/en-us/library/cc266423.aspx">Process Servers (User Mode)</a>.</dd> <dt>KdSrv  (<em>Kdsrv.exe</em>)</dt> <dd>A KD connection server used for remote debugging. KDSrv is described in this documentation; see <a id="ctl00_MTCS_main_ctl19" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl19',this);" href="http://msdn.microsoft.com/en-us/library/cc266454.aspx">KD Connection Servers (Kernel Mode)</a>.</dd> <dt>DbEngPrx  (<em>Dbengprx.exe</em>)</dt> <dd>A repeater (small proxy server) used for remote debugging. DbgSrv is described in this documentation; see <a id="ctl00_MTCS_main_ctl20" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl20',this);" href="http://msdn.microsoft.com/en-us/library/cc266428.aspx">Repeaters</a>.</dd> <dt><!----></dt> <dd><!----></dd> <dt><!----></dt> <dd><!----></dd> <dt>The Remote tool  (<em>Remote.exe</em>)</dt> <dd>A remoting tool that can be used to remotely control any console program, including KD, CDB, and NTSD. The Remote tool is described in this documentation; see <a id="ctl00_MTCS_main_ctl21" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl21',this);" href="http://msdn.microsoft.com/en-us/library/cc267440.aspx">Remote Tool</a> and <a id="ctl00_MTCS_main_ctl22" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl22',this);" href="http://msdn.microsoft.com/en-us/library/cc266442.aspx">Remote Debugging Through <em>Remote.exe</em></a>.</dd> <dt>GFlags  (Global Flags Editor, <em>Gflags.exe</em>)</dt> <dd>A tool used to control registry keys and other settings. GFlags is described in this documentation; see <a id="ctl00_MTCS_main_ctl23" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl23',this);" href="http://msdn.microsoft.com/en-us/library/cc265942.aspx">GFlags</a>.</dd> <dt>The Kill tool  (<em>Kill.exe</em>)</dt> <dd>A tool used to terminate a process. The Kill tool is described in this documentation; see <a id="ctl00_MTCS_main_ctl24" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl24',this);" href="http://msdn.microsoft.com/en-us/library/cc266299.aspx">Kill Tool</a>.</dd> <dt>The Breakin tool  (<em>Breakin.exe</em>)</dt> <dd>A tool used to cause a user-mode break to occur in a process. <em>Breakin.exe</em> is not described in this documentation. Use the <strong>breakin /?</strong> command for help with this tool.</dd> <dt>The List tool  (File List Utilit
y, <em>List.exe</em>)</dt> <dd><em>List.exe</em> is not described in this documentation. Use the <strong>list /?</strong> command for help with this tool. </dd> <dt>TList  (Task List Viewer, <em>Tlist.exe</em>)</dt> <dd>A tool used to list all running processes. TList is described in this documentation; see <a id="ctl00_MTCS_main_ctl25" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl25',this);" href="http://msdn.microsoft.com/en-us/library/cc267860.aspx">TList</a>.</dd> <dt>RTList  (Remote Task List Viewer, <em>Rtlist.exe</em>)</dt> <dd>A tool used to list running processes via a DbgSrv process server. RTList is not described in this documentation. Use the <strong>rtlist /?</strong> command for help with this tool. </dd> <dt>UMDH  (User-Mode Dump Heap utility, <em>Umdh.exe</em>)</dt> <dd>A tool used to analyze heap allocations. UMDH is described in this documentation; see <a id="ctl00_MTCS_main_ctl26" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl26',this);" href="http://msdn.microsoft.com/en-us/library/cc267868.aspx">UMDH</a>.</dd> <dt>USBView  (Universal Serial Bus Viewer, <em>Usbview.exe</em>)</dt> <dd>A tool used to display the USB devices connected to a computer. USBView is described in this documentation; see <a id="ctl00_MTCS_main_ctl27" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl27',this);" href="http://msdn.microsoft.com/en-us/library/cc748123.aspx">USBView</a>.</dd> </dl><!---->

If you peform a custom install of Debugging Tools for Windows and select the <strong>SDK</strong> feature and all of its subfeatures, the libraries, headers, and samples used to build debugger extensions will be installed.
<h4>Documentation</h4>
<dl> <dt>"Debugging Tools for Windows"  (<em>Debugger.chm</em>)</dt> <dd>This is the documentation you are currently reading. It is the central documentation for Debugging Tools for Windows.</dd> <dt>"Debug Help Library"  (<em>Dbghelp.chm</em>)</dt> <dd>This documentation describes the DbgHelp API and the ImageHlp API, and also explains how to create your own symbol server. <em>This is installed when you peform a custom install of Debugging Tools for Windows and select the <strong>SDK</strong> feature and its subfeatures.</em></dd> </dl><!---->
<h4>Tools Outside the Debugging Tools for Windows Package</h4>
The following related tools are not part of the Debugging Tools for Windows package:

<dl> <dt>Dr. Watson  (<em>Drwtsn32.exe</em>)</dt> <dd>A tool used for automatically creating dump files and sending error reports to Microsoft Online Crash Analysis (OCA). Dr. Watson is partially described in this documentation; see <a id="ctl00_MTCS_main_ctl28" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl28',this);" href="http://msdn.microsoft.com/en-us/library/cc265793.aspx">Dr. Watson</a>. The other features of Dr. Watson are described in the help file associated with <em>drwtsn32.exe</em>.</dd> <dt>Build utility  (<em>Build.exe</em>)</dt> <dd>A compiler and linker used to build debugger extensions and other programs. The Build utility and its documentation can be found in the Windows Driver Kit, and in earlier versions of the Windows DDK. </dd> <dt>BinPlace  (<em>Binplace.exe</em>)</dt> <dd>A tool used to control symbol files for build products. BinPlace and its documentation can be found in the Windows Driver Kit, and in earlier versions of the Windows DDK. </dd> <dt>Application Verifier  (<em>AppVerif.exe</em> and <strong>!avrf</strong>)</dt> <dd>A tool used to test user-mode applications. This tool consists of two components: the <em>AppVerif.exe</em> utility and the <strong>!avrf</strong> extension command. All the features of Application Verifier that are debugger-related are described in <!--src=[internet_link_sm.gif]--><img src="http://i.msdn.microsoft.com/Cc267862.internet_link_sm(en-us,MSDN.10).gif" alt="Debugging Tools for Windows"  title="Cc267862.internet link sm(en us,MSDN.10) windows" /><a id="ctl00_MTCS_main_ctl30" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl30',this);" href="http://go.microsoft.com/fwlink/?linkid=108353" target="_blank">Application Verifier</a>. The other features of Application Verifier are described in the help file associated with <em>AppVerif.exe</em>.</dd> </dl>
<div>Debugging Tools for Windows</div>
<div>WinDbg</div>
<!--Content type: PSDK_3. Transform: webcollection2mtps.xslt.-->
<div><!----></div>
<a id="r01_intro_eae4d594-1986-49f9-b8b1-87f7eeb0d513.xml"><!----></a>

Microsoft Windows Debugger (WinDbg) is a powerful Windows-based debugging tool. It is capable of both <a id="ctl00_MTCS_main_ctl01" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl01',this);" href="http://msdn.microsoft.com/en-us/library/cc265787.aspx#1a7518e7-05c9-4be8-baf0-63b4024f4e30">user-mode</a> and <a id="ctl00_MTCS_main_ctl02" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl02',this);" href="http://msdn.microsoft.com/en-us/library/cc265769.aspx#714fb29e-5a07-45f9-99e8-e3f319e69c2f">kernel-mode</a> debugging.

WinDbg provides full source-level debugging for the Windows kernel, kernel-mode drivers, and system services, as well as user-mode applications and drivers.

WinDbg uses the Microsoft Visual Studio debug symbol formats for source-level debugging. It can access any <a id="ctl00_MTCS_main_ctl03" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl03',this);" href="http://msdn.microsoft.com/en-us/library/cc265773.aspx#986a5629-886b-417b-a52e-7352511b0e35">symbol</a> or variable from a module that has PDB symbol files, and can access any public function's name that is exposed by <a id="ctl00_MTCS_main_ctl04" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl04',this);" href="http://msdn.microsoft.com/en-us/library/cc265774.aspx#c125f2f6-a5ce-419a-98de-c9331ca0e56d">modules</a> that were compiled with COFF symbol files (such as Windows <em>.dbg</em> files).

WinDbg can view source code, set <a id="ctl00_MTCS_main_ctl05" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl05',this);" href="http://msdn.microsoft.com/en-us/library/cc265776.aspx#0b1614a6-b26e-4079-8a25-381977fa2c44">breakpoints</a>, view variables (including C++ objects), stack traces, and memory. Its Debugger Command window allows the user to issue a wide variety of commands.

For kernel-mode debugging, WinDbg requires two machines (the <a id="ctl00_MTCS_main_ctl06" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl06',this);" href="http://msdn.microsoft.com/en-us/library/cc265783.aspx#77205ddc-d81d-483c-ab52-47eb6d613eac">host computer</a> and the <a id="ctl00_MTCS_main_ctl07" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl07',this);" href="http://msdn.microsoft.com/en-us/library/cc265771.aspx#592a23b6-7f7d-434c-b4f6-5e1470b41393">target computer</a>). Kernel debugging is only supported on NT-based Windows operating systems.

WinDbg also supports various remote debugging options for both user-mode and kernel-mode targets.

WinDbg is the graphical-interface counterpart to <a id="ctl00_MTCS_main_ctl08" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl08',this);" href="http://msdn.microsoft.com/en-us/library/cc266320.aspx">CDB</a> / <a id="ctl00_MTCS_main_ctl09" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl09',this);" href="http://msdn.microsoft.com/en-us/library/cc266320.aspx#f7997e21-d84a-4224-af71-bc393265af91">NTSD</a> and to <a id="ctl00_MTCS_main_ctl10" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl10',this);" href="http://msdn.microsoft.com/en-us/library/cc266319.aspx">KD</a>.
<div>Debugging Tools for Windows</div>
<div>KD</div>
<!--Content type: PSDK_3. Transform: webcollection2mtps.xslt.-->
<div><!----></div>
<a id="r01_intro_ad867058-949b-4093-abf6-c4363257a83d.xml"><!----></a>

Microsoft Kernel Debugger (KD) is a character-based console program that enables in-depth analysis of <a id="ctl00_MTCS_main_ctl01" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl01',this);" href="http://msdn.microsoft.com/en-us/library/cc265769.aspx#c2dfd7a9-249b-4018-9789-2b3d6268346b">kernel-mode</a> activity on all NT-based operating systems.

KD can be used to debug kernel-mode programs and drivers, or to monitor the behavior of the operating system itself. KD also supports multiprocessor debugging.

Typically, the KD tool will not be run on the computer being debugged. Two machines (the <a id="ctl00_MTCS_main_ctl02" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl02',this);" href="http://msdn.microsoft.com/en-us/library/cc265783.aspx#77205ddc-d81d-483c-ab52-47eb6d613eac">host computer</a> and the <a id="ctl00_MTCS_main_ctl03" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl03',this);" href="http://msdn.microsoft.com/en-us/library/cc265771.aspx#592a23b6-7f7d-434c-b4f6-5e1470b41393">target computer</a>) are needed for kernel-mode debugging.

Most KD commands cannot be targeted to specific processes or threads, as they can in <a id="ctl00_MTCS_main_ctl04" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl04',this);" href="http://msdn.microsoft.com/en-us/library/cc266320.aspx">CDB</a>, <a id="ctl00_MTCS_main_ctl05" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl05',this);" href="http://msdn.microsoft.com/en-us/library/cc266320.aspx#f7997e21-d84a-4224-af71-bc393265af91">NTSD</a>, and <a id="ctl00_MTCS_main_ctl06" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl06',this);" href="http://msdn.microsoft.com/en-us/library/cc266321.aspx">WinDbg</a>.
<h4>Debugging different target platforms</h4>
KD is capable of debugging a target computer which is running on an x86, Itanium, or x64 platform.

The debugger will automatically detect the platform on which the target is running. You do not need to specify the target on the KD command line. The older syntax (using the name <em>I386KD</em> or <em>IA64KD</em>) is obsolete.
<div>Debugging Tools for Windows</div>
<div>CDB and NTSD</div>
<!--Content type: PSDK_3. Transform: webcollection2mtps.xslt.-->
<div><!----></div>
<a id="r01_intro_d33cdade-c8d0-4a93-a626-d19ffa1df8b2.xml"><!----></a>

CDB and NTSD are console applications which can debug <a id="ctl00_MTCS_main_ctl01" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl01',this);" href="http://msdn.microsoft.com/en-us/library/cc265787.aspx#b9622678-468c-4b90-a002-a3d4280796f0">user-mode</a> <a id="ctl00_MTCS_main_ctl02" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl02',this);" href="http://msdn.microsoft.com/en-us/library/cc265771.aspx#997fd309-38d4-4217-9777-65e9f2af4377">programs</a>. These two debuggers are nearly identical, except in the manner in which they are launched.

This documentation will use "CDB" when referring to the capabilities of both CDB and NTSD. <em>Except as noted, all references to CDB in this documentation apply equally to NTSD</em>. There are a few techniques that can only work properly with CDB, or can only work properly with NTSD. These differences are documented in the appropriate sections.

<!---->

<!---->

<!---->
<h3><a id="f5cad0b2-b5ab-4d3d-a4ce-9d29bc7957df"><!----></a>CDB</h3>
Microsoft Console Debugger (CDB) is a character-based console program that enables low-level analysis of Windows user-mode memory and constructs.

CDB is extremely powerful for debugging a program that is currently running or has recently crashed ("live analysis"), yet simple to set up. It can be used to investigate the behavior of a working application. In the case of a failing application, CDB can be used to obtain a stack trace or to look at the guilty parameters. It works well across a network (using a remote access server), as it is character-based.

With CDB, you can display and execute program code, set <a id="ctl00_MTCS_main_ctl03" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl03',this);" href="http://msdn.microsoft.com/en-us/library/cc265776.aspx#0b1614a6-b26e-4079-8a25-381977fa2c44">breakpoints</a>, and examine and change values in memory. CDB can analyze binary code by "disassembling" it and displaying assembly instructions. It can also analyze source code directly.

Because CDB can access memory locations through addresses or global symbols, you can refer to data and instructions by name rather than by address, making it easy to locate and debug specific sections of code. You can also display disassembled machine code. CDB supports debugging multiple threads and processes. It is extensible, and can read and write both paged and non-paged memory.

If the target application is itself a console application, the target will share the console window with CDB. To spawn a separate console window for a target console application, use the <strong>-2</strong> <a id="ctl00_MTCS_main_ctl04" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl04',this);" href="http://msdn.microsoft.com/en-us/library/cc266523.aspx">command-line option</a>.

<!---->
<h3><a id="f7997e21-d84a-4224-af71-bc393265af91"><!----></a>NTSD</h3>
There is a variation of the CDB debugger named Microsoft NT Symbolic Debugger (NTSD). It is identical to CDB in every way, except that it spawns a new text window when it is started, whereas CDB inherits the Command Prompt window from which it was invoked.

Like CDB, NTSD is fully capable of debugging both console applications and graphical Windows programs. (The name "Console Debugger" is used to indicate the fact that CDB is classified as a console application; it does not imply that the target application must be a console application.)

Since the <strong>start</strong> command can also be used to spawn a new console window, the following two constructions will give the same results:

<strong>start cdb </strong><em>parameters</em>
<strong>ntsd </strong><em>parameters</em>
<h4>NTSD in the <em>System32</em> Directory</h4>
Whereas CDB is only available as part of the Debugging Tools for Windows package, NTSD is available both in this package and as part of the Windows system itself. It can be found in the <em>system32</em> directory of Windows.

If you are planning on using the NTSD that appears in the <em>system32</em> directory, there are two important facts you should be aware of:
<ul>
	<li>This version of NTSD cannot be used for <a id="ctl00_MTCS_main_ctl05" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl05',this);" href="http://msdn.microsoft.com/en-us/library/cc266458.aspx">Remote Debugging Through the Debugger</a>.</li>
	<li>This version of NTSD may not match the version of the documentation you are currently reading.</li>
</ul>
<!---->

To avoid these issues, it is recommended that you use only the version of NTSD or CDB that was installed as part of the Debugging Tools for Windows package.
<h4>Controlling CDB or NTSD from the Kernel Debugger</h4>
It is possible to redirect the input and output from CDB or NTSD so that it can be controlled from a kernel debugger (either KD or WinDbg).

If this technique is used with CDB, the CDB window will appear but will not be useable for input and output. If this is used with NTSD, no console window will appear at all.

Controlling NTSD from the kernel debugger is therefore especially useful, since it results in an extremely light-weight debugger that places almost no burden on the computer containing the target application. This combination can be used to debug system processes, shutdown, and the later stages of boot up. See <a id="ctl00_MTCS_main_ctl06" onclick="javascript:Track('ctl00_MTCS_main_ctl00|ctl00_MTCS_main_ctl06',this);" href="http://msdn.microsoft.com/en-us/library/cc266367.aspx">Controlling the User-Mode Debugger from the Kernel Debugger</a> for details.<p><a href="http://www.askapache.com/windows/debugging-tools.html"></a><a href="http://www.askapache.com/windows/debugging-tools.html">Debugging Tools for Windows</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/windows/debugging-tools.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Questions I Ask Web Hosting Companies, Before Buying</title>
		<link>http://www.askapache.com/hosting/before-buying-web-hosting.html</link>
		<comments>http://www.askapache.com/hosting/before-buying-web-hosting.html#comments</comments>
		<pubDate>Sun, 25 Apr 2010 10:15:16 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Hosting]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4419</guid>
		<description><![CDATA[<p>The following is a transcript of a chat I had with a company called tektonic, and at that time I was looking for a cheap linux host to use for some redundancy/failover operations.  I generally contact a new hosting company like this every few months.. I like to have options available in case of some kind of failure or network attack, so it's always a good idea to have a few ace linux servers in your back pocket.</p>
<p>If you've read any other articles on AskApache, you can see a certain obsession towards optimization, speed, and security -- so that is the purpose of the following questions.</p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/hosting/before-buying-web-hosting.html"></a><a href="http://www.askapache.com/hosting/before-buying-web-hosting.html"><cite>AskApache.com</cite></a></p><p>I'm always on the lookout for cheap hosting and great hosting companies, and being that I have done this for many years, on many platforms, and with many hosts, my only requirement is that the host uses a UNIX/BSD/LINUX operating system.  I'm just not one of those people who likes to do things the hard way, constantly, if its even possible on a non-nix, or one of those people who enjoys getting hacked or my sites defaced by a cracker.  So *nix is definitely a requirement.  This is just a current look at the basic idea I use when looking for a web host.  If you were smart you would do a whole lot more than this.</p>

<h2>Research the People</h2>
<p>Ok, in a web hosting company there are 5 distinct groups of people, at least generally, that you will want to get in contact with or at least do some background research on (like the owners/founders).  Depending on which of these groups you talk to will determine the amount and quality of information you get, the difference is night and day. Because of my past experience with really bad hosts (DreamHost), and really great hosts (<a rel="nofollow" href="http://www.wiredtree.com/298.html">WiredTree</a>), I am very cautious and purposeful in making this decision, so I go to great lengths to contact at least one person from each of these groups.  Most good advice says to also get in touch with customers.. I don't usually need/want to do that though because most customers don't know jack.  But of course I know a few of the customers because I research the hosts network block and test the speed and servers that run on their IP block.</p>

<h3>Who / Why</h3>
<p>Being a curious and inquisitive person by nature, I always do background research on who started the company, how they started it, and what skills they have.  Knowing who the owners are and if they are real unix/network experts or just snake oil salesmen really makes a difference in this world of smoke and mirrors.
<p> Here's my recommendation of which group to contact, in order of best to worst:</p>
<ol>
<li><strong>Owners/Founders</strong> - The Founders have been involved since the start of the company.  Always contact.</li>
<li><strong>System Admins</strong> - Programmers and System Operators who keep things running, fix problems tech support cant.  Always contact.</li>
<li><strong>Sales/Marketing</strong> - Both types have different motivations for what they say, and how they say it.  Always contact both.</li>
<li><strong>Tech Support</strong> - They make the web go round, will always know a lot about problems and issues their customers frequently experience.  Always contact.</li>
<li><strong>Management</strong> - These people are in charge of the day-to-day operations, overseers.  Contact optional.</li>
</ol>



<h2>Questions to Ask</h2>
<p>The following is a transcript of a chat I had with a company called <a href="http://tektonic.net/">tektonic</a>, and at that time I was looking for a cheap linux host to use for some redundancy/failover operations.  I generally contact a new hosting company like this every few months.. I like to have options available in case of some kind of failure or network attack, so it's always a good idea to have a few ace linux servers in your back pocket.</p>
<p>If you've read any other articles on AskApache, you can see a certain obsession towards optimization, speed, and security -- so that is the purpose of the following questions.</p>
<table cellspacing="0" cellpadding="5" border="1" width="100%" dir="ltr">
    <tbody>
        <tr>
            <td colspan="2"><div>General Info</div></td>
        </tr>
        <tr>
            <td><strong>Chat start time</strong></td>
            <td> Apr 7, 2010 7:18:07 AM EST</td>
        </tr>
        <tr>
            <td><strong>Chat end time</strong></td>
            <td> Apr 7, 2010 8:38:52 AM EST</td>
        </tr>
        <tr>
            <td><strong>Duration (actual chatting time)</strong></td>
            <td> 01:20:44</td>
        </tr>
        <tr>
            <td><strong>Operator</strong></td>
            <td> Vish</td>
        </tr>
    </tbody>
</table>
<h2>Chat Transcript</h2>
<div class="zebra3" style="font-size:1.1em;line-height:.9em;">

<blockquote>
    <p style="color:#ccc"><strong>info:</strong> Please wait for a site operator to respond. You are 1 out of 1 in the queue. The average wait time is 0 minutes and 30 seconds.</p>
    <p style="color:#ccc"><strong>info:</strong> You are now chatting with &#39;Vish&#39;</p>
    <p><strong>Vish:</strong> Hello</p>
    <p class="aa21"><strong>AskApache:</strong> Hi vish, i was looking to purchase a planwith you guys but had some questions.. is this the right place to ask?</p>
    <p><strong>Vish:</strong> yeah sure</p>
    <p><strong>Vish:</strong> Let me know how may I assist you with ?</p>
    <p class="aa21"><strong>AskApache:</strong> what is your cheapest plan that includes ssh?</p>
    <p><strong>Vish:</strong> <a href="http://tektonic.net/vps.php">http://tektonic.net/vps.php</a></p>
    <p><strong>Vish:</strong> Linux-360</p>
    <p class="aa21"><strong>AskApache:</strong> im there.. </p>
    <p><strong>Vish:</strong> It is cheapest plan you can have</p>
    <p class="aa21"><strong>AskApache:</strong> what does full root access mean for you guys? </p>
    <p class="aa21"><strong>AskApache:</strong> do you have swap? jailshell?</p>
    <p><strong>Vish:</strong> you have full access of you server .</p>
    <p class="aa21"><strong>AskApache:</strong> including network interface device access? ie.. is it possible to setup virtual nics?</p>
    <p><strong>Vish:</strong> Sorry we do not provide it.</p>
    <p><strong>Vish:</strong> hold on </p>
    <p><strong>Vish:</strong> Let me check</p>
    <p class="aa21"><strong>AskApache:</strong> how can i find out more about the limits of the machine for the Linux-360?</p>
    <p class="aa21"><strong>AskApache:</strong> like how many processes, fd descriptors.. </p>
    <p><strong>Vish:</strong> You can mail us at sales department.</p>
    <p><strong>Vish:</strong> They will get back to you with in few hrs with your answers </p>
    <p><strong>Vish:</strong> You can just drop mail at <a href="mailto:sales@tektonic.net">sales@tektonic.net</a></p>
    <p class="aa21"><strong>AskApache:</strong> no thanks.</p>
    <p class="aa21"><strong>AskApache:</strong> jw if you had that info offhand.</p>
    <p class="aa21"><strong>AskApache:</strong> do you know if cpanel is optinoal?</p>
    <p class="aa21"><strong>AskApache:</strong> could it be uninstalled?</p>
    <p><strong>Vish:</strong> yeah</p>
    <p><strong>Vish:</strong> you can install or uninstall as you wish </p>
    <p class="aa21"><strong>AskApache:</strong> Thanks vish you are being very helpful... a few more.. </p>
    <p><strong>Vish:</strong> sure</p>
    <p class="aa21"><strong>AskApache:</strong> what operating system?</p>
    <p><strong>Vish:</strong> Hold on ..</p>
    <p><strong>Vish:</strong> allow me a moment. </p>
    <p class="aa21"><strong>AskApache:</strong> please take your time</p>
    <p><strong>Vish:</strong> We do provide Ubantu , Centos and Debian</p>
    <p><strong>Vish:</strong> You can reinstall your server any time with one click </p>
    <p class="aa21"><strong>AskApache:</strong> what devices are supported in /dev ?</p>
    <p class="aa21"><strong>AskApache:</strong> do you support loop devices, ramdisk/tmpfs/swap?</p>
    <p><strong>Vish:</strong> One moment please..</p>
    <p class="aa21"><strong>AskApache:</strong> no rush at all, thanks</p>
    <p><strong>Vish:</strong> We do provide tmpfs but ramdisk and swap is not available .</p>
    <p><strong>Vish:</strong> All basic device are available with us optional devices like TUN is also enabled for you automatically. </p>
    <p class="aa21"><strong>AskApache:</strong> sweet</p>
    <p class="aa21"><strong>AskApache:</strong> is ipv6 supported?</p>
    <p><strong>Vish:</strong> It is there but we do support currently .</p>
    <p><strong>Vish:</strong> We are thinking to provide it in near future for our clients ;)</p>
    <p class="aa21"><strong>AskApache:</strong> good idea, people will start using it in 5years or so.. maybe</p>
    <p class="aa21"><strong>AskApache:</strong> how is the internal network segmented? vlans? </p>
    <p class="aa21"><strong>AskApache:</strong> for security..</p>
    <p><strong>Vish:</strong> Yeah, We do have Vlans</p>
    <p class="aa21"><strong>AskApache:</strong> security is very crucial.</p>
    <p><strong>Vish:</strong> You can check  more info in network here <a href="http://tektonic.net/network.php">network</a></p>
    <p class="aa21"><strong>AskApache:</strong> ok thanks brb</p>
    <p class="aa21"><strong>AskApache:</strong> do you allow kernel modules? or reloading the kernel like kexec?</p>
    <p><strong>Vish:</strong> a moment please.</p>
    <p><strong>Vish:</strong> What type kernel module you are looking for exactly ?</p>
    <p><strong>Vish:</strong> kexex is  for fast reboot .</p>
    <p><strong>Vish:</strong> Is there any specific requirement ?</p>
    <p><strong>Vish:</strong> As we do not allow kernel modules on VPS they are not supported by virtuzzo. </p>
    <p class="aa21"><strong>AskApache:</strong> ok.. so far so good. let me think a minute.</p>
    <p class="aa21"><strong>AskApache:</strong> what kind of failovers do you have? </p>
    <p class="aa21"><strong>AskApache:</strong> like if a machine fails to reboot or goes offline</p>
    <p><strong>Vish:</strong> we do not provide failover services for vpses at this time. You  will have power panel in hand using it you can reboot or reinstall your machine in one click. You can reach us 24*7 for live support.</p>
    <p class="aa21"><strong>AskApache:</strong> one problem that I&#39;ve seen on other vps&#39;s is sometimes a vps upon reboot fails to recognize the network interface/fails to connect to the web.. When that happens we are unable to ssh into the box to fix the problem and rely on support.. is this something that would be easy/normal for your support (to have to manually login to the vps locally)</p>
    <p><strong>Vish:</strong> There are the possiblities for the issue so we need to check in server but you can reach us anytime for live chat and ticket system.</p>
    <p><strong>Vish:</strong> as you are on live chat right now ;)</p>
    <p class="aa21"><strong>AskApache:</strong> so your support does have access to the vps locally? </p>
    <p class="aa21"><strong>AskApache:</strong> in case the network is down due to vps errors</p>
    <p><strong>Vish:</strong> Yes, We have the access</p>
    <p class="aa21"><strong>AskApache:</strong> do you run any packet filtering on the network or is this controlled solely with the vps?</p>
    <p class="aa21"><strong>AskApache:</strong> like iptables stuff.. switch/router filtering beyond defaults..</p>
    <p><strong>Vish:</strong> No , we dont have packet filtering the port we block is IRC only.</p>
    <p class="aa21"><strong>AskApache:</strong> great</p>
    <p><strong>Vish:</strong> I&#39;m sorry for the delay. I&#39;ll be right with you.</p>
    <p><strong>Vish:</strong> Is there anything else I may assist you with ?</p>
    <p class="aa21"><strong>AskApache:</strong> no problem, you&#39;ve answered all my questions so far.. trying to think of anything else I&#39;d like to know before buying.. </p>
    <p><strong>Vish:</strong> Sure</p>
    <p><strong>Vish:</strong> Is there anything else I can help you with ?</p>
    <p class="aa21"><strong>AskApache:</strong> Does the Linux-360 support filesystems? what storage devices are included (usually just 1 ext2/3/4 fs for vps).. Is it possible to repartition the drive? </p>
    <p class="aa21"><strong>AskApache:</strong> Oh and the other kernel module I would love to have on a vps is fuse so that I can mount remote filesystems (such as sshfs or nbd)</p>
    <p><strong>Vish:</strong> We do not provide kernel modules on VPS.</p>
    <p class="aa21"><strong>AskApache:</strong> do you allow kernel compilation? (that way i can build the module statically into the kernel) </p>
    <p><strong>Vish:</strong> A moment please.</p>
    <p><strong>Vish:</strong> We do not allow kernel compilation on VPS.</p>
    <p class="aa21"><strong>AskApache:</strong> ok, thats smart security</p>
    <p class="aa21"><strong>AskApache:</strong> what about the linux-360 partitioning question?</p>
    <p><strong>Vish:</strong> Thanks. :)</p>
    <p><strong>Vish:</strong> it is tmpfs on VPS</p>
    <p><strong>Vish:</strong> and we dot allow repartition.</p>
    <p class="aa21"><strong>AskApache:</strong> which is ultimately mounted on.. filesystems? like could I modify an ext3 / to ext4 or reiserfs?</p>
    <p class="aa21"><strong>AskApache:</strong> expected.. ok</p>
    <p><strong>Vish:</strong> No, it is vzfs</p>
    <p class="aa21"><strong>AskApache:</strong> even better.</p>
    <p class="aa21"><strong>AskApache:</strong> thats what i mostly use.</p>
    <p><strong>Vish:</strong> great</p>
    <p class="aa21"><strong>AskApache:</strong> What vps os install images do you use? like where do you get the CentOS/Ubuntu/Debian vps images? And are they modified/customized by you guys in any way?</p>
    <p class="aa21"><strong>AskApache:</strong> Or just all defaults?</p>
    <p><strong>Vish:</strong> they include basic services such as httpd, sendmail</p>
    <p class="aa21"><strong>AskApache:</strong> sorry for all the q&#39;s ... I wasn&#39;t thinking that I&#39;d actually find a good host to purchase, but so far tek is looking really good.. might go ahead within the hour.</p>
    <p><strong>Vish:</strong> otherwise default </p>
    <p><strong>Vish:</strong> We get it from parallels</p>
    <p><strong>Vish:</strong> Okay great.</p>
    <p><strong>Vish:</strong> Is there anything else I can help you with ?</p>
    <p class="aa21"><strong>AskApache:</strong> like: <a href="http://download.openvz.org/template/precreated/">http://download.openvz.org/template/precreated/</a></p>
    <p class="aa21"><strong>AskApache:</strong> do you use templates like that.. </p>
    <p><strong>Vish:</strong> We get it  from parallels</p>
    <p class="aa21"><strong>AskApache:</strong> how many employees do you have? how many customers? </p>
    <p><strong>Vish:</strong> Sorry, We do not disclose this information</p>
    <p class="aa21"><strong>AskApache:</strong> thats fine.. </p>
    <p><strong>Vish:</strong> For more you can contact sales department.</p>
    <p><strong>Vish:</strong> You are on technical department live chat.</p>
    <p class="aa21"><strong>AskApache:</strong> can you give me more info on what type of parallels products you utilize? </p>
    <p class="aa21"><strong>AskApache:</strong> I wouldn&#39;t last long on any other chat.. ;)</p>
    <p class="aa21"><strong>AskApache:</strong> I&#39;m curious so if it&#39;s a template/container I haven&#39;t used before I can test it out on my own machine.</p>
    <p><strong>Vish:</strong> We provide power panel from parallels</p>
    <p class="aa21"><strong>AskApache:</strong> i mean like the templates/container versions you use.. I want to check that you use updated/new versions and are valid licensed.</p>
    <p><strong>Vish:</strong> you mean OS version ?</p>
    <p class="aa21"><strong>AskApache:</strong> basically, do you know if you use the latest available os images from parallels.. </p>
    <p class="aa21"><strong>AskApache:</strong> and I will let you go with that.. </p>
    <p style="color:#ccc"><strong>info:</strong> Your chat transcript will be sent to your email at the end of your chat.</p>
    <p><strong>Vish:</strong> Yes , We do provide latest OS version as per requirement. </p>
    <p class="aa21"><strong>AskApache:</strong> thank you vish, you&#39;ve been most helpful. I am going to do a little more digging online about you guys and will probably be back with a couple questions.. cya around, have an awesome day</p>
</blockquote>
</div>

<h2>Hosts used by AskApache.com</h2>
<p><a rel="nofollow" href="http://www.wiredtree.com/298.html">WiredTree</a> is the main hosting company that I mainly use for this site and my business.  It took me 10+ years of trial and error before I found them, you can believe I will be posting alot more about them on this site, stay tuned.  I also use <a rel="nofollow" href="http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=askapache">HostGator</a>, and several other dependable nix hosts that are dirt cheap.</p>

<h2>Finding A Host</h2>
<p>I used to spend days and weeks googling for a host that wouldn't end up burning me later, oh that really sucked.  Now I use a site developed by a colleague of mine, <a href="http://www.webhostingsearch.com/">Web Hosting Search</a> as it lets me fairly quickly find a linux host with my bare requirements.  From THERE is when I start my own research.  This includes email and followups on the phone, visiting wiki's, googling owners, sneaking around in customer areas, etc..</p>



<h2>Who do you Use?</h2>
<p>I'd love to hear about anyone's experiences with specific hosts, recommendations especially!</p><p><a href="http://www.askapache.com/hosting/before-buying-web-hosting.html"></a><a href="http://www.askapache.com/hosting/before-buying-web-hosting.html">Questions I Ask Web Hosting Companies, Before Buying</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/hosting/before-buying-web-hosting.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

