\section{md5auth.c File Reference}
\label{md5auth_8c}\index{md5auth.c@{md5auth.c}}
{\tt \#include $<$stdio.h$>$}\par
{\tt \#include \char`\"{}md5.h\char`\"{}}\par
{\tt \#include \char`\"{}libcomm.h\char`\"{}}\par
\subsection*{Functions}
\begin{CompactItemize}
\item 
void {\bf free\_\-authinfo} (struct {\bf AUTHINFO} $\ast$destroy)
\begin{CompactList}\small\item\em Free the memory space which is used by an {\bf AUTHINFO} {\rm (p.\,\pageref{structAUTHINFO})} structure.\item\end{CompactList}\item 
int {\bf socket\_\-md5auth} (int fd, char $\ast$netname, char $\ast$name, struct {\bf AUTHINFO} $\ast$$\ast$plocallogin, struct {\bf AUTHINFO} $\ast$$\ast$premotelogin)
\begin{CompactList}\small\item\em Do both side authentification.\item\end{CompactList}\item 
{\bf AUTHINFO} $\ast$ {\bf getauthinfo} (char $\ast$netname, char $\ast$name)
\begin{CompactList}\small\item\em Load authentication informations (netname, name, passwd, keyencrypt, keydecrypt) from authfile.\item\end{CompactList}\end{CompactItemize}


\subsection{Function Documentation}
\index{md5auth.c@{md5auth.c}!free_authinfo@{free\_\-authinfo}}
\index{free_authinfo@{free\_\-authinfo}!md5auth.c@{md5auth.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void free\_\-authinfo (struct {\bf AUTHINFO} $\ast$ {\em destroy})}\label{md5auth_8c_a0}


Free the memory space which is used by an {\bf AUTHINFO} {\rm (p.\,\pageref{structAUTHINFO})} structure.

\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
struct}]{\bf AUTHINFO} {\rm (p.\,\pageref{structAUTHINFO})} $\ast$) pointer to structure to destroy. \end{description}
\end{Desc}
\index{md5auth.c@{md5auth.c}!getauthinfo@{getauthinfo}}
\index{getauthinfo@{getauthinfo}!md5auth.c@{md5auth.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}struct {\bf AUTHINFO}$\ast$ getauthinfo (char $\ast$ {\em netname}, char $\ast$ {\em name})}\label{md5auth_8c_a2}


Load authentication informations (netname, name, passwd, keyencrypt, keydecrypt) from authfile.

\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
netname}](char $\ast$) specify the network name (may IP). NULL not specified.\item[{\em 
name}](char $\ast$) specity the login name. NULL not specified.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
(struct {\bf AUTHINFO} {\rm (p.\,\pageref{structAUTHINFO})} $\ast$) the first entry from authfile which matches network name OR login name. If both values are NULL, the first entry of the authfile is given back. \end{Desc}
\index{md5auth.c@{md5auth.c}!socket_md5auth@{socket\_\-md5auth}}
\index{socket_md5auth@{socket\_\-md5auth}!md5auth.c@{md5auth.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int socket\_\-md5auth (int {\em fd}, char $\ast$ {\em netname}, char $\ast$ {\em name}, struct {\bf AUTHINFO} $\ast$$\ast$ {\em plocallogin}, struct {\bf AUTHINFO} $\ast$$\ast$ {\em premotelogin})}\label{md5auth_8c_a1}


Do both side authentification.

This function is usually called just after a socket stream is established. The function must be called on both sides. Both sides following these steps:

1. get auth info ([login] name, passwd) by using {\bf getauthinfo}() {\rm (p.\,\pageref{libcomm_8h_a9})} from name or netname for remote login

2. generate random numbers

3. exchange (first send, then receive) login names

4. exchange random numbers

5. calculate md5 checksum over the random numbers (received from other side) and the remote passwd.

6. exchange md5 checksums

7. get auth info from name (received from other side) for local login

8. calculate md5 checksum over the local random numbers and the local passwd.

9. check login -- compare the received md5sum (6.) with the generated one (8.); send acknowledgement

10. receive remote acknowledgement

11. return suitable values\begin{Desc}
\item[Parameters: ]\par
\begin{description}
\item[{\em 
fd}](int) describes the socket on which the authentication has to be done\item[{\em 
netname}](char $\ast$) use netname to resolve [login] name and passwd of the remote machine (NULL: not specified)\item[{\em 
netname}](char $\ast$) use [login] name to resolve passwd of the remote machine (NULL: not specified; both NULL use first entry in file, see {\bf getauthinfo}() {\rm (p.\,\pageref{libcomm_8h_a9})})\item[{\em 
plocallogin}](struct {\bf AUTHINFO} {\rm (p.\,\pageref{structAUTHINFO})} $\ast$$\ast$) (pointer to pointer to an {\bf AUTHINFO} {\rm (p.\,\pageref{structAUTHINFO})} struct) in this (double pointed) struct the local authinfo will be loaded, if the parameter is not null.\item[{\em 
premotelogin}](struct {\bf AUTHINFO} {\rm (p.\,\pageref{structAUTHINFO})} $\ast$$\ast$) in this (double pointed) struct the remote authinfo will be loaded, if the parameter is not null.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns: ]\par
(int) 0: Authentication/Login OK; -1: remote login error; -2: login error on both sides; -3: local login error; -4: other (network) error; -5: cannot load remote auth info; -6: cannot load local auth info; \end{Desc}
