[icecast-dev] [PATCH] updates for the CVS version.

Ian Kumlien pomac at vapor.com
Sun May 19 17:22:05 PDT 2002



Hi, 

Since the version of the patch that went in to CVS didn't take chroot into
account, I did a patch that fixes this... 

Please keep in mind that i have been consuming alc, and i have been working at
a carneval all day... But i tested this and it works here.

//Ian Kumlien

PS. Might need some indent fixes.. but that should be all... 
DS.




--- icecast/src/main.c	Tue May 14 13:06:54 2002
+++ icecast.old/src/main.c	Mon May 20 02:04:55 2002
@@ -9,9 +9,6 @@
 #include "httpp.h"
 
 #ifdef CHUID
-#include <sys/types.h>
-#include <grp.h>
-#include <pwd.h>
 #include <errno.h>
 #endif
 
@@ -194,8 +191,6 @@
 static void _chuid_setup(void)
 {
    ice_config_t *conf = config_get_config();
-   struct passwd *user;
-   struct group *group;
    
    if(conf->chuid)
    {
@@ -205,16 +200,13 @@
            return;
        }
 
-       user = getpwnam(conf->user);
-       group = getgrnam(conf->group);
-       
-       if(!setgid(group->gr_gid))
-           fprintf(stdout, "Changed groupid to %i.\n", group->gr_gid);
+       if(!setgid(conf->gid))
+           fprintf(stdout, "Changed groupid to %i.\n", conf->gid);
        else
            fprintf(stdout, "Error changing groupid: %s.\n", strerror(errno));
 
-       if(!setuid(user->pw_uid))
-           fprintf(stdout, "Changed userid to %i.\n", user->pw_uid);
+       if(!setuid(conf->uid))
+           fprintf(stdout, "Changed userid to %i.\n", conf->uid);
        else
            fprintf(stdout, "Error changing userid: %s.\n", strerror(errno));
 
--- icecast/src/config.c	Tue May 14 13:06:54 2002
+++ icecast.old/src/config.c	Mon May 20 02:13:55 2002
@@ -4,6 +4,10 @@
 #include <xmlmemory.h>
 #include <parser.h>
 #include "config.h"
+#ifdef CHUID
+#include <pwd.h>
+#include <grp.h>
+#endif
 
 #define CONFIG_DEFAULT_LOCATION "Earth"
 #define CONFIG_DEFAULT_ADMIN "icemaster at localhost"
@@ -21,8 +25,8 @@
 #define CONFIG_DEFAULT_ERROR_LOG "error.log"
 #define CONFIG_DEFAULT_CHROOT 0
 #define CONFIG_DEFAULT_CHUID 0
-#define CONFIG_DEFAULT_USER NULL
-#define CONFIG_DEFAULT_GROUP NULL
+#define CONFIG_DEFAULT_UID 0
+#define CONFIG_DEFAULT_GID 0
 
 #ifndef _WIN32
 #define CONFIG_DEFAULT_BASE_DIR "/usr/local/icecast"
@@ -65,8 +69,6 @@
         if (_configuration.access_log) free(_configuration.access_log);
         if (_configuration.error_log) free(_configuration.error_log);
     if (_configuration.bind_address) free(_configuration.bind_address);
-    if (_configuration.user) free(_configuration.user);
-    if (_configuration.group) free(_configuration.group);
     dirnode = _configuration.dir_list;
     while(dirnode) {
         nextdirnode = dirnode->next;
@@ -147,8 +149,10 @@
         _configuration.error_log = (char *)strdup(CONFIG_DEFAULT_ERROR_LOG);
     _configuration.chroot = CONFIG_DEFAULT_CHROOT;
     _configuration.chuid = CONFIG_DEFAULT_CHUID;
-    _configuration.user = CONFIG_DEFAULT_USER;
-    _configuration.group = CONFIG_DEFAULT_GROUP;
+#ifdef CHUID
+    _configuration.uid = CONFIG_DEFAULT_UID;
+    _configuration.gid = CONFIG_DEFAULT_GID;
+#endif
 }
 
 static void _parse_root(xmlDocPtr doc, xmlNodePtr node)
@@ -282,6 +286,10 @@
 {
    char *tmp;
    xmlNodePtr oldnode;
+#ifdef CHUID
+   struct passwd *user;
+   struct group *group;
+#endif
 
    do {
        if (node == NULL) break;
@@ -298,12 +306,16 @@
            do {
                if(node == NULL) break;
                if(xmlIsBlankNode(node)) continue;
-               if(strcmp(node->name, "user") == 0) {
-                   if(_configuration.user) free(_configuration.user);
-                   _configuration.user = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
+	       if(strcmp(node->name, "user") == 0) {
+#ifdef CHUID
+                   if((user = getpwnam((char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1))))
+			   _configuration.uid = user->pw_uid;
+#endif
                } else if(strcmp(node->name, "group") == 0) {
-                   if(_configuration.group) free(_configuration.group);
-                   _configuration.group = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
+#ifdef CHUID
+		   if((group = getgrnam((char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1))))
+			   _configuration.gid = group->gr_gid;
+#endif
                }
            } while((node = node->next));
            node = oldnode;
--- icecast/src/config.h	Tue May 14 13:06:54 2002
+++ icecast.old/src/config.h	Mon May 20 02:14:15 2002
@@ -1,6 +1,10 @@
 #ifndef __CONFIG_H__
 #define __CONFIG_H__
 
+#ifdef CHUID
+#include <sys/types.h>
+#endif
+
 #define CONFIG_EINSANE -1
 #define CONFIG_ENOROOT -2
 #define CONFIG_EBADROOT -3
@@ -41,8 +45,10 @@
 
     int chroot;
     int chuid;
-    char *user;
-    char *group;
+#ifdef CHUID
+    uid_t uid;
+    gid_t gid;
+#endif
 } ice_config_t;
 
 void config_initialize(void);

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
icecast project homepage: http://www.icecast.org/
To unsubscribe from this list, send a message to 'icecast-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Icecast-dev mailing list