Changeset 379

Show
Ignore:
Timestamp:
08/31/06 20:28:05 (2 years ago)
Author:
alo
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cherokee/trunk/cherokee/Makefile.am

    r370 r379  
    544544else 
    545545dynamic_validator_htdigest_lib = libplugin_htdigest.la 
     546endif 
     547 
     548 
     549# 
     550# Balancer Round Robin 
     551# 
     552balancer_round_robin = \ 
     553balancer_round_robin.c \ 
     554balancer_round_robin.h 
     555 
     556libplugin_round_robin_la_LDFLAGS = $(module_ldflags)  
     557libplugin_round_robin_la_SOURCES = $(balancer_round_robin) 
     558 
     559if STATIC_BALANCER_ROUND_ROBIN 
     560static_balancer_round_robin_src = $(balancer_round_robin) 
     561else 
     562dynamic_balancer_round_robin_lib = libplugin_round_robin.la 
    546563endif 
    547564 
     
    764781$(static_validator_htpasswd_src) \ 
    765782\ 
     783$(static_balancer_round_robin_src) \ 
     784\ 
    766785$(common_cgi) \ 
    767786\ 
     
    886905$(dynamic_validator_plain_lib) \ 
    887906$(dynamic_validator_htdigest_lib) \ 
    888 $(dynamic_validator_htpasswd_lib) 
     907$(dynamic_validator_htpasswd_lib) \ 
     908$(dynamic_balancer_round_robin_lib)  
    889909 
    890910 
  • cherokee/trunk/cherokee/balancer.h

    r372 r379  
    4444 
    4545 
     46/* Handler properties 
     47 */ 
     48typedef ret_t (* balancer_props_func_free_t)  (void  *balancerp); 
     49 
     50typedef struct { 
     51        balancer_props_func_free_t free; 
     52} cherokee_balancer_props_t; 
     53 
     54 
    4655/* Balancer 
    4756 */ 
  • cherokee/trunk/cherokee/connection.c

    r376 r379  
    11611161cherokee_connection_build_local_directory_userdir (cherokee_connection_t *conn, cherokee_virtual_server_t *vsrv, cherokee_config_entry_t *entry) 
    11621162{ 
    1163         struct passwd *pwd;      
     1163        ret_t         ret; 
     1164        struct passwd pwd; 
     1165        char          tmp[1024]; 
    11641166 
    11651167        /* Has a defined DocumentRoot 
     
    11821184        /* Default: it is inside the UserDir in home 
    11831185         */ 
    1184         pwd = (struct passwd *) getpwnam (conn->userdir.buf); 
    1185         if ((pwd == NULL) || (pwd->pw_dir == NULL)) { 
     1186        ret = cherokee_getpwnam (conn->userdir.buf, &pwd, tmp, 1024); 
     1187        if ((ret != ret_ok) || (pwd.pw_dir == NULL)) { 
    11861188                conn->error_code = http_not_found; 
    11871189                return ret_error; 
    11881190        } 
    1189  
     1191         
    11901192        /* Build the local_directory: 
    11911193         */ 
    1192         cherokee_buffer_add (&conn->local_directory, pwd->pw_dir, strlen(pwd->pw_dir)); 
    1193         cherokee_buffer_add (&conn->local_directory, "/", 1); 
     1194        cherokee_buffer_add (&conn->local_directory, pwd.pw_dir, strlen(pwd.pw_dir)); 
     1195        cherokee_buffer_add_str (&conn->local_directory, "/"); 
    11941196        cherokee_buffer_add_buffer (&conn->local_directory, &vsrv->userdir); 
    11951197 
  • cherokee/trunk/cherokee/handler.h

    r370 r379  
    6060 
    6161typedef struct { 
    62         handler_props_func_free_t   free; 
     62        handler_props_func_free_t free; 
    6363} cherokee_handler_props_t; 
    6464 
  • cherokee/trunk/cherokee/handler_error_redir.c

    r378 r379  
    102102 
    103103ret_t  
    104 cherokee_handler_error_redir_new (cherokee_handler_t **hdl, cherokee_connection_t *cnt, cherokee_handler_props_t *props) 
     104cherokee_handler_error_redir_new (cherokee_handler_t **hdl, cherokee_connection_t *conn, cherokee_handler_props_t *props) 
    105105{ 
    106106        list_t *i; 
     
    109109                error_entry_t *entry = (error_entry_t *)i; 
    110110                 
    111                 if (entry->error != cnt->error_code) 
     111                if (entry->error != conn->error_code) 
    112112                        continue; 
    113113 
    114                 cherokee_buffer_clean (&cnt->redirect); 
    115                 cherokee_buffer_add_buffer (&cnt->redirect, &entry->url);  
     114                cherokee_buffer_clean (&conn->redirect); 
     115                cherokee_buffer_add_buffer (&conn->redirect, &entry->url);  
    116116                 
    117                 cnt->error_code = http_moved_permanently;  
    118                 return cherokee_handler_redir_new (hdl, cnt, props); 
     117                conn->error_code = http_moved_permanently;  
     118                return cherokee_handler_redir_new (hdl, conn, props); 
    119119        } 
    120120         
  • cherokee/trunk/cherokee/module.h

    r347 r379  
    4444        cherokee_handler   = 1 << 2, 
    4545        cherokee_encoder   = 1 << 3, 
    46         cherokee_validator = 1 << 4 
     46        cherokee_validator = 1 << 4, 
     47        cherokee_balancer  = 1 << 5 
    4748} cherokee_module_type_t; 
    4849 
  • cherokee/trunk/cherokee/util.c

    r370 r379  
    10801080        return ret_ok; 
    10811081} 
     1082 
     1083 
     1084 
     1085#if defined(HAVE_PTHREAD) && !defined(HAVE_GETPWNAM_R) 
     1086static pthread_mutex_t __global_getpwnam_mutex = PTHREAD_MUTEX_INITIALIZER; 
     1087#endif 
     1088 
     1089ret_t  
     1090cherokee_getpwnam (const char *name, struct passwd *pwbuf, char *buf, size_t buflen) 
     1091{ 
     1092#ifndef HAVE_GETPWNAM_R 
     1093        size_t         pw_name_len   = 0; 
     1094        size_t         pw_passwd_len = 0; 
     1095        size_t         pw_gecos_len  = 0; 
     1096        size_t         pw_dir_len    = 0; 
     1097        size_t         pw_shell_len  = 0; 
     1098        char          *ptr; 
     1099        struct passwd *tmp; 
     1100 
     1101        CHEROKEE_MUTEX_LOCK (&__global_getpwnam_mutex); 
     1102         
     1103        tmp = getpwnam (name); 
     1104        if (tmp == NULL)  
     1105                return ret_error; 
     1106 
     1107        if (tmp->pw_name)   pw_name_len   = strlen(tmp->pw_name); 
     1108        if (tmp->pw_passwd) pw_passwd_len = strlen(tmp->pw_passwd); 
     1109        if (tmp->pw_gecos)  pw_gecos_len  = strlen(tmp->pw_gecos); 
     1110        if (tmp->pw_dir)    pw_dir_len    = strlen(tmp->pw_dir); 
     1111        if (tmp->pw_shell)  pw_shell_len  = strlen(tmp->pw_shell); 
     1112 
     1113        if ((pw_name_len + pw_passwd_len +  
     1114             pw_gecos_len + pw_dir_len + pw_shell_len) > buflen) 
     1115                return ret_error; 
     1116 
     1117        memset (buf, 0, buflen); 
     1118        ptr = buf; 
     1119 
     1120        pwbuf->pw_uid = tmp->pw_uid; 
     1121        pwbuf->pw_gid = tmp->pw_gid; 
     1122 
     1123        if (tmp->pw_dir) { 
     1124                memcpy (ptr, tmp->pw_dir, pw_dir_len); 
     1125                pwbuf->pw_dir = ptr; 
     1126                ptr += pw_dir_len + 1; 
     1127        } 
     1128 
     1129        if (tmp->pw_passwd) { 
     1130                memcpy (ptr, tmp->pw_passwd, pw_passwd_len); 
     1131                pwbuf->pw_passwd = ptr; 
     1132                ptr += pw_passwd_len + 1; 
     1133        } 
     1134 
     1135        if (tmp->pw_name) { 
     1136                memcpy (ptr, tmp->pw_name, pw_name_len); 
     1137                pwbuf->pw_name = ptr; 
     1138                ptr += pw_name_len + 1; 
     1139        } 
     1140 
     1141        if (tmp->pw_gecos) { 
     1142                memcpy (ptr, tmp->pw_gecos, pw_gecos_len); 
     1143                pwbuf->pw_gecos = ptr; 
     1144                ptr += pw_gecos_len + 1; 
     1145        } 
     1146 
     1147        if (tmp->pw_shell) { 
     1148                memcpy (ptr, tmp->pw_shell, pw_shell_len); 
     1149                pwbuf->pw_shell = ptr; 
     1150                ptr += pw_shell_len + 1; 
     1151        } 
     1152 
     1153        CHEROKEE_MUTEX_UNLOCK (&__global_getpwnam_mutex); 
     1154        return ret_ok; 
     1155 
     1156#elif HAVE_GETPWNAM_R_5 
     1157        int            re; 
     1158        struct passwd *tmp; 
     1159 
     1160        re = getpwnam_r (name, pwbuf, buf, buflen, &tmp); 
     1161        if (re != 0) return ret_error; 
     1162 
     1163        return ret_ok; 
     1164 
     1165#elif HAVE_GETPWNAM_R_4 
     1166        int re; 
     1167 
     1168        re = getpwnam_r (name, pwbuf, buf, buflen); 
     1169        if (re != 0) return ret_error; 
     1170 
     1171        return ret_ok; 
     1172#endif 
     1173 
     1174        return ret_no_sys; 
     1175} 
     1176 
     1177 
     1178#if defined(HAVE_PTHREAD) && !defined(HAVE_GETGRNAM_R) 
     1179static pthread_mutex_t __global_getgrnam_mutex = PTHREAD_MUTEX_INITIALIZER; 
     1180#endif 
     1181 
     1182ret_t  
     1183cherokee_getgrnam (const char *name, struct group *grbuf, char *buf, size_t buflen) 
     1184{ 
     1185#ifndef HAVE_GETGRNAM_R 
     1186        size_t        gr_name_len   = 0; 
     1187        size_t        gr_passwd_len = 0; 
     1188        char         *ptr; 
     1189        struct group *tmp; 
     1190 
     1191        CHEROKEE_MUTEX_LOCK (&__global_getgrnam_mutex); 
     1192 
     1193        tmp = getgrnam (name); 
     1194        if (tmp == NULL)  
     1195                return ret_error; 
     1196 
     1197        if (tmp->gr_name)   gr_name_len   = strlen(tmp->gr_name); 
     1198        if (tmp->gr_passwd) gr_passwd_len = strlen(tmp->gr_passwd); 
     1199 
     1200        if ((gr_name_len + gr_passwd_len) > buflen) 
     1201                return ret_error; 
     1202 
     1203        memset (buf, 0, buflen); 
     1204        ptr = buf; 
     1205 
     1206        grbuf->gr_gid = tmp->gr_gid; 
     1207 
     1208        if (tmp->gr_name) { 
     1209                memcpy (ptr, tmp->gr_name, gr_name_len); 
     1210                grbuf->gr_name = ptr; 
     1211                ptr += gr_name_len + 1; 
     1212        } 
     1213 
     1214        if (tmp->gr_passwd) { 
     1215                memcpy (ptr, tmp->gr_passwd, gr_passwd_len); 
     1216                grbuf->gr_passwd = ptr; 
     1217                ptr += gr_passwd_len + 1; 
     1218        } 
     1219 
     1220        // TODO: Duplicate char **tmp->gr_mem 
     1221 
     1222        CHEROKEE_MUTEX_UNLOCK (&__global_getgrnam_mutex); 
     1223        return ret_ok; 
     1224 
     1225#elif HAVE_GETGRNAM_R_5 
     1226        int           re; 
     1227        struct group *tmp; 
     1228 
     1229        re = getgrnam_r (name, grbuf, buf, buflen, &tmp); 
     1230        if (re != 0) return ret_error; 
     1231 
     1232        return ret_ok; 
     1233 
     1234#elif HAVE_GETGRNAM_R_4 
     1235        int re; 
     1236 
     1237        re = getgrnam_r (name, grbuf, buf, buflen); 
     1238        if (re != 0) return ret_error; 
     1239 
     1240        return ret_ok; 
     1241#endif 
     1242 
     1243        return ret_no_sys; 
     1244} 
  • cherokee/trunk/cherokee/util.h

    r370 r379  
    4141#endif  
    4242 
     43#include <pwd.h> 
     44#include <grp.h> 
     45 
    4346#include <time.h> 
    4447#include <dirent.h> 
     
    7780/* Time management functions 
    7881 */ 
    79  
    8082struct tm *cherokee_gmtime           (const time_t *timep, struct tm *result); 
    8183struct tm *cherokee_localtime        (const time_t *timep, struct tm *result); 
     
    8789ret_t cherokee_gethostbyname (const char *hostname, void *addr); 
    8890ret_t cherokee_syslog        (int priority, cherokee_buffer_t *buf); 
     91ret_t cherokee_getpwnam      (const char *name, struct passwd *pwbuf, char *buf, size_t buflen); 
     92ret_t cherokee_getgrnam      (const char *name, struct group *pwbuf, char *buf, size_t buflen); 
    8993 
    9094/* Misc 
  • cherokee/trunk/configure.in

    r370 r379  
    212212AC_CHECK_FUNCS(gmtime gmtime_r localtime localtime_r getrlimit getdtablesize readdir readdir_r flockfile funlockfile) 
    213213 
     214FW_CHECK_PWD 
     215FW_CHECK_GRP 
    214216 
    215217AH_BOTTOM([ 
     
    920922           [use_static_module="$use_static_module $enableval "],[]) 
    921923 
    922 modules="error_redir server_info file admin dirlist fcgi fastcgi scgi redir common nn cgi phpcgi proxy gzip ncsa combined w3c pam ldap htpasswd plain htdigest
     924modules="error_redir server_info file admin dirlist fcgi fastcgi scgi redir common nn cgi phpcgi proxy gzip ncsa combined w3c pam ldap htpasswd plain htdigest round_robin
    923925 
    924926# Remove modules that will not be compiles 
     
    985987AM_CONDITIONAL(STATIC_VALIDATOR_PLAIN,        grep plain          $conf_h >/dev/null) 
    986988AM_CONDITIONAL(STATIC_VALIDATOR_HTDIGEST,     grep htdigest       $conf_h >/dev/null) 
     989AM_CONDITIONAL(STATIC_BALANCER_ROUND_ROBIN,   grep round_robin    $conf_h >/dev/null) 
    987990 
    988991AC_OUTPUT(Makefile cherokee/Makefile.MingW m4/Makefile cherokee/Makefile cget/Makefile icons/Makefile themes/Makefile www/Makefile doc/Makefile doc/develop/Makefile doc/develop/doxygen.cfg contrib/Makefile qa/Makefile windows/Makefile  cherokee-config cherokee.spec cherokee.pc windows/cherokee.nsi) 
  • cherokee/trunk/m4/Makefile.am

    r324 r379  
    33network.m4 \ 
    44sendfile_samba.m4 \ 
    5 etr_socket_nsl.m4  
     5etr_socket_nsl.m4 \ 
     6pwd_grp.m4