about summary refs log tree commit diff stats
path: root/WWW
diff options
context:
space:
mode:
Diffstat (limited to 'WWW')
-rw-r--r--WWW/Library/Implementation/HTAAProt.c224
-rw-r--r--WWW/Library/Implementation/HTAAProt.h70
-rw-r--r--WWW/Library/Implementation/HTAssoc.h2
-rw-r--r--WWW/Library/Implementation/HTFile.c28
-rw-r--r--WWW/Library/Implementation/HTString.h4
5 files changed, 239 insertions, 89 deletions
diff --git a/WWW/Library/Implementation/HTAAProt.c b/WWW/Library/Implementation/HTAAProt.c
index ceda12cb..0ad16671 100644
--- a/WWW/Library/Implementation/HTAAProt.c
+++ b/WWW/Library/Implementation/HTAAProt.c
@@ -29,11 +29,13 @@
 #include <HTAAUtil.h>
 #include <HTAAFile.h>
 #include <HTLex.h>	/* Lexical analysor	*/
-#include <HTAssoc.h>	/* Association list	*/
 #include <HTAAProt.h>	/* Implemented here	*/
 
 #include <LYLeaks.h>
 
+#define NOBODY    65534	/* -2 in 16-bit environment */
+#define NONESUCH  65533	/* -3 in 16-bit environment */
+
 /*
 ** Protection setup caching
 */
@@ -119,52 +121,31 @@ PUBLIC char * HTAA_getFileName NOARGS
 */
 PUBLIC int HTAA_getUid NOARGS
 {
-    struct passwd *pw = NULL;
+    int uid;
 
     if (current_prot  &&  current_prot->uid_name) {
 	if (isNumber(current_prot->uid_name)) {
-	    if (NULL != (pw = getpwuid(atoi(current_prot->uid_name)))) {
-		CTRACE(tfp, "%s(%s) returned (%s:%s:%d:%d:...)\n",
-			    "HTAA_getUid: getpwuid",
-			    current_prot->uid_name,
-				   pw->pw_name,
-#ifndef __MVS__  /* S/390 -- gil -- 0018 */
-				                pw->pw_passwd,
-#else
-				                "(none)",
-#endif /* __MVS __ */
-			    (int) pw->pw_uid, (int) pw->pw_gid);
-		return pw->pw_uid;
+	    uid = atoi(current_prot->uid_name);
+	    if ((*HTAA_UidToName (uid)) != '\0') {
+		return uid;
 	    }
 	}
 	else {	/* User name (not a number) */
-	    if (NULL != (pw = getpwnam(current_prot->uid_name))) {
-		CTRACE(tfp, "%s(\"%s\") %s (%s:%s:%d:%d:...)\n",
-			    "HTAA_getUid: getpwnam",
-			    current_prot->uid_name, "returned",
-				   pw->pw_name,
-#ifndef __MVS__  /* S/390 -- gil -- 0040 */
-				                pw->pw_passwd,
-#else
-				                "(none)",
-#endif /* __MVS __ */
-			    (int) pw->pw_uid, (int) pw->pw_gid);
-		return pw->pw_uid;
+	    if ((uid = HTAA_NameToUid (current_prot->uid_name)) != NONESUCH) {
+		return uid;
 	    }
 	}
     }
     /*
     ** Ok, then let's get uid for nobody.
     */
-    if (NULL != (pw = getpwnam("nobody"))) {
-	CTRACE(tfp, "HTAA_getUid: Uid for `nobody' is %d\n",
-		    (int) pw->pw_uid);
-	return pw->pw_uid;
+    if ((uid = HTAA_NameToUid ("nobody")) != NONESUCH) {
+	return uid;
     }
     /*
     ** Ok, then use default.
     */
-    return 65534;	/* nobody */
+    return NOBODY;	/* nobody */
 }
 
 
@@ -179,44 +160,31 @@ PUBLIC int HTAA_getUid NOARGS
 */
 PUBLIC int HTAA_getGid NOARGS
 {
-    struct group *gr = NULL;
+    int gid;
 
     if (current_prot  &&  current_prot->gid_name) {
 	if (isNumber(current_prot->gid_name)) {
-	    if (NULL != (gr = getgrgid(atoi(current_prot->gid_name)))) {
-#if !defined(__EMX__) && !defined(__MVS__)  /* no gr_passwd  S/390 -- gil -- 0061 */
-		CTRACE(tfp, "%s(%s) returned (%s:%s:%d:...)\n",
-			    "HTAA_getGid: getgrgid",
-			    current_prot->gid_name,
-			    gr->gr_name, gr->gr_passwd, (int) gr->gr_gid);
-#endif
-		return gr->gr_gid;
+	    gid = atoi(current_prot->gid_name);
+	    if (*HTAA_GidToName(gid) != '\0') {
+		return gid;
 	    }
 	}
 	else {	/* Group name (not number) */
-	    if (NULL != (gr = getgrnam(current_prot->gid_name))) {
-#if !defined(__EMX__) && !defined(__MVS__)  /* no gr_passwd  S/390 -- gil -- 0078 */
-		CTRACE(tfp, "%s(\"%s\") returned (%s:%s:%d:...)\n",
-			    "HTAA_getGid: getgrnam",
-			    current_prot->gid_name,
-			    gr->gr_name, gr->gr_passwd, (int) gr->gr_gid);
-#endif
-		return gr->gr_gid;
+	    if ((gid = HTAA_NameToGid (current_prot->gid_name)) != NONESUCH) {
+		return gid;
 	    }
 	}
     }
     /*
     ** Ok, then let's get gid for nogroup.
     */
-    if (NULL != (gr = getgrnam("nogroup"))) {
-	CTRACE(tfp, "HTAA_getGid: Gid for `nogroup' is %d\n",
-		    (int) gr->gr_gid);
-	return gr->gr_gid;
+    if ((gid = HTAA_NameToGid ("nogroup")) != NONESUCH) {
+	return gid;
     }
     /*
     ** Ok, then use default.
     */
-    return 65534;	/* nogroup */
+    return NOBODY;	/* nogroup */
 }
 #endif /* not VMS */
 
@@ -602,3 +570,153 @@ PUBLIC void HTAA_clearProtections NOARGS
     current_prot = NULL;	/* These are not freed because	*/
     default_prot = NULL;	/* they are actually in cache.	*/
 }
+
+typedef struct {
+    	char *name;
+	int user;
+    	} USER_DATA;
+
+PRIVATE HTList *known_grp;
+PRIVATE HTList *known_pwd;
+
+PRIVATE void save_gid_info ARGS2(char *, name, int, user)
+{
+    USER_DATA *data = calloc(1, sizeof(USER_DATA));
+    if (HTList_isEmpty(known_grp))
+	known_grp = HTList_new();
+    StrAllocCopy(data->name, name);
+    data->user = user;
+    HTList_addObject (known_grp, data);
+}
+
+PRIVATE void save_uid_info ARGS2(char *, name, int, user)
+{
+    USER_DATA *data = calloc(1, sizeof(USER_DATA));
+    if (HTList_isEmpty(known_pwd))
+	known_pwd = HTList_new();
+    StrAllocCopy(data->name, name);
+    data->user = user;
+    HTList_addObject (known_pwd, data);
+}
+
+/* PUBLIC                                                       HTAA_UidToName
+**              GET THE USER NAME
+** ON ENTRY:
+**      The user-id
+**
+** ON EXIT:
+**      returns the user name, or an empty string if not found.
+*/
+PUBLIC char * HTAA_UidToName ARGS1(int, uid)
+{
+    struct passwd *pw;
+    HTList *me = known_pwd;
+
+    while (HTList_nextObject(me)) {
+	USER_DATA *data = (USER_DATA *)(me->object);
+	if (uid == data->user)
+	    return data->name;
+    }
+
+    if ((pw = getpwuid(uid)) != 0
+     && pw->pw_name != 0) {
+	CTRACE(tfp, "%s(%d) returned (%s:%d:...)\n",
+		    "HTAA_UidToName: getpwuid",
+		    uid,
+		    pw->pw_name, (int) pw->pw_uid);
+	save_uid_info(pw->pw_name, pw->pw_uid);
+	return pw->pw_name;
+    }
+    return "";
+}
+
+/* PUBLIC                                                       HTAA_NameToUid
+**              GET THE USER ID
+** ON ENTRY:
+**      The user-name
+**
+** ON EXIT:
+**      returns the user id, or NONESUCH if not found.
+*/
+PUBLIC int HTAA_NameToUid ARGS1(char *, name)
+{
+    struct passwd *pw;
+    HTList *me = known_pwd;
+
+    while (HTList_nextObject(me)) {
+	USER_DATA *data = (USER_DATA *)(me->object);
+	if (!strcmp(name, data->name))
+	    return data->user;
+    }
+
+    if ((pw = getpwnam(name)) != 0) {
+	CTRACE(tfp, "%s(%s) returned (%s:%d:...)\n",
+		    "HTAA_NameToUid: getpwnam",
+		    name,
+		    pw->pw_name, (int) pw->pw_uid);
+	save_uid_info(pw->pw_name, pw->pw_uid);
+	return pw->pw_uid;
+    }
+    return NONESUCH;
+}
+
+/* PUBLIC                                                       HTAA_GidToName
+**              GET THE GROUP NAME
+** ON ENTRY:
+**      The group-id
+**
+** ON EXIT:
+**      returns the group name, or an empty string if not found.
+*/
+PUBLIC char * HTAA_GidToName ARGS1(int, gid)
+{
+    struct group *gr;
+    HTList *me = known_grp;
+
+    while (HTList_nextObject(me)) {
+	USER_DATA *data = (USER_DATA *)(me->object);
+	if (gid == data->user)
+	    return data->name;
+    }
+
+    if ((gr = getgrgid(gid)) != 0
+     && gr->gr_name != 0) {
+	CTRACE(tfp, "%s(%d) returned (%s:%d:...)\n",
+		    "HTAA_GidToName: getgrgid",
+		    gid,
+		    gr->gr_name, (int) gr->gr_gid);
+	save_gid_info(gr->gr_name, gr->gr_gid);
+	return gr->gr_name;
+    }
+    return "";
+}
+
+/* PUBLIC                                                       HTAA_NameToGid
+**              GET THE GROUP ID
+** ON ENTRY:
+**      The group-name
+**
+** ON EXIT:
+**      returns the group id, or NONESUCH if not found.
+*/
+PUBLIC int HTAA_NameToGid ARGS1(char *, name)
+{
+    struct group *gr;
+    HTList *me = known_grp;
+
+    while (HTList_nextObject(me)) {
+	USER_DATA *data = (USER_DATA *)(me->object);
+	if (!strcmp(name, data->name))
+	    return data->user;
+    }
+
+    if ((gr = getgrnam(name)) != 0) {
+	CTRACE(tfp, "%s(%s) returned (%s:%d:...)\n",
+		    "HTAA_NameToGid: getgrnam",
+		    name,
+		    gr->gr_name, (int) gr->gr_gid);
+	save_gid_info(gr->gr_name, gr->gr_gid);
+	return gr->gr_gid;
+    }
+    return NONESUCH;
+}
diff --git a/WWW/Library/Implementation/HTAAProt.h b/WWW/Library/Implementation/HTAAProt.h
index ed36f656..e423983b 100644
--- a/WWW/Library/Implementation/HTAAProt.h
+++ b/WWW/Library/Implementation/HTAAProt.h
@@ -9,13 +9,13 @@
 #include <HTAssoc.h>
 
 #ifdef SHORT_NAMES
-#define HTAAgUid        HTAA_getUid
-#define HTAAgGid        HTAA_getGid
-#define HTAAgDPr        HTAA_setDefaultProtection
-#define HTAAsCPr        HTAA_setCurrentProtection
-#define HTAAgCPr        HTAA_getCurrentProtection
-#define HTAAgDPr        HTAA_getDefaultProtection
-#define HTAAclPr        HTAA_clearProtections
+#define HTAA_getUid			HTAAgUid        
+#define HTAA_getGid			HTAAgGid        
+#define HTAA_setDefaultProtection	HTAAgDPr        
+#define HTAA_setCurrentProtection	HTAAsCPr        
+#define HTAA_getCurrentProtection	HTAAgCPr        
+#define HTAA_getDefaultProtection	HTAAgDPr        
+#define HTAA_clearProtections		HTAAclPr        
 #endif /*SHORT_NAMES*/
 /*
 
@@ -68,7 +68,7 @@ Callbacks for rule system
 **      returns         nothing.
 **                      Sets the module-wide variable default_prot.
 */
-PUBLIC void HTAA_setDefaultProtection PARAMS((CONST char *      cur_docname,
+extern void HTAA_setDefaultProtection PARAMS((CONST char *      cur_docname,
                                               CONST char *      prot_filename,
                                               CONST char *      eff_ids));
 
@@ -93,7 +93,7 @@ PUBLIC void HTAA_setDefaultProtection PARAMS((CONST char *      cur_docname,
 **      returns         nothing.
 **                      Sets the module-wide variable current_prot.
 */
-PUBLIC void HTAA_setCurrentProtection PARAMS((CONST char *      cur_docname,
+extern void HTAA_setCurrentProtection PARAMS((CONST char *      cur_docname,
                                               CONST char *      prot_filename,
                                               CONST char *      eff_ids));
 
@@ -109,7 +109,7 @@ PUBLIC void HTAA_setCurrentProtection PARAMS((CONST char *      cur_docname,
 **      returns nothing.
 **              Frees the memory used by protection information.
 */
-PUBLIC void HTAA_clearProtections NOPARAMS;
+extern void HTAA_clearProtections NOPARAMS;
 /*
 
 Getting Protection Settings
@@ -137,7 +137,7 @@ Getting Protection Settings
 **              protection setup of the HTTranslate()'d file.
 **              This must not be free()'d.
 */
-PUBLIC HTAAProt *HTAA_getCurrentProtection NOPARAMS;
+extern HTAAProt *HTAA_getCurrentProtection NOPARAMS;
 
 
 
@@ -159,7 +159,7 @@ PUBLIC HTAAProt *HTAA_getCurrentProtection NOPARAMS;
 **              protection settings).
 **              This must not be free()'d.
 */
-PUBLIC HTAAProt *HTAA_getDefaultProtection NOPARAMS;
+extern HTAAProt *HTAA_getDefaultProtection NOPARAMS;
 /*
 
 Get User and Group IDs to Which Set to
@@ -176,7 +176,7 @@ Get User and Group IDs to Which Set to
 **      returns the uid number to give to setuid() system call.
 **              Default is 65534 (nobody).
 */
-PUBLIC int HTAA_getUid NOPARAMS;
+extern int HTAA_getUid NOPARAMS;
 
 
 /* PUBLIC                                                       HTAA_getGid()
@@ -188,7 +188,7 @@ PUBLIC int HTAA_getUid NOPARAMS;
 **      returns the uid number to give to setgid() system call.
 **              Default is 65534 (nogroup).
 */
-PUBLIC int HTAA_getGid NOPARAMS;
+extern int HTAA_getGid NOPARAMS;
 #endif /* not VMS */
 /*
 
@@ -206,7 +206,7 @@ PUBLIC int HTAA_getGid NOPARAMS;
 **      returns the user name
 **              Default is "" (nobody).
 */
-PUBLIC char * HTAA_getUidName NOPARAMS;
+extern char * HTAA_getUidName NOPARAMS;
 
 /* PUBLIC                                                       HTAA_getFileName
 **              GET THE FILENAME (VMS ONLY)
@@ -216,8 +216,46 @@ PUBLIC char * HTAA_getUidName NOPARAMS;
 ** ON EXIT:
 **      returns the filename
 */
-PUBLIC char * HTAA_getFileName NOPARAMS;
+extern char * HTAA_getFileName NOPARAMS;
 #endif /* VMS */
+
+/* PUBLIC                                                       HTAA_UidToName
+**              GET THE USER NAME
+** ON ENTRY:
+**      The user-id
+**
+** ON EXIT:
+**      returns the user name
+*/
+extern char * HTAA_UidToName PARAMS((int uid));
+/* PUBLIC                                                       HTAA_NameToUid
+**              GET THE USER ID
+** ON ENTRY:
+**      The user-name
+**
+** ON EXIT:
+**      returns the user id
+*/
+extern int HTAA_NameToUid PARAMS((char *name));
+/* PUBLIC                                                       HTAA_GidToName
+**              GET THE GROUP NAME
+** ON ENTRY:
+**      The group-id
+**
+** ON EXIT:
+**      returns the group name
+*/
+extern char * HTAA_GidToName PARAMS((int gid));
+/* PUBLIC                                                       HTAA_NameToGid
+**              GET THE GROUP ID
+** ON ENTRY:
+**      The group-name
+**
+** ON EXIT:
+**      returns the group id
+*/
+extern int HTAA_NameToGid PARAMS((char *name));
+
 /*
 
  */
diff --git a/WWW/Library/Implementation/HTAssoc.h b/WWW/Library/Implementation/HTAssoc.h
index 93183302..54db9487 100644
--- a/WWW/Library/Implementation/HTAssoc.h
+++ b/WWW/Library/Implementation/HTAssoc.h
@@ -1,6 +1,6 @@
 /*                       ASSOCIATION LIST FOR STORING NAME-VALUE PAIRS
                                              
-   Lookups from assosiation list are not case-sensitive.
+   Lookups from association list are not case-sensitive.
    
  */
 
diff --git a/WWW/Library/Implementation/HTFile.c b/WWW/Library/Implementation/HTFile.c
index 3e030de0..a4f35b1a 100644
--- a/WWW/Library/Implementation/HTFile.c
+++ b/WWW/Library/Implementation/HTFile.c
@@ -38,13 +38,6 @@
 #include <stat.h>
 #endif /* VMS */
 
-#ifndef VMS
-#ifdef LONG_LIST
-#include <pwd.h>
-#include <grp.h>
-#endif /* LONG_LIST */
-#endif /* !VMS */
-
 #ifdef USE_ZLIB
 #include <GridText.h>
 #endif
@@ -59,6 +52,7 @@
 #endif /* !DECNET */
 #include <HTAnchor.h>
 #include <HTAtom.h>
+#include <HTAAProt.h>
 #include <HTWriter.h>
 #include <HTFWriter.h>
 #include <HTInit.h>
@@ -173,8 +167,7 @@ PRIVATE void LYListFmtParse ARGS5(
 	char buf[512];
 	char fmt[512];
 	char type;
-	struct passwd *p;
-	struct group *g;
+	char *name;
 	time_t now;
 	char *datestr;
 	int len;
@@ -308,10 +301,10 @@ PRIVATE void LYListFmtParse ARGS5(
 
 		case 'o':	/* owner */
 			sprintf(fmt, "%%%ss", start);
-			p = getpwuid(st.st_uid);
-			if (p) {
+			name = HTAA_UidToName (st.st_uid);
+			if (*name) {
 				sprintf(fmt, "%%%ss", start);
-				sprintf(buf, fmt, p->pw_name);
+				sprintf(buf, fmt, name);
 			} else {
 
 				sprintf(fmt, "%%%sd", start);
@@ -320,10 +313,10 @@ PRIVATE void LYListFmtParse ARGS5(
 			break;
 
 		case 'g':	/* group */
-			g = getgrgid(st.st_gid);
-			if (g) {
+			name = HTAA_GidToName(st.st_gid);
+			if (*name) {
 				sprintf(fmt, "%%%ss", start);
-				sprintf(buf, fmt, g->gr_name);
+				sprintf(buf, fmt, name);
 			} else {
 				sprintf(fmt, "%%%sd", start);
 				sprintf(buf, fmt, st.st_gid);
@@ -1545,14 +1538,15 @@ PUBLIC int HTLoadFile ARGS4(
 	**  If the file wasn't VMS syntax, then perhaps it is Ultrix.
 	*/
 	if (!fp) {
-	    char ultrixname[INFINITY];
+	    char * ultrixname = 0;
 	    CTRACE(tfp, "HTLoadFile: Can't open as %s\n", vmsname);
-	    sprintf(ultrixname, "%s::\"%s\"", nodename, filename);
+	    HTSprintf0(&ultrixname, "%s::\"%s\"", nodename, filename);
 	    fp = fopen(ultrixname, "r", "shr=put", "shr=upd");
 	    if (!fp) {
 		CTRACE(tfp, "HTLoadFile: Can't open as %s\n",
 			    ultrixname);
 	    }
+	    FREE(ultrixname);
 	}
 	if (fp) {
 	    int len;
diff --git a/WWW/Library/Implementation/HTString.h b/WWW/Library/Implementation/HTString.h
index 6b039896..6e4e5591 100644
--- a/WWW/Library/Implementation/HTString.h
+++ b/WWW/Library/Implementation/HTString.h
@@ -54,9 +54,9 @@ extern char * HTNextTok PARAMS((char ** pstr,
 		      CONST char * delims, CONST char * bracks, char * found));
 
 #if ANSI_VARARGS
-extern char * HTSprintf PARAMS((char ** pstr, CONST char * fmt, ...))
+extern char * HTSprintf (char ** pstr, CONST char * fmt, ...)
 			GCC_PRINTFLIKE(2,3);
-extern char * HTSprintf0 PARAMS((char ** pstr, CONST char * fmt, ...))
+extern char * HTSprintf0 (char ** pstr, CONST char * fmt, ...)
 			 GCC_PRINTFLIKE(2,3);
 #else
 extern char * HTSprintf () GCC_PRINTFLIKE(2,3);