rem: * NsCp_Init --
add: * NsCp_ModInit --
context: static Ns_ArgProc ArgProc;/* * The following values are sent to the telnet client to enable * and disable password prompt echo. */#define TN_IAC  255#define TN_WILL 251#define TN_WONT 252#define TN_DO   253#define TN_DONT 254#define TN_EOF  236#define TN_IP   244#define TN_ECHO   1static unsigned char do_echo[]    = {TN_IAC, TN_DO,   TN_ECHO};static unsigned char dont_echo[]  = {TN_IAC, TN_DONT, TN_ECHO};static unsigned char will_echo[]  = {TN_IAC, TN_WILL, TN_ECHO};static unsigned char wont_echo[]  = {TN_IAC, TN_WONT, TN_ECHO};/* *---------------------------------------------------------------------- * * NsCp_Init -- * *	Load the config parameters, setup the structures, and *	listen on the control port. * * Results: *	None. * * Side effects: *	Server will listen for control connections on specified *  	address and port. * *---------------------------------------------------------------------- */ intNsCp_Init(char *server, char *module){    Mod *modPtr;    char *path, *addr, *pass, *user, *key, *end;    int i, new, port;    SOCKET lsock;    Ns_Set *set;    Tcl_HashEntry *hPtr;    /*      * Create the listening socket and callback.     */    path = Ns_ConfigGetPath(server, module, NULL);    if (((addr = Ns_ConfigGetValue(path, "address")) == NULL)	 || (!Ns_ConfigGetInt(path, "port", &port)) )  {	Ns_Log(Error, "nscp: address and port must be specified in config");	return NS_ERROR;    }    lsock = Ns_SockListen(addr, port);    if (lsock == INVALID_SOCKET) {	Ns_Log(Error, "nscp: could not listen on %s:%d", addr, port);	return NS_ERROR;    }    Ns_Log(Notice, "nscp: listening on %s:%d", addr, port);    /*     * Create a new Mod structure for this instance.     */    modPtr = ns_malloc(sizeof(Mod));    modPtr->server = server;    modPtr->addr = addr;    modPtr->port = port;    if (!Ns_ConfigGetBool(path, "echopassword", &modPtr->echo)) {    	modPtr->echo = 1;    }    if (!Ns_ConfigGetBool(path, "cpcmdlogging", &modPtr->commandLogging)) {        modPtr->commandLogging = 0; /* Default to off */    }    /*     * Initialize the hash table of authorized users.  Entry values     * are either NULL indicating authorization should be checked     * via the Ns_AuthorizeUser() API or contain a Unix crypt(3)     * sytle encrypted password.  For the later, the entry is     * compatible with /etc/passwd (i.e., username followed by     * password separated by colons).     */    Tcl_InitHashTable(&modPtr->users, TCL_STRING_KEYS);    path = Ns_ConfigGetPath(server, module, "users", NULL);    set = Ns_ConfigGetSection(path);    for (i = 0; set != NULL && i < Ns_SetSize(set); ++i) {	key = Ns_SetKey(set, i);	user = Ns_SetValue(set, i);	if (!STRIEQ(key, "user") || (pass = strchr(user, ':')) == NULL) {	    continue;	}	*pass = '\0';	hPtr = Tcl_CreateHashEntry(&modPtr->users, user, &new);	if (new) {	    Ns_Log(Notice, "nscp: added user: %s", user);	} else {	    Ns_Log(Warning, "nscp: duplicate user: %s", user);	    ns_free(Tcl_GetHashValue(hPtr));	}	*pass++ = ':';	end = strchr(pass, ':');	if (end != NULL) {	    *end = '\0';	}	pass = ns_strdup(pass);	if (end != NULL) {	    *end = ':';	}	Tcl_SetHashValue(hPtr, pass);    }    if (modPtr->users.numEntries == 0) {	Ns_Log(Warning, "nscp: no authorized users");    }    Ns_SockCallback(lsock, AcceptProc, modPtr, NS_SOCK_READ|NS_SOCK_EXIT);    Ns_RegisterProcInfo((void *)AcceptProc, "nscp", ArgProc);    return NS_OK;}/* *---------------------------------------------------------------------- * * ArgProc -- * *	Append listen port info for query callback. * * Results: *	None * * Side effects: *  	None. * *---------------------------------------------------------------------- */static voidArgProc(Tcl_DString *dsPtr, void *arg){    Mod *modPtr = arg;    char buf[20];    sprintf(buf, "%d", modPtr->port);    Tcl_DStringStartSublist(dsPtr);    Tcl_DStringAppendElement(dsPtr, modPtr->addr);    Tcl_DStringAppendElement(dsPtr, buf);    Tcl_DStringEndSublist(dsPtr);}