[Fedora-directory-commits] adminserver/lib/libadmin form_get.c, 1.6, 1.7 httpcon.c, 1.5, 1.6 install.c, 1.5, 1.6 referer.c, 1.6, 1.7 template.c, 1.7, 1.8 util.c, 1.7, 1.8

Richard Allen Megginson (rmeggins) fedora-directory-commits at redhat.com
Wed May 9 00:26:39 UTC 2007


Author: rmeggins

Update of /cvs/dirsec/adminserver/lib/libadmin
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv32253/adminserver/lib/libadmin

Modified Files:
	form_get.c httpcon.c install.c referer.c template.c util.c 
Log Message:
Resolves: bug 239502, bug 186280
Description: adminserver: autotools, FHS, clean up CGI parameters
Fix Description: Too numerous to mention




Index: form_get.c
===================================================================
RCS file: /cvs/dirsec/adminserver/lib/libadmin/form_get.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- form_get.c	31 Mar 2006 22:58:29 -0000	1.6
+++ form_get.c	9 May 2007 00:26:37 -0000	1.7
@@ -32,14 +32,12 @@
 #include <i18n.h>
 #include "prprf.h"
 
-#define HTML_DIR "../html/"
-
 NSAPI_PUBLIC FILE *open_error_file(char *filename)
 {
     FILE *f = NULL;
     char line[BIG_LINE];
 
-    PR_snprintf(line, sizeof(line), "%s%s", HTML_DIR, filename);
+    PR_snprintf(line, sizeof(line), "%s%c%s", util_get_html_dir(), FILE_PATHSEP, filename);
 
     if(!(f = fopen(line, "r")))  {
         fprintf(stdout, "\n<h1 align=center>Catastrophic error</h1>\n");
@@ -55,31 +53,7 @@
     FILE *f = NULL;
     char line[BIG_LINE];
 
-    PR_snprintf(line, sizeof(line), "%s%s", HTML_DIR, filename);
-    if(!(f = fopen(line, "r")))  {
-        report_error(FILE_ERROR, line, "Could not open the HTML file.  "
-                     "Perhaps the permissions have changed or someone "
-                     "has moved the file.");
-    }
-    return f;
-}
-
-/*********************************************************************
-  Open an html file from the specified language subdirectory, if 
-  available, else from the default language subdirectory.
- *********************************************************************/
-
-NSAPI_PUBLIC
-FILE*
-open_html_file_lang(char* filename,char* language)
-{
-    FILE *f = NULL;
-    char filePattern[BIG_LINE];
-    char line[BIG_LINE];
-  
-    PR_snprintf(filePattern, sizeof(filePattern), "%s%s%s", HTML_DIR, "$$LANGDIR/", filename);
-  
-    GetFileForLanguage(filePattern,language,line,sizeof(line));
+    PR_snprintf(line, sizeof(line), "%s%c%s", util_get_html_dir(), FILE_PATHSEP, filename);
     if(!(f = fopen(line, "r")))  {
         report_error(FILE_ERROR, line, "Could not open the HTML file.  "
                      "Perhaps the permissions have changed or someone "
@@ -149,332 +123,3 @@
 	FREE(value);
     }
 }
-
-
-#ifdef MCC_PROXY
-/* This crap doesn't belong here, but I couldn't think of any better place,
- * either.  Basically, this crap *shouldn't* be *anywhere*, we should be
- * able to do without it.  But, we can't.  Some linkers disagree.
- */
-
-#include <pwd.h>
-
-struct passwd *userpw = NULL;
-#if !defined(IRIX) && !defined(SOLARIS)
-char *chr = NULL;
-#endif
-int ProxyTraceFlag = 0;
-int sockd_service()       { return REQ_ABORTED; }
-int record_proxy_access() { return REQ_ABORTED; }
-int sockd_read_request()  { return REQ_ABORTED; }
-int http_parse_request(char *t, Request *rq, Session *sn)
-{
-    return REQ_ABORTED;
-}
-
-struct FuncStruct func_standard[] = {
-  {NULL, NULL, NULL}
-};
-
-pid_t bu_pid = (pid_t)-1;
-bu_terminate() {}
-bu_start() {}
-
-
-/*
- * Turn seconds into a human readable string.
- * This function intentionally only shows at most *two* different
- * units.  This is to keep it short.  The values elsewhere are selected
- * so that this doesn't pose a problem.
- *
- */
-char *human_time_str(long t)
-{
-    char buf[50];
-    int s = t % 60;
-    int m = (t / 60) % 60;
-    int h = (t / 3600) % 24;
-    int d = t / (3600 * 24) % 7;
-    int w = t / (3600 * 24 * 7);
-
-    if (t < 48 * 3600) {
-	h += 24 * d;
-	d = 0;
-    }
-
-    if (w==1) {
-	d += 7;
-	w = 0;
-    }
-
-    if (t < 60) {
-	PR_snprintf(buf, sizeof(buf), "%d sec", s);
-    }
-    else if (t < 3600) {
-	if (s)
-	    PR_snprintf(buf, sizeof(buf), "%d min %d sec", m, s);
-	else
-	    PR_snprintf(buf, sizeof(buf), "%d min", m);
-    }
-    else if (t < 48 * 3600) {
-	if (m)
-	    PR_snprintf(buf, sizeof(buf), "%d hour%s %d min", h, (h>1 ? "s" : ""), m);
-	else
-	    PR_snprintf(buf, sizeof(buf), "%d hour%s", h, (h>1 ? "s" : ""));
-    }
-    else if (t < 14 * 24 * 3600) {
-	if (h)
-	    PR_snprintf(buf, sizeof(buf), "%d day%s %d hour%s", d, (d>1 ? "s" : ""), h, (h>1 ? "s" : ""));
-	else
-	    PR_snprintf(buf, sizeof(buf), "%d day%s", d, (d>1 ? "s" : ""));
-    }
-    else {
-	if (d)
-	    PR_snprintf(buf, sizeof(buf), "%d week%s %d day%s", w, (w>1 ? "s" : ""), d, (d>1 ? "s" : ""));
-	else
-	    PR_snprintf(buf, sizeof(buf), "%d week%s", w, (w>1 ? "s" : ""));
-    }
-    return STRDUP(buf);
-}
-
-
-long cache_size_tbl[] = {
-       10L,    15L,    20L,    25L,    50L,    75L,
-      100L,   150L,   200L,   300L,   400L,   500L,
-      600L,   700L,   800L,   900L,  1000L,  1200L,
-     1400L,  1600L,  1800L,  2000L,  2500L,  3000L,
-     3500L,  4000L,  4500L,  5000L,  5500L,  6000L,
-     7000L,  8000L,  9000L, 10000L, 11000L, 12000L,
-    14000L, 16000L, 20000L, 24000L, 28000L, 32000L,
-        0L
-};
-
-long inst_cache_size_tbl[] = {
-       10L,    25L,    50L,    75L,
-      100L,   200L,   300L,   400L,   500L,
-      600L,   700L,   800L,   900L,  1000L,  1200L,
-     1400L,  1600L,  1800L,  2000L,
-        0L
-};
-
-long cache_capacity_tbl[] = {
-      100L,	/*   1 dir  ==	100 MB	*/
-      250L, 	/*   2 dirs ==	250 MB	*/
-      500L,	/*   4 dirs ==	500 MB	*/
-     1000L,	/*   8 dirs ==	  1 GB	*/
-     2000L,	/*  16 dirs ==	  2 GB	*/
-     4000L,	/*  32 dirs ==	  4 GB	*/
-     8000L,	/*  64 dirs ==	  8 GB	*/
-    16000L,	/* 128 dirs ==	 16 GB	*/
-    32000L,	/* 256 dirs ==	 32 GB	*/
-        0L
-};
-
-long inst_cache_capacity_tbl[] = {
-      100L,	/*   1 dir  ==	100 MB	*/
-      250L, 	/*   2 dirs ==	250 MB	*/
-      500L,	/*   4 dirs ==	500 MB	*/
-     1000L,	/*   8 dirs ==	  1 GB	*/
-     2000L,	/*  16 dirs ==	  2 GB	*/
-        0L
-};
-
-float lm_factor_tbl[] = {
-    0.02, 0.04, 0.06, 0.08,
-    0.1,  0.2,  0.3,  0.4,  0.5,
-    0.6,  0.7,  0.8,  0.9,  1.0,
-    -1.0
-};
-
-long time_interval_tbl[] = {
-    /* 5 min	*/         300L,
-    /* 15 min	*/         900L,
-    /* 30 min	*/        1800L,
-    /* 45 min	*/        2700L,
-    /* 60 min	*/        3600L,
-    /* 2 hours	*/    2 * 3600L,
-    /* 4 hours	*/    4 * 3600L,
-    /* 6 hours	*/    6 * 3600L,
-    /* 8 hours	*/    8 * 3600L,
-    /* 12 hours	*/   12 * 3600L,
-    /* 24 hours	*/   24 * 3600L,
-    /* 2 days	*/   48 * 3600L,
-    /* 3 days	*/   72 * 3600L,
-    /* 4 days	*/   96 * 3600L,
-    /* 5 days	*/  120 * 3600L,
-    /* 6 days	*/  144 * 3600L,
-    /* 7 days	*/  168 * 3600L,
-    /* 10 days	*/  240 * 3600L,
-    /* 14 days	*/  336 * 3600L,
-			     0L
-};
-
-long timeout_tbl[] = {
-    /*  5 sec */	   5L,
-    /* 10 sec */	  10L,
-    /* 15 sec */	  15L,
-    /* 20 sec */	  20L,
-    /* 25 sec */	  25L,
-    /* 30 sec */	  30L,
-    /* 40 sec */	  40L,
-    /* 50 sec */	  50L,
-    /* 60 sec */	  60L,
-    /* 90 sec */	  90L,
-    /*  2 min */	 120L,
-    /*  3 min */	 180L,
-    /*  4 min */	 240L,
-    /*  5 min */	 300L,
-    /*  6 min */	 360L,
-    /*  8 min */	 480L,
-    /* 10 min */	 600L,
-    /* 12 min */	 720L,
-    /* 15 min */	 900L,
-    /* 20 min */	1200L,
-    /* 25 min */	1500L,
-    /* 30 min */	1800L,
-    /* 45 min */	2700L,
-    /* 60 min */	3600L,
-			   0L
-};
-
-int percent_tbl[] = {
-    0, 5, 10, 15, 20, 25, 35, 50, 65, 75, 80, 85, 90, 95, 100,
-    0
-};
-
-
-char *mb_str(long mb)
-{
-    char buf[50];
-
-    if (mb < 1000) {
-	PR_snprintf(buf, sizeof(buf), "%ld MB", mb);
-    }
-    else {
-	int n = mb / 1000;
-	int d = (mb % 1000) / 100;
-
-	if (n < 6 && d) {
-	    PR_snprintf(buf, sizeof(buf), "%d.%d GB", n, d);
-	}
-	else {
-	    PR_snprintf(buf, sizeof(buf), "%d GB", n);
-	}
-    }
-    return STRDUP(buf);
-}
-
-void output_interval_select(char *name, char *other, long selected, long *tbl)
-{
-    int i, found = 0;
-
-    printf("<SELECT NAME=%s %s>\n", name, other ? other : "");
-
-    for(i=0; tbl[i]; i++) {
-	if (!found && tbl[i] > selected) {
-	    found = 1;
-	    printf("<OPTION VALUE=\"%ld\" SELECTED>%s\n", selected, human_time_str(selected));
-	}
-	printf("<OPTION VALUE=\"%ld\"%s>%s\n",
-	       tbl[i], tbl[i]==selected ? " SELECTED" : "", human_time_str(tbl[i]));
-	if (!found && tbl[i]==selected) {
-	    found = 1;
-	}
-    }
-    if (!found)
-	printf("<OPTION VALUE=\"%ld\" SELECTED>%s\n", selected, human_time_str(selected));
-    printf("</SELECT>");
-}
-
-
-void output_mb_select(char *name, char *other, long selected, long *tbl)
-{
-    int i, found = 0;
-
-    printf("<SELECT NAME=%s %s>\n", name, other ? other : "");
-
-    for(i=0; tbl[i]; i++) {
-	if (!found && tbl[i] > selected) {
-	    found = 1;
-	    printf("<OPTION VALUE=\"%ld\" SELECTED>%s\n", selected, mb_str(selected));
-	}
-	printf("<OPTION VALUE=\"%ld\"%s>%s\n",
-	       tbl[i], tbl[i]==selected ? " SELECTED" : "", mb_str(tbl[i]));
-	if (!found && tbl[i]==selected) {
-	    found = 1;
-	}
-    }
-    if (!found)
-	printf("<OPTION VALUE=\"%ld\" SELECTED>%s\n", selected, mb_str(selected));
-    printf("</SELECT>");
-}
-
-
-
-char *lm_str(float f)
-{
-    char buf[50];
-
-    if (f < 0.1)
-	PR_snprintf(buf, sizeof(buf), "%.2f", f);
-    else
-	PR_snprintf(buf, sizeof(buf), "%.1f", f);
-
-    return STRDUP(buf);
-}
-
-
-#define LM_ACCURACY 0.00001
-
-void output_lm_select(char *name, char *other, float selected, float *tbl)
-{
-    int i, found = 0;
-
-    printf("<SELECT NAME=%s %s>\n", name, other ? other : "");
-
-    for(i=0; tbl[i] > 0; i++) {
-	if (!found && tbl[i] - LM_ACCURACY > selected) {
-	    found = 1;
-	    printf("<OPTION VALUE=\"%.3f\">%s\n", selected, lm_str(selected));
-	}
-	if (!found &&
-	    tbl[i] - LM_ACCURACY <= selected &&
-	    tbl[i] + LM_ACCURACY >= selected) {
-	    found = 1;
-	    printf("<OPTION VALUE=\"%.3f\" SELECTED>%s\n", tbl[i], lm_str(tbl[i]));
-	}
-	else {
-	    printf("<OPTION VALUE=\"%.3f\">%s\n", tbl[i], lm_str(tbl[i]));
-	}
-    }
-    if (!found)
-	printf("<OPTION VALUE=\"%.3f\">%s\n", selected, lm_str(selected));
-    printf("</SELECT>");
-}
-
-
-void output_percentage_select(char *name, char *other, int selected, int *tbl)
-{
-    int i, found = 0;
-
-    printf("<SELECT NAME=%s %s>\n", name, other ? other : "");
-
-    for(i=0; !i || tbl[i]; i++) {
-	if (!found && tbl[i] > selected) {
-	    found = 1;
-	    printf("<OPTION VALUE=\"%d\" SELECTED>%d %%\n", selected, selected);
-	}
-	printf("<OPTION VALUE=\"%d\"%s>%d %%\n",
-	       tbl[i], tbl[i]==selected ? " SELECTED" : "", tbl[i]);
-	if (!found && tbl[i]==selected) {
-	    found = 1;
-	}
-    }
-    if (!found)
-	printf("<OPTION VALUE=\"%d\" SELECTED>%d %%\n", selected, selected);
-    printf("</SELECT>");
-}
-
-
-#endif	/* MCC_PROXY */
-


Index: httpcon.c
===================================================================
RCS file: /cvs/dirsec/adminserver/lib/libadmin/httpcon.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- httpcon.c	29 Sep 2005 22:12:04 -0000	1.5
+++ httpcon.c	9 May 2007 00:26:37 -0000	1.6
@@ -303,67 +303,6 @@
     fflush(stdout);
 }
 
-/*
- * Consolidate the SEC Initialization here because NT DLL architecture
- * takes a separate copy of libsec's variable causing this section
- * of code to fail if the initialization lies outside the DLL!
- */
-
-
-#if 0
-static int CL_secinited = 0;
-static CERTCertDBHandle *certdb;
-
-
-void
-CL_secinit()
-{
-   if (CL_secinited) return;
-
-   (void) systhread_init("cluster");	/* libsec needs PR_Init() */
-
-/* we can still only call SEC_Init() on UNIX - Adam */
-
-#ifdef	XP_WIN32
-   (void) RNG_RNGInit();
-   /*(void) SSL3_Init();*/
-#else 	/* !XP_WIN32 */
-   (void) SEC_Init();
-#endif	/* XP_WIN32 */
-
-   /*
-    * TBD - The clcert.db file needs to be placed on the new Key
-    *       directory as soon as mlm setup the structure.
-    */
-   if (!strcasecmp(getenv("HTTPS"), "ON")) {
-
-      char *varptr, *certfile;
-
-      varptr = get_nsadm_var("Certfile");
-      if (varptr == (char *) NULL) {
-         report_error(SYSTEM_ERROR, "Missing Certfile",
-				    "failed to obtain certificate database");
-      }
-      certfile = (char *)MALLOC(strlen(varptr)+16);
-      if ( strstr( varptr, ".db" ) ) {
-	strcpy( certfile, varptr );
-      } else {
-	sprintf(certfile, "%s.db", varptr);
-      }
-      if (CERT_OpenCertDBFilename(&certdb, certfile, PR_TRUE)) {
-         report_error(SYSTEM_ERROR, "SEC Init Failed",
-				    "failed to init certificate database");
-      }
-      FREE(certfile);
-      (void) CERT_SetDefaultCertDB(&certdb);
-   }
-   CL_secinited = 1;
-}
-
-#endif
-
-
-
 NSAPI_PUBLIC PRFileDesc*
 make_http_request(char *protocol, char *server, unsigned int port, char *request, int timeout, int *errcode)
 {
@@ -417,7 +356,7 @@
 
     if (!strcmp(protocol, "https")) {
 	
-	req_socket = SSLSocket_init(req_socket);
+	req_socket = SSLSocket_init(req_socket, CONFIGDIR, SECURITYDIR);
 	if (req_socket == NULL) {
 	    *errcode = PR_GetError();
             report_error(SYSTEM_ERROR, "SEC Init Failed", 


Index: install.c
===================================================================
RCS file: /cvs/dirsec/adminserver/lib/libadmin/install.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- install.c	18 Aug 2005 19:20:01 -0000	1.5
+++ install.c	9 May 2007 00:26:37 -0000	1.6
@@ -92,32 +92,3 @@
 #endif
     return -1;
 }
-
-
-#ifdef XP_UNIX
-#include <pwd.h>
-
-NSAPI_PUBLIC int try_user(char *user)
-{
-    struct passwd *pw;
-    char fn[128];
-    int fd, ret;
-
-    setpwent();
-    if(!(pw = getpwnam(user)))
-        return -1;
-
-    endpwent();
-
-    if(geteuid())
-        return 0;
-
-    sprintf(fn, "/tmp/trychown.%d", getpid());
-    if( (fd = creat(fn, 0777)) == -1)
-        return 0;         /* Hmm. */
-    ret = chown(fn, pw->pw_uid, pw->pw_gid);
-    close(fd);
-    unlink(fn);
-    return (ret == -1 ? -2 : 0);
-}
-#endif /* XP_UNIX */


Index: referer.c
===================================================================
RCS file: /cvs/dirsec/adminserver/lib/libadmin/referer.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- referer.c	31 Mar 2006 22:58:29 -0000	1.6
+++ referer.c	9 May 2007 00:26:37 -0000	1.7
@@ -91,42 +91,6 @@
 	     "</SCRIPT>\n", ref );
 }
 
-NSAPI_PUBLIC void
-set_referer( char **qqq )
-{
-  char	*surl = getenv( "SERVER_URL" );
-  char	*sn = getenv( "SCRIPT_NAME" );
-  char	*referer = (char *)MALLOC( strlen( surl ) + strlen( sn ) + 4 );
-
-  fprintf( stdout,
-	   "<SCRIPT language="MOCHA_NAME">\n"
-	   "document.cookie='"REFER_VAR"=' + window.location.href + "
-	   "'; path=/%s/';\n"
-	   "</SCRIPT>", get_srvname( 0 ) );
-  /* Need to recalculate the referer for internal use */
-  sprintf( referer, "%s%s", surl, sn );
-  cookieValue( REFER_VAR, referer );
-  FREE( referer );
-}
-
-NSAPI_PUBLIC void
-set_fake_referer( char *new_ref )
-{
-  char *surl=getenv("SERVER_URL");
-  char *sn=getenv("SCRIPT_NAME");
-  char *referer = (char *)MALLOC(strlen(surl)+strlen(sn)+strlen(new_ref)+4);
-
-  fprintf( stdout,
-	   "<SCRIPT language="MOCHA_NAME">\n"
-	   "document.cookie='"REFER_VAR"=%s; path=/%s/';\n"
-	   "</SCRIPT>", new_ref, get_srvname( 0 ) );
-
-  /* Need to recalculate the referer for internal use */
-  sprintf(referer, "%s%s", surl, sn);
-  strcpy(strrchr(referer, '/') + 1, new_ref);
-  cookieValue( REFER_VAR, referer );
-}
-
 /* Blame Rob. */
 NSAPI_PUBLIC void redirect_to_script(char *script)
 {


Index: template.c
===================================================================
RCS file: /cvs/dirsec/adminserver/lib/libadmin/template.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- template.c	31 Mar 2006 22:58:29 -0000	1.7
+++ template.c	9 May 2007 00:26:37 -0000	1.8
@@ -71,7 +71,6 @@
   {"ELEMDIV ", "\n"},
   {"REFERER ", "FUNC link_referer"},
   {"INDEX ", "<a href=\"index\">%s</a>\n"},
-  {"SERVERROOT ", "FUNC serverroot"},
   {"RESTART ", "<a href=\"pcontrol\">%s</a>\n"},
   {"ACCESS ", "FUNC makeurl"},
   {"COMMIT ", "<a href=\"commit?commit\">%s</a>\n"},
@@ -91,7 +90,6 @@
 void booktrack(char *input, char **vars);
 void docswitcher(char *input);
 void link_referer(char **input, char **vars);
-void serverroot(char **vars);
 char **get_vars(char *string);
 static void output(char *string);
 void makeurl(char **vars);
@@ -137,8 +135,6 @@
                      docswitcher(input[0]);
                  else if(!strncmp(templates[index].format+5, "link_referer",12))
                      link_referer(input, vars);
-                 else if(!strncmp(templates[index].format+5, "serverroot",10))
-                     serverroot(vars);
                  else if(!strncmp(templates[index].format+5, "makeurl",7))
                      makeurl(vars);
                  else if(!strncmp(templates[index].format+5, "curservname",11))
@@ -304,18 +300,6 @@
     output("<hr width=10%%>\n");
 }
 
-void serverroot(char **vars) 
-{
-    char line[BIG_LINE];
-#ifdef USE_ADMSERV
-    char *sroot = getenv("NETSITE_ROOT");
-#else
-    char *sroot = get_mag_var("#ServerRoot");
-#endif
-    PR_snprintf(line, sizeof(line), "%s%s", (sroot) ? sroot : "", (vars[0]) ? vars[0] : "");
-    output(line);
-}
-
 void makeurl(char **vars)
 {
     char line[BIG_LINE];


Index: util.c
===================================================================
RCS file: /cvs/dirsec/adminserver/lib/libadmin/util.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- util.c	31 Mar 2006 22:58:29 -0000	1.7
+++ util.c	9 May 2007 00:26:37 -0000	1.8
@@ -882,118 +882,6 @@
     return;
 }
 
-int str_flag_to_int(char *str_flag) 
-{
-    if (!str_flag)
-        return -1;
-    if (!strcmp(str_flag, "1"))
-        return 1;
-    return 0;
-}            
-
-/*
- * get_ip_and_mask - function to take something that may be an IP Address
- *                   and netmaks, and validate it.  It takes two possible
- *
- *     Parmaters:    char   *candidate
- *
- *     Returns NULL if it isn't a valid IP address and mask. It returns
- *     the IP address and mask in the form "iii.iii.iii.iii mmm.mmm.mmm.mmm"
- *     if it is valid. This is in a string dynamicly allocated in this
- *     function.
- *
- *     Processing:  the candidate is assumed to be in one of
- *                  these two formats:
- *
- *     1. "iii.iii.iii.iii" (returns: "iii.iii.iii.iii 255.255.255.255")
- *     2. "iii.iii.iii.iii mmm.mmm.mmm.mmm"
- *     3. "iii.*", "iii.iii.*", or "iii.iii.iii.*"
- *
- *     The rules are:
- *     I.    If it has a space in it, it is assumed to be the delimiter in
- *           format 2.
- *     II.   If it has a "*" in it, it's assumed to be format 3.
- *     III.  If it's in format 3, the net mask returned is:
- *           255.0.0.0, 255.255.0.0, or 255.255.255.0 respectivly,
- *           and parts of the address right of the * is replaced with 0s.
- *     IV.   We use inet_addr on the pieces to validate them.
- *
- * 
- */
-
-char *get_ip_and_mask(char *candidate)
-{
-    char work[BIG_LINE];
-
-    char *p;
-    char *result = NULL;
-    int   len;
-    int   dots = 0;
-    int   i;
-
-    if (candidate && strlen(candidate) < (unsigned) BIG_LINE) {
-
-        if ((p = strchr(candidate, ' '))) {
-            len = p-candidate+1;
-            memcpy(work, candidate, len);
-            work[len] = '\0';
-            if (inet_addr(work) != -1) {
-                len = strlen(candidate)-strlen(p)-1;
-                if (len > 0) {
-                    memcpy(work, p+1, len);
-                    work[len] = '\0';
-                    if (inet_addr(work) != -1) {
-                        result = strdup(candidate);
-                    }
-                }
-            }
-        }
-        else if ((p = strchr(candidate, '*')) &&
-                 (p-candidate > 1          )  &&
-                 (*(p-1) == '.')               ) {
-            memset(work, 0, BIG_LINE);
-            for (i=0; candidate[i]!='*'; ++i) {
-                if (candidate[i+1] != '*')
-                    work[i] = candidate[i];
-                if (candidate[i] == '.')
-                    ++dots;
-            }
-            if (dots == 1 || dots == 2 || dots == 3) {
-                for (i=0; i<4-dots; ++i) {
-                    strcat(work, ".0");
-                }
-                if (inet_addr(work) != -1) {
-                    strcat(work, " ");
-                    p = &work[strlen(work)];
-                    for (i=0; i<dots; ++i) {
-                        if (i==0)
-                            strcat(work, "255");
-                        else
-                            strcat(work, ".255");
-                    } 
-                    for (i=0; i<4-dots; ++i) {
-                        strcat(work, ".0");
-                    }
-                    if (inet_addr(p) != -1) {
-                        result = strdup(work);
-                    }
-                }
-            }
-        }
-        else {
-            if (inet_addr(candidate) != -1) {
-                PL_strncpyz(work, candidate, sizeof(work));
-                PL_strcatn(work, sizeof(work), " 255.255.255.255");
-                result = strdup(work);
-            }
-        }
-    }
-    else
-        result = NULL;
-
-    return result;
-}
-
 /* do fgets with a filebuffer *, instead of a File *.  Can't use util_getline
    because it complains if the line is too long.
    It does throw away <CR>s, though.
@@ -1193,101 +1081,6 @@
   }
 }
 
-static int adm_initialized=0;
-
-/* Initialize NSPR for all the base functions we use */
-NSAPI_PUBLIC int ADM_Init(void)
-{
-    if(!adm_initialized)  {
-        NSPR_INIT("AdminPrograms");
-        adm_initialized=1;
-    }
-    return 0;
-}
-
-
-#ifdef XP_UNIX
-/*
- * This function will return the SuiteSpot user id and group id used to
- * recommend that Servers to run as.  Any line starts with '#'
- * is treated as comment.  It looks for SuiteSpotUser/SuiteSpotGroup
- * name/value pair.
- *
- * It returns  0 when success and allocate storage for user and group.
- *    returns -1 when only SuiteSpot user id is found.
- *    returns -2 when only SuiteSpot group id is found.
- *    returns -3 when NO SuiteSpot user and group is found.
- *    returns -4 when fails to open <server_root>/shared/config/ssusers.conf
- */
-NSAPI_PUBLIC int ADM_GetUXSSid(char *sroot, char **user, char **group)
-{
-    int  foundUser, foundGroup;
-    char fn[BIG_LINE];
-    char line[BIG_LINE];
-    FILE *f;
-
-    foundUser = 0;
-    foundGroup = 0;
-    *user  = (char *) NULL;
-    *group = (char *) NULL;
-
-    PR_snprintf(fn, sizeof(fn), "%s/shared/config/ssusers.conf", sroot);
-    if (f = fopen(fn, "r")) {
-       while (fgets(line, sizeof(line), f)) {
-	  if (line[0] == '#') {
-	     continue;
-	  }
-          if (!strncmp(line, "SuiteSpotUser", strlen("SuiteSpotUser"))) {
-             char *ptr1;
-             ptr1 = line + strlen("SuiteSpotUser");
-             while ((*ptr1 == '\t') || (*ptr1 == ' ')) {
-                ptr1++;
-             }
-             if ((strlen(ptr1) > 0) && (*user == (char *) NULL)) {
-                *user = (char *) MALLOC(strlen(ptr1)+1);
-		if (ptr1[strlen(ptr1)-1] == '\n') {
-		   ptr1[strlen(ptr1)-1] = '\0';
-		}
-                strcpy(*user, ptr1);
-             }
-	     foundUser = 1;
-	     continue;
-          }
-          if (!strncmp(line, "SuiteSpotGroup", strlen("SuiteSpotGroup"))) {
-             char *ptr1;
-             ptr1 = line + strlen("SuiteSpotGroup");
-             while ((*ptr1 == '\t') || (*ptr1 == ' ')) {
-                ptr1++;
-             }
-             if ((strlen(ptr1) > 0) && (*group == (char *) NULL)) {
-                *group = (char *) MALLOC(strlen(ptr1)+1);
-		if (ptr1[strlen(ptr1)-1] == '\n') {
-		   ptr1[strlen(ptr1)-1] = '\0';
-		}
-                strcpy(*group, ptr1);
-             }
-             foundGroup = 1;
-	     continue;
-          }
-       }
-       fclose(f);
-    } else {
-       return(-4);
-    }
-
-    if (foundUser && foundGroup) {
-       return(0);
-    } else if (foundUser) {
-       return(-1);
-    } else if (foundGroup) {
-       return(-2);
-    } else {
-       return(-3);
-    }
-}
-#endif	/* XP_UNIX */
-
-
 /* this macro was copied from libldap/tmplout.c */
 
 #define HREF_CHAR_ACCEPTABLE( c )	(( c >= '-' && c <= '9' ) ||	\
@@ -1325,3 +1118,279 @@
     htmladmin_strcat_escaped( p, s );
     return( p );
 }
+
+/* returns true if the given path is a valid directory, false otherwise */
+NSAPI_PUBLIC int
+util_is_dir_ok(const char *path)
+{
+    PRFileInfo prinfo;
+    int ret = 0;
+
+    if (path && *path &&
+	(PR_SUCCESS == PR_GetFileInfo(path, &prinfo)) &&
+	prinfo.type == PR_FILE_DIRECTORY) {
+	ret = 1;
+    }
+
+    return ret;
+}
+
+/* returns true if the given path is a valid file, false otherwise */
+NSAPI_PUBLIC int
+util_is_file_ok(const char *path)
+{
+    PRFileInfo prinfo;
+    int ret = 0;
+
+    if (path && *path &&
+	(PR_SUCCESS == PR_GetFileInfo(path, &prinfo)) &&
+	prinfo.type == PR_FILE_FILE) {
+	ret = 1;
+    }
+
+    return ret;
+}
+
+/* returns true if the file was found somewhere, false otherwise */
+NSAPI_PUBLIC int
+util_find_file_in_paths(
+    char *filebuf, /* this will be filled in with the full path/filename if found, '\0' otherwise */
+    size_t bufsize, /* size of filebuf e.g. sizeof(filebuf) */
+    const char *filename, /* the base filename to look for */
+    const char *path, /* path given by caller */
+    const char *arpath, /* path relative to ADMSERV_ROOT */
+    const char *nrpath /* path relative to NETSITE_ROOT */
+)
+{
+    int retval = 0;
+    const char *admroot = getenv("ADMSERV_ROOT");
+    const char *nsroot = getenv("NETSITE_ROOT");
+
+    /* try given path */
+    PR_snprintf(filebuf, bufsize, "%s/%s", path, filename);
+    retval = util_is_file_ok(filebuf);
+    if (!retval && admroot) { /* look in ADMSERV_ROOT */
+	PR_snprintf(filebuf, bufsize, "%s%s%s/%s", admroot,
+		    (arpath && *arpath) ? "/" : "",
+		    (arpath && *arpath) ? arpath : "",
+		    filename);
+	retval = util_is_file_ok(filebuf);
+    }
+    if (!retval && nsroot) { /* look in ADMSERV_ROOT */
+	PR_snprintf(filebuf, bufsize, "%s%s%s/%s", nsroot,
+		    (nrpath && *nrpath) ? "/" : "",
+		    (nrpath && *nrpath) ? nrpath : "",
+		    filename);
+	retval = util_is_file_ok(filebuf);
+    }
+
+    if (!retval) {
+	filebuf[0] = '\0';
+    }
+
+    return retval;
+}
+
+NSAPI_PUBLIC const char*
+util_get_conf_dir(void)
+{
+    const char *admroot = getenv("ADMSERV_ROOT");
+    const char *nsroot = getenv("NETSITE_ROOT");
+    static char confdir[PATH_MAX];
+
+    if (!confdir[0]) {
+        if (util_is_dir_ok(CONFIGDIR)) {
+            PR_snprintf(confdir, sizeof(confdir), CONFIGDIR);
+        } else if (util_is_dir_ok(admroot)) {
+            PR_snprintf(confdir, sizeof(confdir), admroot);
+        } else if (util_is_dir_ok(nsroot)) {
+            PR_snprintf(confdir, sizeof(confdir), "%s/admin-serv/config", nsroot);
+        } else {
+            return NULL;
+        }
+    }
+
+    return confdir;
+}
+
+NSAPI_PUBLIC const char*
+util_get_log_dir(void)
+{
+    const char *admroot = getenv("ADMSERV_ROOT");
+    const char *nsroot = getenv("NETSITE_ROOT");
+    static char logdir[PATH_MAX];
+
+    if (!logdir[0]) {
+        if (util_is_dir_ok(LOGDIR)) {
+            PR_snprintf(logdir, sizeof(logdir), LOGDIR);
+        } else if (util_is_dir_ok(admroot)) {
+            PR_snprintf(logdir, sizeof(logdir), "%s/../logs", admroot);
+        } else if (util_is_dir_ok(nsroot)) {
+            PR_snprintf(logdir, sizeof(logdir), "%s/admin-serv/logs", nsroot);
+        } else {
+            return NULL;
+        }
+    }
+
+    return logdir;
+}
+
+/* old style html dir == progpath/../html */
+#define HTML_DIR "../html/"
+
+NSAPI_PUBLIC const char*
+util_get_html_dir(void)
+{
+    const char *admroot = getenv("ADMSERV_ROOT");
+    const char *nsroot = getenv("NETSITE_ROOT");
+    static char htmldir[PATH_MAX];
+
+    if (!htmldir[0]) {
+        if (util_is_dir_ok(HTMLDIR)) {
+            PR_snprintf(htmldir, sizeof(htmldir), HTMLDIR);
+        } else if (util_is_dir_ok(admroot)) {
+            PR_snprintf(htmldir, sizeof(htmldir), "%s/../../bin/admin/admin/html", admroot);
+        } else if (util_is_dir_ok(nsroot)) {
+            PR_snprintf(htmldir, sizeof(htmldir), "%s/bin/admin/admin/html", nsroot);
+        } else {
+            PR_snprintf(htmldir, sizeof(htmldir), HTML_DIR);
+        }
+    }
+
+    return htmldir;
+}
+
+NSAPI_PUBLIC const char*
+util_get_icon_dir(void)
+{
+    const char *admroot = getenv("ADMSERV_ROOT");
+    const char *nsroot = getenv("NETSITE_ROOT");
+    static char icondir[PATH_MAX];
+
+    if (!icondir[0]) {
+        if (util_is_dir_ok(ICONDIR)) {
+            PR_snprintf(icondir, sizeof(icondir), ICONDIR);
+        } else if (util_is_dir_ok(admroot)) {
+            PR_snprintf(icondir, sizeof(icondir), "%s/../../bin/admin/admin/icons", admroot);
+        } else if (util_is_dir_ok(nsroot)) {
+            PR_snprintf(icondir, sizeof(icondir), "%s/bin/admin/admin/icons", nsroot);
+        } else {
+            return NULL;
+        }
+    }
+
+    return icondir;
+}
+
+/* return true if all of the chars in s are valid chars for use in
+   file and directory names, and false otherwise.  This means that
+   the string must begin with a letter or number, and must contain
+   letters, numbers, '.', '-' and '_'.
+   The main purpose of this is to see if a malicious client is sending
+   us bogus path names in an attempt to gain access or DoS.
+*/
+NSAPI_PUBLIC int
+util_is_valid_path_string(const char *s)
+{
+    int ret = 0;
+    if (s) {
+	if (isalnum(*s)) {
+	    ret = 1;
+	    for(; ret && *s; ++s) {
+		ret = isalnum(*s) || (*s == '-') || (*s == '_') || (*s == '.');
+	    }
+	}
+    }
+    return ret;
+}
+
+/* try various ways to determine if the given name is a valid
+   file or directory - this value is passed in as a form
+   parameter, and our motto is "Don't trust the user!"
+   If the given filetype is directory, also check to see if the optional
+   given filename (may be NULL) is in the given directory
+*/
+NSAPI_PUBLIC int
+util_verify_file_or_dir(
+    const char *name, /* name of file or directory to check */
+    PRFileType filetype, /* type of name */
+    const char *childname, /* optional child file/dir to check inside given parent name */
+    size_t childlen, /* only compare first childlen chars of childname - use -1 for entire string */
+    PRFileType childtype /* type of child */
+)
+{
+    int ret = 0;
+    PRFileInfo fileinfo;
+    /* first, just a simple access check */
+    PRStatus status = PR_GetFileInfo(name, &fileinfo);
+    ret = ((status == PR_SUCCESS) && (fileinfo.type == filetype));
+    if (ret) {
+	/* checks out ok - let's split it into the base name and the parent dir,
+	   open the parent dir, and see if the base name exists in the parent dir
+	*/
+	char *copy = PL_strdup(name);
+	size_t len = strlen(copy);
+	char *ptr = &copy[len-1];
+	/* get the basename - a really bad name may look like
+	   /path/foo/// or even ///////////////// */
+	for (; (ptr > copy) && (*ptr == '/'); --ptr) {
+	    /* do nothing */
+	}
+	if ((ptr == copy) && (*ptr == '/')) {
+	    /* bad - string consists of nothing but '/' */
+	    ptr = NULL;
+	    ret = 0;
+	} else {
+	    PRDir *pdir;
+	    PRDirEntry *pent;
+
+	    ret = 0;
+	    if (*ptr == '/') {
+		*ptr = 0; /* terminate the string at the first trailing '/' */
+	    }
+	    ptr = strrchr(copy, '/');
+	    if (!ptr) {
+		ptr = copy;
+		copy = PL_strdup(".");
+	    } else {
+		*ptr = 0;
+		++ptr;
+		ptr = PL_strdup(ptr);
+	    }
+	    /* copy now points at the parent, ptr at the child */
+	    if (pdir = PR_OpenDir(copy)) {
+		for(pent = PR_ReadDir(pdir, PR_SKIP_BOTH); pent && !ret;
+		    pent = PR_ReadDir(pdir, PR_SKIP_BOTH)) {
+		    ret = !strcmp(pent->name, ptr);
+		}
+		PR_CloseDir(pdir);
+	    }
+	    if (ret && childname && (filetype == PR_FILE_DIRECTORY)) {
+		ret = 0;
+		/* we've verified that name is a valid directory - see if
+		   the given filename exists in that directory */
+		if (pdir = PR_OpenDir(name)) {
+		    for(pent = PR_ReadDir(pdir, PR_SKIP_BOTH); pent && !ret;
+			pent = PR_ReadDir(pdir, PR_SKIP_BOTH)) {
+			if (childlen > 0) {
+			    ret = !strncmp(pent->name, childname, childlen);
+			} else {
+			    ret = !strcmp(pent->name, childname);
+			}
+		    }
+		    PR_CloseDir(pdir);
+		    if (ret) {
+			/* child exists - check type */
+			char *fullname = PR_smprintf("%s%c%s", name, FILE_PATHSEP, childname);
+			status = PR_GetFileInfo(fullname, &fileinfo);
+			ret = ((status == PR_SUCCESS) && (fileinfo.type == childtype));
+			PR_smprintf_free(fullname);
+		    }
+		}
+	    }
+	}
+	PL_strfree(copy);
+	PL_strfree(ptr);
+    }
+    return ret;
+}




More information about the Fedora-directory-commits mailing list