Business IT - Technology for your business

No. 1 Story

Telstra adds one million mobile services, but Sensis plummets

Telstra has revealed the addition of almost one million new mobile services in the six months to December 2011, but Sensis revenues plummeted 24 percent in 12 months.

read more

Write your own Linux server part two

Business IT - Open Source

Testing from a terminal window


The daemon is intended for use with a front-end client system such as an intranet page. However, it can be called – and thus tested – directly from a command-line based telnet program.

free hit counter
Simply use telnet to connect to the port the daemon is running on, such as with a command like

telnet localhost 5000


The daemon will give no helpful output. You must first enter the secret password before useful tasks can be performed. The date and time will be repeatedly outputted, giving up to three opportunities to enter the password before the calling client is disconnected.


$ telnet localhost 5000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Mon Aug 20 10:38:24 2007
abcde
Mon Aug 20 10:38:30 2001
help
Mon Aug 20 10:38:32 2001
helo
Connection closed by foreign host.


The secret password is found in the dwserv.h file.  Note that you must stop the daemon and re-execute make anytime you change the source code. If a front-end program connects to the daemon then it must be modified to use the correct secret password.


$ grep SECRET *.h
dwserv.h:#define SECRET_PASSWORD "allyourbasearebelongtous"


The following commands are available -


ALIA - return aliases for a given username
GROU - return groups for a given username
MAKE - make a new user account
STRT - start a process
VERS - return the program version
QUIT - disconnect from the server
STAT - inspect the number of connections


Here’s another sample session. This time we enter the correct secret password, and you will see we get meaningful output from the VERS and STAT commands, before choosing to disconnect.


# telnet localhost 5000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Mon Aug 20 10:38:43 2007
allyourbasearebelongtous
vers
1.2
stat
3 connections.
quit
Connection closed by foreign host.


The log file

If logging is enabled, the log file will report on each connection that is made to the server.  You will find information detailing the computer that connected and the commands that were executed.  This permits you to monitor any accounts that have been created or processes executed.

The log file is only ever appended to, even if the daemon is restarted. It is not overwritten. This means you will not lose information, but it does mean the log file must be rotated periodically to avoid running out of disk space.

Final comments


You now have the complete code to produce your own Linux network service. In this case, it allows you to make accounts and some other useful tasks. This gives power to control your network from an intranet or through some other means.

What’s nice is that the daemon uses TCP/IP sockets and responds in a timely fashion to incoming requests, spawning their processing off to a child worker thread. Also, the rc2.d script provides automatic startup in a manner consistent with other, distro-supplied, daemons.

Check out 99dwsvr on the following page.



- sponsored feature -

The Death of Traditional BI: What’s Next?

How to Make Business Discovery Work for Your Business IP PABX BUYING GUIDE

Business Discovery takes its cues from consumer apps. Like Google, it encourages us- ers to hunt for and explore data without worrying about or even noticing the underly- ing technology. Their entire experience is working within an intuitive interface to get real-time, self-service results with only minimal training. ...more