From 969b35d1d7ef74b337629b1ed984d34068e23d5f Mon Sep 17 00:00:00 2001 From: zolliker Date: Thu, 28 Jan 2010 08:39:21 +0000 Subject: [PATCH] - moved IFServerOption to ifile.c - moved PWSicsUser to passwd.c - moved back InitObjectCommands to ofac.c --- ifile.c | 28 ++++++++++++++++++++++++ ofac.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- ofac.h | 14 +++++++----- passwd.c | 37 +++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 9 deletions(-) diff --git a/ifile.c b/ifile.c index c54406e4..0d678167 100644 --- a/ifile.c +++ b/ifile.c @@ -43,6 +43,7 @@ #include #include #include +#include #include "ifile.h" /*====================== Locals ============================================*/ @@ -208,6 +209,33 @@ void IFDeleteOptions(IPair * pList) } } +/*----------------------- Server options creation -------------------------*/ +int IFServerOption(SConnection * pCon, SicsInterp * pSics, + void *pData, int argc, char *argv[]) +{ + char pBueffel[512]; + + assert(pSics); + assert(pCon); + + /* check authorisation */ + if (!SCMatchRights(pCon, usMugger)) { + SCWrite(pCon, "Insufficient privilege to set options", eError); + return 0; + } + + /* test if sufficient arguments */ + if (argc < 3) { + snprintf(pBueffel,sizeof(pBueffel)-1, "Syntax: %s name value ", argv[0]); + SCWrite(pCon, pBueffel, eError); + return 0; + } + + /* just do it */ + pSICSOptions = IFAddOption(pSICSOptions, argv[1], argv[2]); + return 1; +} + /*=========================================================================== Testcode: Define MAIN to activate it. Needs a file test.txt as input diff --git a/ofac.c b/ofac.c index 29990ccb..c7bacc98 100644 --- a/ofac.c +++ b/ofac.c @@ -7,14 +7,17 @@ * heavy modifications to separate PSI specific commands into a * separate library. Mark Koennecke, June 2003 * - * moved all staff except command and initialization list to sicsutil.c + * moved some functions to sicsutil.c * Markus Zolliker Jan 2010 */ #include "ofac.h" +#include "exeman.h" +#include "statusfile.h" +#include "site.h" /*--------------------------------------------------------------------------*/ -void InitGeneral(void) +static void InitGeneral(void) { #define INIT(F) { void F(void); F(); } @@ -38,7 +41,7 @@ void InitGeneral(void) INIT(SiteInit); /* site specific initializations */ } -void InitIniCommands(SicsInterp * pInter) +static void InitIniCommands(SicsInterp * pInter) { /* declare and add permanent command */ @@ -165,4 +168,59 @@ void InitIniCommands(SicsInterp * pInter) } -/* all other content moved to sicsutil.c - M.Zolliker Jan 2010 */ +/*--------------------------------------------------------------------------*/ +int InitObjectCommands(pServer pServ, char *file) +{ + SConnection *pCon = NULL; + char pBueffel[1024]; + int iRet; + SicsInterp *pSics; + pExeList pExe; + pEnvMon pEnv = NULL; + pSite site = NULL; + + pSics = pServ->pSics; + assert(pSics); + + InitGeneral(); + + /* general initialization */ + /* create a connection */ + pCon = SCCreateDummyConnection(pSics); + if (!pCon) { + return 0; + } + MakeExeManager(pCon, pSics, NULL, 1, NULL); + + pExe = CreateExeList(pServ->pTasker); + pServ->pExecutor = pExe; + pEnv = CreateEnvMon(); + + assert(pExe); + assert(pEnv); + + InitIniCommands(pSics); + /* + install site specific commands + */ + site = getSite(); + if (site != NULL) { + site->AddSiteCommands(pServ->pSics); + } + + InstallBckRestore(pCon, pSics); + + + /* evaluate the file */ + snprintf(pBueffel,sizeof(pBueffel)-1, "fileeval %s", file); + iRet = InterpExecute(pSics, pCon, pBueffel); + + /* done */ + SCDeleteConnection(pCon); + if (site != NULL && site->RemoveSiteCommands != NULL) { + site->RemoveSiteCommands(pSics); + } + + RemoveStartupCommands(); + return 1; +} diff --git a/ofac.h b/ofac.h index 2c655089..fd13d0f2 100644 --- a/ofac.h +++ b/ofac.h @@ -3,6 +3,14 @@ * * copyright: see file COPYRIGHT * + * SICS is a highly configurable system. This function implements + * the configurable. Configuration is meant to happen via a Tcl- + * configuration script. This module will initialize commands which + * create SICS-objects. Than an initialization file is evaluated + * via the macro facility. As most of the initialization commands + * will no longer be needed after this, they will be deleted. + * All this will be run with a higly privileged connection which + * prints to stdout/stdin. * * Mark Koennecke 1996 - ? * Markus Zolliker Jan 2010 @@ -12,10 +20,6 @@ #define OBJECTFACTORY #include "sics.h" -/* module initialisation calls */ -void InitGeneral(void); - -/* module initialisation calls */ -void InitIniCommands(SicsInterp * pInter); +int InitObjectCommands(pServer pServ, char *file); #endif diff --git a/passwd.c b/passwd.c index 99c3c3ee..0f687cf0 100644 --- a/passwd.c +++ b/passwd.c @@ -44,6 +44,7 @@ #include #include "passwd.h" #include "splitter.h" +#include "sics.h" typedef struct __PENTRY { char *name; @@ -152,3 +153,39 @@ int InitPasswd(char *filename) fclose(fp); return iRes; } +/*----------------------- Password database update -------------------------*/ +int PWSicsUser(SConnection * pCon, SicsInterp * pSics, void *pData, + int argc, char *argv[]) +{ + char pBueffel[512]; + TokenList *pList = NULL; + + assert(pSics); + assert(pCon); + + /* check authorisation */ + if (SCGetRights(pCon) > usMugger) { + SCWrite(pCon, "Insufficient privilege to set users", eError); + return 0; + } + + /* analyse commandlist */ + pList = SplitArguments(argc - 1, &argv[1]); + if ((!pList) || (!pList->pNext) || (!pList->pNext->pNext)) { + snprintf(pBueffel,sizeof(pBueffel)-1, "Invalid Passwd Entry ::\n %s %s %s\n", argv[1], + argv[2], argv[3]); + SCWrite(pCon, pBueffel, eError); + DeleteTokenList(pList); + return 0; + } else { + if (pList->pNext->pNext->Type != eInt) { + SCWrite(pCon, "Need integer rights code", eError); + DeleteTokenList(pList); + return 0; + } else { + AddUser(pList->text, pList->pNext->text, pList->pNext->pNext->iVal); + } + } + DeleteTokenList(pList); + return 1; +}