TechnicalArchitectureWorx

The (Unofficial) ITWorx Technical Architecture Blog

Archive for May, 2007

Cygwin NFS Server HOWTO

Posted by archworx on May 31, 2007

This document shows how to install a minimal Cygwin enviroment to host an NFS server.

If you’re using Windows XP, be sure to check out the last sections on firewall and network device problems before you try testing your configuration.
Please read the official documentation first

Things often change in the Cygwin project .After installing Cygwin and the nfs-server (see below) you will find the documentation here:
/usr/share/doc/Cygwin/nfs-server-x.y.z.README

You need a directory for the Cygwin installation.
c:\Cygwin

You will also need a place to archive the Cygwin packages. This should be where you keep other installers. For this example, we create the directory:
e:\CygwinInstaller

Enter this string in your browser’s address bar:

http://www.cygwin.com/setup.exe

Download the installer (setup.exe) to:
e:\CygwinInstaller

Now run the setup.exe program. Press Next on the splash window and select
Install from Internet

Press Next.
Your root directory should be:
c:\Cygwin

Select: “Install For: All Users”
Select: “Default Text File Type: Unix”
Press Next.
Specify your local package directory: (for example)
e:\CygwinInstaller

Press Next. Select: “Direct Connection” Press Next.

Choosing a mirror is tricky. You want to find a fast one. I’ve had good luck with:

http://cygwin.get-software.com

Press Next.
A list of packages will rapidly appear in the setup window.

Installing extra packages

Several packages are needed beyond the default installation. If you’ve been messing around, press the “View” button repeatedly to cycle through to the “Category” view.

Adding vim:
Click on the + sign next to the Editors category. Scroll down to find the “vim” item and click on the word “Skip.” Each time you click in this area, the text will change, scrolling through the available versions of the package. Often, it is a good idea to select the most recent version of the package. For example, “6.2-3″. The box in the “Bin?” column should be checked automatically.

Or you can add mono
A powerlfull but much simpler text editor because anybody who are not familiar with vi editor will probably face some dificulties :)
Click on the + sign next to the Editors category. Scroll down to find the “mono” item and click on the word “Skip.”

Adding nfs-server:
Click on the + sign next to the Net category. Scroll down to find the nfs-server item and click on the word “Skip” so it becomes “Install.” Select a recent version of the package. Note: The nfs-server is fairly new, so if you don’t see it in the Net category, back out and try a different Cygwin server.

Adding sunrpc:
This component is found in the Libs category. Scroll down to find the sunrpc item and click on the word “Skip” until it becomes “Install.” Select a recent version of the package.

Adding cygrunsrv:
This utility lets you configure the nfs server as a Windows system service. Click on the + sign next to the Admin category. Scroll down to find the cygrunsrv item and click on the word “Skip”. Select a recent version of the package.

Press Next.
All your packages as well as any packages they require will be downloaded and installed.
Configuring the server

Run the configuration script

In the cygwin shell window, run:
/usr/bin/nfs-server-config

A number of warnings will appear about you installing cygwin for a single user, even though you didn’t. You can ignore these complaints.

Editing the configuration files

You probably need to learn the “vi” editor so you can easily create or modify Cygwin configuration files without installing all of X-Windows to support a GUI editor. You will be annoyed if this is your first exposure to vi. Give in. Learn it. It Is Your Destiny.

Otherwise, use Notepad and find some way to convert from windows to unix text format. (Try the drag-n-drop programs uf2d and df2u.)

Host access control files

If you perform the installation of cygwin as described above, you will not need to edit /etc/hosts.allow or /etc/hosts.deny. If you have installed tcp-wrappers by accident or because you decided to install everything, you will need to edit them:

Edit:
/etc/hosts.allow

To enable access by just one host:
nfsd: 148.150.62.152

To enable an entire subnet:
nfsd: 148.150.0.0/255.255.0.0

Edit
/etc/hosts.deny

Comment out any lines that appear in this file. It will be empty unless you have chosen to install other Cygwin network packages.

The hosts.allow and hosts.deny files support more complex authorization schemes. See “man hosts_acccess” and “man hosts_options” if you need more precise control.

Export directories

Edit:
/etc/exports

This is where you export local directories.

This example exports the /pub directory to everyone in the 148.150.62 subnet.
/pub 148.150.62.0/255.255.255.0(ro, no_root_squash)

The option “ro” means read-only. Use “rw” for read-write.

You cannot use the wildcard “*” in host numbers:
No: 148.150.62.*

You can use the wild card in host names:
Yes: *.mts.com

To use ip names, the name must be a real DNS name or it must in your /etc/hosts file.

Note: The Cygwin hosts file: /etc/hosts is actually a shortcut to your windows hosts file at:
c:\winnt\system32\drivers\etc\hosts

For some reason, nfs mounts are MUCH faster if you don’t authorize entire subnets. It is better to list specific hosts.

Per-user authorization

If the user and group numbers on the client machine match those of an authorized user on the server, access is allowed based on the privilages granted to the user on the server.

Note: You can only have users & permissions in Cygwin if you are using NTFS in windows. If you have FAT32, you must connect as root from the remote system.

The root account is special. Access is never allowed to remote root users unless the “no_root_squash” option is used (as shown in the example above.)

The easy way is to access the server from a client running as root and use the no_root_squash option.
Starting the server

Run:
Start Menu/Programs/Administrative Tools/Services

There are three services associated with NFS:
Cygwin mountd
Cygwin nfsd
Cygwin portmap

Right-click on each of these and use the pop-up menu to start all three servers. You will find that portmap starts automatically when you start either nfsd or mountd first. There is a dependency between system services that Windows tries to maintain automatically.

After editing any of the configuration files the /etc directory, you must restart these services. Because mountd and nfsd are configured to depend on portmap, it is sufficent to right-click on portmap and select “restart.” A dialog will appear to confirm that you also want to restart mountd and nfsd.
Mounting an nfs share on the client machine

The client machine in the following example is assumed to be a Linux or other Unix system. If you have a nice free NFS client for Windows, I’d like to hear about it so I can add a link on this page.

For this example, we assume that the NFS server running on your Windows machine has an ip name “remote” and an exported directory “/pub” defined under /etc/exports as shown above.

The name “remote” only has to be defined on the Linux/Unix client. You can define the name in /etc/hosts or just use the ip number of your Windows server in the following example.

Log into your client machine. You probably need to be “root” to mount the remote nfs directory.

Create a local directory:
mkdir /mnt/there

Mount the share:
mount -t nfs remote:/pub /mnt/there

You should now be able to poke around in /mnt/there, and see any files located in the “/pub” directory on the Cygwin/Windows side.

Important update: A reader of this HOWTO has discovered that CygwinNFS does not support NFS version 3, which is now the default in Linux. To overcome this problem you must add an option to the mount command line: “-overs=2″ The full command line becomes:
mount -t nfs -o nfsvers=2 remote:/pub /mnt/there

An alternative specification using “vers” also works on Linux and other Unix-like systems:
mount -t nfs -o vers=2 remote:/pub /mnt/there

(Thanks to Mr. Ostrozhansky!)
Exporting other Windows directories

If you run “mount” with no parameters in the cygwin shell, you will see a list of mounted directories.

The Windows root directories, c:\, d:\ etc will also appear in this list. They are accessed through the special path names /cygdrive/c, /cygdrive/d etc. If you visit the root “/” of cygwin, you will find that these mount points don’t actually exist. If you try to list them in the nfs /etc/exports file, they will fail to mount on the client system.

This is probably a bug, but there is a simple work-around:

Create a directory for each Windows volume you want to export and then mount them directly to the windows pathname:

Make directories to use as mount points:
mkdir -p /mnt/c
mkdir -p /mnt/d

Mount the windows directories:
mount c:/ /mnt/c
mount d:/ /mnt/d

Now you can export these directories in /etc/exports:
/mnt/c myClient.com(rw, no_root_squash)
/mnt/d myClient.com(rw, no_root_squash)

Don’t forget to restart the portmap service in Windows.

You may be worried about what happens to your mounts when you reboot windows: They are stored in the registry, rather than /etc/fstab. After a reboot, they are restored and they will be available to remote systems via NFS.

In fact, if you reboot windows when an nfs mount was created on a remote client, the mounted files will still be available after windows reboots.
Uninstalling Cygwin

Stop the services:
cygrunsrv –stop mountd
cygrunsrv –stop nfsd
cygrunsrv –stop portmap

Remove the services:
cygrunsrv –remove mountd
cygrunsrv –remove nfsd
cygrunsrv –remove portmap

If you use Cygwin to run other services such as X-Windows, you should stop these processes now.

Exit the shell and run the Cygwin setup.exe Use the “View” button repeatedly to cycle to the “Category” view, then click on the “Default” text next to category “All” to cycle through until you see Uninstall.

Press Next-> to remove everthing.

Cygwin is one of those programs that doesn’t really like to be uninstalled. To finish the job, delete everything in your c:\cygwin directory. You may find that you need to stop residual cygwin processes with the Task Damager before you can delete everthing in the Cygwin folder. Reboot if necessary.

Next, run Regedit and search for cygwin. Delete all the keys you find and any surrounding “Cygnus Solutions” folders.
Windows XP Issues

Many people report trouble running the NFS server under Windows XP. Since service pack 2, XP has a firewall which will block NFS connections by default.

A great thanks for Hugh Sparks who made this document.

http://www.csparks.com/CygwinNFS/index.xhtml

Posted in Bubly, Open Source | 4 Comments »

Test Driven Development (TDD)

Posted by archworx on May 27, 2007

One of the basics in eXtreme Programing (XP) is to test any code that might break. In an approach to make life easier, developers wrote tests before writing the actual code!!

“It’s about figuring out what you are trying to do before you run off half-cocked to try to do it. You write a specification that nails down a small aspect of behaviour in a concise, unambiguous, and executable form. It’s that simple. Does that mean you write tests? No. It means you write specifications of what your code will have to do. It means you specify the behaviour of your code ahead of time. But not far ahead of time. In fact, just before you write the code is best because that’s when you have as much information at hand as you will up to that point. Like well done TDD, you work in tiny increments… specifying one small aspect of behaviour at a time, then implementing it.” – Dave Astels

The development cycle in TDD is called Test-Code-Simplify, and it looks like the following:

(“Extreme Programming Applied“, p159)

  1. Write a single test
  2. Compile it. It shouldn’t compile, because you haven’t written the implementation code it calls
  3. Implement just enough code to get the test to compile
  4. Run the test and see it fail
  5. Implement just enough code to get the test to pass
  6. Run the test and see it pass
  7. Refactor for clarity and “once and only once”
  8. Repeat

Posted in El-Geish, Extreme Programming | 1 Comment »

Sharepoint String Limitations

Posted by archworx on May 24, 2007

Recently we have been conducting some investigations on constructing high powered dynamic applications in MOSS 2007, which connect a wide mesh of subsystems from a single entry point. During the analysis we found out that a lot of the data we needed to manipulate is rather large, so I asked some friends and was very pleased to find a very comprehensive list of size limitations on Sharepoint Strings summarized here:

http://www.sharepointblogs.com/marwantarek/archive/2007/03/25/sharepoint-2007-strings-maximum-limitations.aspx

Posted in mkaram, Sharepoint | Leave a Comment »

Edit and Continue

Posted by archworx on May 23, 2007

Source: http://msdn2.microsoft.com/en-us/library/bcew296c(VS.80).aspx

Edit and Continue is a time-saving feature that enables you to make changes to your source code while your program is in break mode. When you resume execution of the program by choosing an execution command like Continue or Step, Edit and Continue automatically applies the code changes with some limitations. This allows you to make changes to your code during a debugging session, instead of having to stop, recompile your entire program, and restart the debugging session.

Posted in .NET 2.0, El-Geish, Programming, VS 2005 | Leave a Comment »

F#

Posted by archworx on May 23, 2007

Source: http://research.microsoft.com/fsharp

Combining the efficiency, scripting, strong typing and productivity of ML with the stability, libraries, cross-language working and tools of .NET.

F# is a programming language that provides the much sought-after combination of type safety, performance and scripting, with all the advantages of running on a high-quality, well-supported modern runtime system. F# gives you a combination of

The only language to provide a combination like this is F# (pronounced FSharp) – a scripted/functional/imperative/object-oriented programming language that is a fantastic basis for many practical scientific, engineering and web-based programming tasks. 

F# is a pragmatically-oriented variant of ML that shares a core language with OCaml. F# programs run on top of the .NET Framework. Unlike other scripting languages it executes at or near the speed of C# and C++, making use of the performance that comes through strong typing. Unlike many statically-typed languages it also supports many dynamic language techniques, such as property discovery and reflection where needed. F# includes extensions for working across languages and for object-oriented programming, and it works seamlessly with other .NET programming languages and tools.

For further information, read about F# in more detail, download the F# distribution, read the getting started pages (a guide to installation and running your first program), go to the F# Manual, and learn about the growing F# Community. A short FAQ is also included on this site.

Some Starting points

Posted in .NET 2.0, El-Geish, Programming | 1 Comment »

Anonymous Methods in C#

Posted by archworx on May 23, 2007

In .Net v1.x, declaration of delegate required named methods. C# 2.0 introduced anonymous methods, as MSDN states, “Creating anonymous methods is essentially a way to pass a code block as a delegate parameter.

// Create a handler for a click event
btn.Click += delegate(System.Object o, System.EventArgs e) { MessageBox.Show("Click!"); };

This can be very useful in some cases such as a parameter to the Thread constructor:

new System.Threading.Thread(
  delegate()
  {
      System.Console.WriteLine("Hello");
      System.Console.WriteLine("World");
  }).Start();

Click here for more info.

Posted in .NET 2.0, El-Geish, Programming | 1 Comment »

‘My’ Namespace in VB.Net 2.0

Posted by archworx on May 23, 2007

For rapid development, Visual Basic .Net 2.0 introduced a namespace called My to access all the stuff that belongs to you like computer, network, printers, keyboard, forms, and others.

My Namespace 

For eaxmple, if you need to access the network, you just type: My.Computer.Network.

If My.Computer.Network.IsAvailable Then
    My.Computer.Network.DownloadFile("http://myserver.com/log.txt","c:\archives\serverlog.txt")
End If

Click here for more info.

Posted in .NET 2.0, El-Geish, Programming, VS 2005 | Leave a Comment »

Scalable Vector Graphics (SVG)

Posted by archworx on May 17, 2007

Scalable Vector Graphics (SVG) is an XML markup language for describing two-dimensional vector graphics, both static and animated, and either declarative or scripted.

SVG was developed by the W3C SVG Working Group starting in 1998, after Macromedia and MicrosoftVector Markup Language (VML) whereas Adobe Systems and Sun Microsystems submitted a competing format known as PGML. The working group was chaired by Chris Lilley of the W3C.

To see exmple please download the Adobe SVG ViewerExample1

Advantages of using SVG over other image formats (like JPEG and GIF) are:

  • SVG files are smaller and more compressible than JPEG and GIF images
  • SVG images are scalable
  • SVG images can be printed with high quality at any resolution
  • SVG images are zoomable. Any part of the image can be zoomed without degradation
  • SVG works with Java technology
  • SVG is an open standard

to learn SVG visit W3Schools

Posted in YShahin | 1 Comment »

Interview Question: Is a String of Parenthesis Balanced?

Posted by archworx on May 17, 2007

Here’s an easy one:

Given a string that contains only parenthesis like “(” “[" ")" "]“

We call a string balanced if every opening parenthesis has its corresponding closing parenthesis (and vice versa) , but they have to be in closed in correct order i.e. if you open a nested parenthesis inside another the nested one should be closed before the outer one is closed.

So an example of a balanced string would be “([[(())]])”

Examples of unbalanced strings would be “]([()])[" and "[[[((]))]]”

Can you write a function that takes a string (or characher array) as a parameter and returns true if it is balanced and false if it is not.

Waiting for your answers

Posted in AFathalla, Interview Question | 5 Comments »

When to use Page.IsValid ?

Posted by archworx on May 15, 2007

In his asp.net blog http://weblogs.asp.net/sibrahim/archive/2003/06/15/8723.aspx, Samer Ibrahim  points out a very important issue regarding Page.IsValid usage in asp.net pages. He quoted the following paragraph from Fritz Onion’s book  ‘Essential asp.net’ :

“As soon as you place a validation control on a page, it is imperative that you check the IsValid flag of the Page class before using any of the data posted by the client.  It is a common misconception that if validation fails on a page, the code for that page will not execute.  On the contrary, the only thing that happens when server-side validation fails is that the IsValid flag of the Page class is set to false, and each validation control that failed renters itself as a visible span so that the error indicator shows up when the page is redisplayed to the user.”

 So if a nice hacker bypasses the javascript validation, the server’s postback code will execute unless you check using safety condition: if(Page.IsValid){//run my code}

Posted in .NET 2.0, MZayet | 3 Comments »

 
Follow

Get every new post delivered to your Inbox.

Join 559 other followers