Profil supprimé | Puisque c'est si gentillement demandé
Voici les parties du code qui pourraient poser problème :
Code :
- typedef struct _configs {
- char* nom;
- int n;
- char** params;
- struct _configs* next;
- } configs;
- typedef struct _users {
- char* nom;
- char* type;
- char* open_basedir;
- struct _users* last;
- struct _users* next;
- time_t timestamp;
- } users;
- configs* c;
- users* user;
- int n_users;
- void add(char* type, char* name, char* value) {
- configs* d=c;
- configs* e=NULL;
- while (d!=NULL) {
- if(d->nom==NULL || type==NULL)
- return;
- if(strcmp(d->nom,type)==0)
- break;
- e=d;
- d=d->next;
- }
- if(d==NULL) {
- if(e!=NULL) {
- e->next=(configs*)malloc(sizeof(configs)); // Ligne 131
- if(e->next==NULL)
- syslog(LOG_NOTICE,"Erreur d'allocation (121)" );
- d=e->next;
- }
- else {
- c=(configs*)malloc(sizeof(configs)); // Ligne 137
- if(c==NULL)
- syslog(LOG_NOTICE,"Erreur d'allocation (127)" );
- d=c;
- }
- d->nom=(char*)malloc((strlen(type)+1)*sizeof(char));
- if(d->nom==NULL)
- syslog(LOG_NOTICE,"Erreur d'allocation (132)" );
- strcpy(d->nom,type);
- d->n=0;
- d->params=NULL;
- }
- d->n+=1;
- d->params=(char**)realloc(d->params,d->n*sizeof(char*)); // Ligne 151
- if(d->params==NULL)
- syslog(LOG_NOTICE,"Erreur d'allocation (141)" );
- d->params[d->n-1]=(char*)malloc((strlen(name)+strlen(value)+3)*sizeof(char));
- if(d->params[d->n-1]==NULL)
- syslog(LOG_NOTICE,"Erreur d'allocation (144)" );
- d->next=NULL;
- sprintf(d->params[d->n-1],"%s=%s\n",name,value);
- }
- void freeconfigs() {
- int i;
- configs *n,*d=c;
- while(d!=NULL) {
- n=d->next;
- free(d->nom);
- for(i=0;i<d->n;i++) {
- free(d->params[i]);
- }
- if(d->params!=NULL) {
- free(d->params);
- }
- free(d);
- d=n;
- }
- c=NULL;
- }
- void reset_configs() {
- MYSQL m;
- int i, err;
- MYSQL_RES *r1;
- MYSQL_ROW row;
- mysql_init(&m);
- mysql_options(&m,MYSQL_READ_DEFAULT_GROUP,"phpwrapperd" );
- for(i=0;i<getValueI("MYSQL_RETRY" );i++) {
- if(!mysql_real_connect(&m,
- getValueS("MYSQL_HOST" ),
- getValueS("MYSQL_LOGIN" ),
- getValueS("MYSQL_PASSWORD" ),
- getValueS("MYSQL_DB" ),
- 0,
- getValueS("MYSQL_SOCK" ),
- 0)) {
- syslog(LOG_NOTICE, "Impossible de se connecter au server mysql : %s\n",mysql_error(&m));
- if(i==getValueI("MYSQL_RETRY" )-1) {
- syslog(LOG_NOTICE,"!!! Abandon de connexion au serveur MySQL !!!" );
- return;
- }
- }
- else
- i=getValueI("MYSQL_RETRY" );
- }
-
- mysql_query(&m,"select * from php_config" );
- r1=mysql_store_result(&m);
- if(r1==NULL) {
- syslog(LOG_NOTICE,"`select * from php_config' : %s\n",mysql_error(&m));
- mysql_close(&m);
- return;
- }
- freeconfigs();
- while ((row = mysql_fetch_row(r1))) {
- mysql_commit(&m);
- add(row[0],row[1],row[2]); // Ligne 203
- }
- mysql_free_result(r1);
- mysql_close(&m);
- }
- void get_user(char* name, char** base_dir, char** type) {
- MYSQL m;
- int i, err;
- char* query;
- MYSQL_RES *r1;
- MYSQL_ROW row;
- users* u;
- users* tmp;
- int exists=1;
- u=user;
- if(user==NULL)
- exists=0;
- else {
- if(user->nom==NULL || name==NULL)
- return;
- while(strcmp(u->nom,name)) {
- u=u->next;
- if(u==user) {
- exists=0;
- break;
- }
- }
- }
- if(!exists || u->timestamp<(time(NULL)-getValueI("REFRESH_CACHE_USERS_DELAY" ))) {
- query=(char*)malloc((49+strlen(name))*sizeof(char));
- if(query==NULL)
- syslog(LOG_NOTICE,"Erreur d'allocation (272)" );
- sprintf(query,"select type,homedir from users where username='%s'",name);
-
- mysql_init(&m);
- mysql_options(&m,MYSQL_READ_DEFAULT_GROUP,"phpwrapperd" );
-
- for(i=0;i<getValueI("MYSQL_RETRY" );i++) {
- if(!mysql_real_connect(&m,
- getValueS("MYSQL_HOST" ),
- getValueS("MYSQL_LOGIN" ),
- getValueS("MYSQL_PASSWORD" ),
- getValueS("MYSQL_DB" ),
- 0,
- getValueS("MYSQL_SOCK" ),
- 0)) {
- syslog(LOG_NOTICE,"Impossible de se connecter au server mysql : %s\n",mysql_error(&m));
- if(i==getValueI("MYSQL_RETRY" )-1) {
- syslog(LOG_NOTICE,"!!! Abandon de connexion au serveur MySQL !!!" );
- free(query);
- return;
- }
- }
- else
- break;
- }
-
- mysql_query(&m,query);
- r1=mysql_store_result(&m);
- if(mysql_num_rows(r1)==0 || r1==NULL){
- if(r1==NULL)
- syslog(LOG_NOTICE,"`%s' : %s\n",query, mysql_error(&m));
- *base_dir=NULL;
- *type=NULL;
- mysql_free_result(r1);
- mysql_close(&m);
- free(query);
- return;
- }
- if(!exists)
- syslog(LOG_NOTICE,"Adding user `%s' in cache", name);
- else
- syslog(LOG_NOTICE,"Updating user `%s' in cache", name);
-
- if(n_users>=getValueI("MAX_USERS_CACHE" ))
- free_last_user();
-
- u=(users*)malloc(sizeof(users));
- if(u==NULL)
- syslog(LOG_NOTICE,"Erreur d'allocation (302)" );
- if(user==NULL) {
- u->last=u;
- u->next=u;
- n_users=1;
- }
- else {
- tmp=user->last;
- u->last=tmp;
- u->next=user;
- user->last=u;
- u->last->next=u;
- n_users++;
- }
- u->nom=NULL;
- u->type=NULL;
- u->open_basedir=NULL;
- user=u;
- if(u->nom!=NULL) free(u->nom);
- u->nom=(char*)malloc((strlen(name)+1)*sizeof(char)); // Ligne 338
- if(u->nom==NULL)
- syslog(LOG_NOTICE,"Erreur d'allocation (344)" );
- strcpy(u->nom,name);
-
- row = mysql_fetch_row(r1);
- mysql_commit(&m);
- if(u->type!=NULL) free(u->type);
- u->type=(char*)malloc((strlen(row[0])+1)*sizeof(char)); // Ligne 346
- if(u->type==NULL)
- syslog(LOG_NOTICE,"Erreur d'allocation (352)" );
- strcpy(u->type,row[0]);
- if(u->open_basedir!=NULL) free(u->open_basedir);
- u->open_basedir=(char*)malloc((strlen(row[1])+1)*sizeof(char));
- if(u->open_basedir==NULL)
- syslog(LOG_NOTICE,"Erreur d'allocation (357)" );
- strcpy(u->open_basedir,row[1]);
- mysql_free_result(r1);
- mysql_close(&m);
- free(query);
-
- u->timestamp=time(NULL);
- exists=1;
- }
- else {
- *base_dir=u->open_basedir;
- *type=u->type;
- }
- }
- void send_phpconfig() {
- configs* d=c;
- char line[MAXLINE];
- char *openbase_dir=NULL;
- char *type=NULL;
- int i;
- readline(newsockfd,line,MAXLINE);
- get_user(line,&openbase_dir,&type); // Ligne 379
- if (openbase_dir==NULL || type==NULL) {
- syslog(LOG_NOTICE,"unknown user `%s'",line);
- return;
- }
- d=c;
- if(d!=NULL) {
- if(d->nom==NULL || type==NULL)
- return;
- while(strcmp(d->nom,type))
- d=d->next;
- for(i=0;i<d->n;i++){
- writen(newsockfd,d->params[i],strlen(d->params[i]));
- }
- }
- sprintf(line,"open_basedir=%s\n",openbase_dir);
- writen(newsockfd,line,strlen(line)+1);
- writen(newsockfd,"\n",1);
- }
|
EDIT : ajout des n° de ligne utiles Message édité par Profil supprimé le 22-04-2005 à 09:51:27
|