/* l'ancienne commande... */ int reconnect_after_timeout(int refait_commande) { int code, ret; char *chaine_to_sauve, *ptr; aff_try_reconnect(); close(tcp_fd); ptr=strchr(line_write,'\n'); if (ptr) *(++ptr)='\0'; chaine_to_sauve=safe_strdup(line_write); code=connect_server(Options.serveur_name,0); if ((code!=200) && (code!=201)) { free(chaine_to_sauve); return -1; } adjust_time(); /* il faut peut-être mieux le refaire, si c'est possible */ /* reste a envoyer la bonne commande pour GROUP */ if (refait_commande) { ret=(Newsgroup_courant ? va_dans_groupe() : 1); if (ret==-1) { free(chaine_to_sauve); return -1; } if (ret==0) { code=return_code(); if (code<0) { free(chaine_to_sauve); return -1; } } if (debug) fprintf(stderr, "Reste a renvoyer la commande bugguante\n"); raw_write_server(chaine_to_sauve, strlen(chaine_to_sauve)); /* on renvoie la commande... */ } if (debug) fprintf(stderr, "Reconnexion réussie ...\n"); free(chaine_to_sauve); aff_end_reconnect(); return 0; }
/* * Return my process info */ ProcessInfo *pool_get_my_process_info(void) { if (!process_context) ereport(FATAL, (return_code(1), errmsg("process context is not initialized"))); return &process_context->process_info[process_context->proc_id]; }
/* * if the file has setuid bit and the owner is root, it returns 1, otherwise returns 0 */ static int has_setuid_bit(char * path) { struct stat buf; if (stat(path,&buf) < 0) { ereport(FATAL, (return_code(1), errmsg("has_setuid_bit: command '%s' not found", path))); } return ((buf.st_uid == 0) && (S_ISREG(buf.st_mode)) && (buf.st_mode & S_ISUID))?1:0; }
/* * Initialize per process context */ void pool_init_process_context(void) { process_context = &process_context_d; if (!process_info) ereport(FATAL, (return_code(1), errmsg("process info is not set"))); process_context->process_info = process_info; if (!pool_config->backend_desc) ereport(FATAL, (return_code(1), errmsg("backend desc is not set"))); process_context->backend_desc = pool_config->backend_desc; process_context->proc_id = my_proc_id; process_context->local_session_id = 0; /* initialize local session counter */ }
/* On utilise read_server_with_reconnect */ int return_code () { int lus, code; char *buf; lus=(init_connection ? read_server(tcp_line_read,3,MAX_READ_SIZE-1) : read_server_with_reconnect(tcp_line_read, 3, MAX_READ_SIZE-1)); if (lus<3) return -1; code=(int)strtol(tcp_line_read,&buf,10); /* Ici, on gere le cas d'une ligne trop longue */ while (tcp_line_read[lus-1]!='\n') { if (debug) fprintf(stderr, "ligne tres longue ???\n"); lus=read_server(tcp_line_read, 1, MAX_READ_SIZE-1); if (lus<1) { if (debug) fprintf(stderr, "Echec en lecture du serveur\n"); return -1; } if (debug) fprintf(stderr, "%s", tcp_line_read); } if (group_instead_of_list) { group_instead_of_list=0; if (code<400) { long min, max; /* Attention, on a change de groupe, il faut revenir au groupe normal... */ strtol(buf,&buf,10); min=strtol(buf,&buf,10); max=strtol(buf,&buf,10); if (Newsgroup_courant) { va_dans_groupe(); return_code(); /* ICI et pas ailleurs, sinon on casse tcp_line_read */ } snprintf(tcp_line_read,2047,"%s %ld %ld y\r\n",filter_cmd_list,max,min); renvoie_courte_liste=2; } else renvoie_courte_liste=1; return 215; } return code; }
static int ttd_rpc(ttd_conn connection, enum ttd_operations opcode, ttd_target target, ttd_request_t request, ttd_reply_t reply, boolean_t take_interrupts) { ttd_operation op; int i, n, result; int readfds; int seq; struct timeval timeout; op = (ttd_operation) opcode; seq = (op < (ttd_operation) DISCONNECT_FROM_TARGET) ? 0 : ++(connection->seq); n = sizeof(*request); /* * Convert to network byte order. */ request->server = htonl(connection->server); request->seq = htonl(seq); request->operation = htonl(op); request->target = htonl(target); timeout.tv_sec = 10; timeout.tv_usec = ttd_retry_timeout; /* * Throw away any previous messages. */ if (use_clean_out_code) { clean_out_socket(connection); } for (i = 0; i < ttd_retry_count; i++) { result = send(connection->socket, (char *) request, n, 0); if (result < 0) { printf("ttd_rpc: error on send\n"); return TTD_UnixErrorRC; } if (result != n) { (void) fprintf(stderr, "?ttd: partial send\n"); return TTD_UnixErrorRC; } readfds = 1 << connection->socket; result = select(connection->socket+1, &readfds, (int *) NULL, (int *) NULL, &timeout); if (result < 0) { if (errno != EINTR) { printf("ttd_rpc: error on select\n"); return TTD_UnixErrorRC; } else if (take_interrupts) { printf("ttd_rpc: operation interrupted\n"); return TTD_TargetTimedOutRC; } } if (result > 0) { result = recv(connection->socket, (char *) reply, sizeof( *reply ), 0); if (result < 0) { if (errno != EINTR) { printf("ttd_rpc: recv, eintr\n"); return TTD_UnixErrorRC; } else if (take_interrupts) { printf("ttd_rpc: operation interrupted\n"); return TTD_TargetTimedOutRC; } } /* * Convert back to host byte order. */ reply->seq = ntohl(reply->seq); reply->target = ntohl(reply->target); reply->operation = ntohl(reply->operation); if ((reply->server == request->server) && (reply->operation == op) && ((op < (ttd_operation) DISCONNECT_FROM_TARGET) || ((reply->seq == seq) && (reply->target == target)))) { reply->server = ntohl(reply->server); return return_code( reply->result.code ); } } if (result == 0) { printf("TTD timeout\n"); } } return TTD_NoReplyRC; }
int abmfP_write_action_function( GenCodeInfo genCodeInfo, ABObj action ) { int rc = 0; /* return code */ BOOL isTTCB = FALSE; BOOL ss_cb = FALSE; File codeFile = genCodeInfo->code_file; BOOL topUserSegWritten = FALSE; BOOL bottomUserSegWritten = FALSE; BOOL funcBodyWritten = FALSE; BOOL funcEndWritten = FALSE; BOOL actionPrintfWritten = FALSE; int return_value = 0; ABObj fromObj = obj_get_from(action); ABObj actualFromObj = NULL; ABObj toObj = obj_get_to(action); ABObj module = NULL; char actionName[1024]; char actionPrintf[1024]; abmfP_gencode_enter_func(genCodeInfo); abmfP_ip_obj(genCodeInfo) = obj_get_to(action); util_strncpy(actionName, abmfP_get_action_name(action), 1024); sprintf(actionPrintf, "printf(\"action: %s()\\n\");\n", actionName); /*** *** START OF FUNCTION ***/ switch (obj_get_when(action)) { case AB_WHEN_AFTER_CREATED: /* * post-create procs have the signature of an Xt Callback, * although they are called as conventional functions. */ fromObj = obj_get_from(action); actualFromObj = get_actual_from_obj(action); abmfP_write_xm_callback_begin(genCodeInfo, FALSE, actionName); write_instance_ptr_var(genCodeInfo, actualFromObj, get_from_var_name(), "callData", TRUE, NULL); abio_puts(genCodeInfo->code_file, nlstr); break; case AB_WHEN_DRAGGED_FROM: { abio_printf(genCodeInfo->code_file, abmfP_lib_default_dragCB->def, /* this is a format string */ actionName,actionName,actionName, actionName,actionName, actionName); abio_puts(genCodeInfo->code_file, "\n\n"); /* these are all in the "library" definition */ topUserSegWritten = TRUE; bottomUserSegWritten = TRUE; funcBodyWritten = TRUE; funcEndWritten = TRUE; actionPrintfWritten = TRUE; } break; case AB_WHEN_DROPPED_ON: { abio_printf(genCodeInfo->code_file, abmfP_lib_default_dropCB->def, /* this is a format string */ actionName,actionName,actionName,actionName); abio_puts(genCodeInfo->code_file, "\n\n"); /* these are all in the "library" definition */ topUserSegWritten = TRUE; bottomUserSegWritten = TRUE; funcBodyWritten = TRUE; funcEndWritten = TRUE; actionPrintfWritten = TRUE; } break; case AB_WHEN_TOOLTALK_QUIT: case AB_WHEN_TOOLTALK_DO_COMMAND: case AB_WHEN_TOOLTALK_GET_STATUS: case AB_WHEN_TOOLTALK_PAUSE_RESUME: isTTCB = TRUE; abio_printf(codeFile, begin_tt_callback_body, actionName); abmfP_write_c_block_begin(genCodeInfo); write_tooltalk_cb_vars(genCodeInfo, action); break; case AB_WHEN_SESSION_RESTORE: ss_cb = TRUE; abio_printf(codeFile, begin_ss_restore_callback_body, abmfP_get_action_name(action)); abmfP_write_c_block_begin(genCodeInfo); write_ss_cb_vars(genCodeInfo, action); break; case AB_WHEN_SESSION_SAVE: ss_cb = TRUE; abio_printf(codeFile, begin_ss_save_callback_body, abmfP_get_action_name(action)); abmfP_write_c_block_begin(genCodeInfo); write_ss_cb_vars(genCodeInfo, action); break; default: abmfP_write_xm_callback_begin(genCodeInfo, FALSE, actionName); break; } /* switch obj_get_when() */ /***** ***** TOP USER SEGMENT *****/ if (!topUserSegWritten) { STRING contents = (actionPrintfWritten? NULL:(isTTCB? actionPrintf:NULL)); abmfP_write_user_var_and_code_seg(genCodeInfo, contents); abio_puts(codeFile, nlstr); topUserSegWritten = TRUE; if (contents != NULL) { actionPrintfWritten = TRUE; } } /*** *** FUNCTION BODY ***/ if (isTTCB) { write_tooltalk_cb_body1(genCodeInfo, action); abmfP_write_user_code_seg(genCodeInfo, NULL); write_tooltalk_cb_body2(genCodeInfo, action); funcBodyWritten = TRUE; bottomUserSegWritten = TRUE; } else if (ss_cb) { write_ss_cb_body1(genCodeInfo, action); abmfP_write_user_code_seg(genCodeInfo, NULL); write_ss_cb_body2(genCodeInfo, action); funcBodyWritten = TRUE; bottomUserSegWritten = TRUE; } else if (!funcBodyWritten) switch (obj_get_func_type(action)) { case AB_FUNC_BUILTIN: rc = abmfP_write_builtin_action(genCodeInfo, action, TRUE); return_if_err(rc,rc); funcBodyWritten = TRUE; break; case AB_FUNC_USER_DEF: abmfP_write_user_start_comment(genCodeInfo, "vvv Add C code below vvv"); abmfP_write_user_end_comment(genCodeInfo, "^^^ Add C code above ^^^"); bottomUserSegWritten = TRUE; funcBodyWritten = TRUE; break; case AB_FUNC_CODE_FRAG: abio_puts(codeFile, obj_get_func_code(action)); funcBodyWritten = TRUE; break; case AB_FUNC_ON_ITEM_HELP: abio_printf(codeFile, "dtb_do_onitem_help();\n"); funcBodyWritten = TRUE; break; case AB_FUNC_HELP_VOLUME: abio_printf(codeFile, "dtb_show_help_volume_info(\"%s\", \"%s\");\n", istr_string(action->info.action.volume_id), istr_string(action->info.action.location)); funcBodyWritten = TRUE; break; default: { char *obj_name_string = obj_get_name(fromObj); util_printf_err(catgets(Dtb_project_catd, 1, 78, "unknown function type for action from object, %s"), obj_name_string); return_code(ERR); } break; } /***** ***** BOTTOM USER SEGMENT *****/ if (!bottomUserSegWritten) { STRING contents = (actionPrintfWritten? NULL:actionPrintf); abmfP_write_user_code_seg(genCodeInfo, contents); bottomUserSegWritten = TRUE; if (contents != NULL) { actionPrintfWritten = TRUE; } } /***** ***** FUNCTION END *****/ if (!funcEndWritten) { abmfP_write_c_func_end(genCodeInfo, NULL); funcEndWritten = TRUE; } epilogue: abmfP_gencode_exit_func(genCodeInfo); return return_value; }
/* list minimal... */ int write_command (int num_com, int num_param, char **param) { int ret,code; char **param2=param; char *buf; if (num_com==CMD_LIST) filter_cmd_list[0]='\0'; renvoie_direct=0; if ((server_command_status[num_com] & CMD_FLAG_MAXIMAL)==CMD_FLAG_MAXIMAL) return raw_write_command(num_com, num_param, param2); switch (num_com) { /* NEWGROUPS : on se fiche totalement que ça marche ou non */ /* NEWNEWS : appelé par cherche_newnews, le retour -1 n'est pas grave */ /* GROUP : on ne peut pas le rejeter, on le suppose donc maximal */ case CMD_NEWGROUPS : case CMD_NEWNEWS : case CMD_GROUP : server_command_status[num_com]=CMD_FLAG_MAXIMAL; return raw_write_command(num_com, num_param, param2); /* STAT : pfiouuuu... pour l'instant, je laisse tomber */ /* HEAD : idem */ /* BODY : idem */ /* ARTICLE : idem */ case CMD_STAT : case CMD_HEAD : case CMD_BODY : case CMD_ARTICLE : server_command_status[num_com]=CMD_FLAG_MAXIMAL; return raw_write_command(num_com, num_param, param2); /* XHDR : bon, ça louze, mais si on est là, XOVER n'existe pas */ /* XOVER : on n'installe pas le test tout de suite... */ case CMD_XHDR : case CMD_XOVER : server_command_status[num_com]=CMD_FLAG_MAXIMAL; return raw_write_command(num_com, num_param, param2); /* POST : théoriquement déjà testé */ case CMD_POST : return raw_write_command(num_com, num_param, param2); /* LIST : ah ! enfin le truc important !!! */ /* On suppose le nombre de paramètre à 0 ou 1 (2 => active) */ case CMD_LIST : if ((num_param==0) && ((server_command_status[num_com] & CMD_FLAG_KNOWN) ==CMD_FLAG_KNOWN)) return raw_write_command(num_com, num_param, param2); /* On se fout de overview.fmt */ if ((num_param>0) && (strcmp(*param2,"overview.fmt")==0)) return raw_write_command(num_com, num_param, param2); if ((server_command_status[num_com] & CMD_FLAG_KNOWN) ==CMD_FLAG_KNOWN) { if (num_param==2) { if (strncmp(*param2,"active",6)==0) param2++; else return -2; /* erreur */ } if (strncmp(*param2,"active ",7)==0) buf=*param2+7; else buf=*param2; /* Ne pas changer *param2 */ strncpy(filter_cmd_list,buf,MAX_NEWSGROUP_LEN-1); /* On va bien cradifier... */ if (strchr(buf,'*')) return raw_write_command(num_com,0,NULL); group_instead_of_list=1; return raw_write_command(CMD_GROUP,1,&buf); } if ((server_command_status[num_com] & CMD_FLAG_TESTED) ==CMD_FLAG_TESTED) return -1; /* impossible pour l'instant */ ret=raw_write_command(num_com, num_param, param2); if (ret<0) return -1; code=return_code(); if (code>400) { server_command_status[CMD_LIST]=CMD_FLAG_KNOWN; return write_command(CMD_LIST, num_param, param); } if (num_param>0) server_command_status[CMD_LIST]=CMD_FLAG_MAXIMAL; renvoie_direct=1; return ret; /* CMD_DATE : un détail dans un sens */ case CMD_DATE : if ((server_command_status[num_com] & CMD_FLAG_KNOWN) ==CMD_FLAG_KNOWN) return raw_write_command(CMD_DATE, 0, NULL); ret=raw_write_command(CMD_DATE, 0, NULL); if (ret<0) return -1; code=return_code(); if (code>500) return -1; renvoie_direct=1; return ret; /* Par défaut, hum... Ben... on retourne */ default : return raw_write_command(num_com, num_param, param); } }
/* fonction coupe la connexion. */ int connect_server (flrn_char *host, int port) { int ret, code; int rc,rc2; char *trad; const char *special; flrn_char *tmptrad; init_connection=1; if (host==NULL) { special=_("Pas de serveur où se connecter.\n"); rc=conversion_from_utf8(special, &tmptrad, 0, (size_t)(-1)); rc2=conversion_to_terminal(tmptrad,&trad,0,(size_t)(-1)); fputs(trad,stderr); if (rc2==0) free(trad); if (rc==0) free(tmptrad); return -1; } if (port==0) port=Options.port; rc=conversion_to_utf8(host,&trad,0,(size_t)(-1)); ret=contact_server(host, port); if (rc==0) free(trad); if (ret<0) { special=_("Échec de la connexion au serveur : %s\n"); rc=conversion_from_utf8(special, &tmptrad, 0, (size_t)(-1)); rc2=conversion_to_terminal(tmptrad,&trad,0,(size_t)(-1)); fprintf(stderr,trad,host); if (rc2==0) free(trad); if (rc==0) free(tmptrad); return -1; } code=return_code(); init_connection=0; if ((code!=200) && (code!=201)) { close (tcp_fd); return code; } server_command_status[CMD_QUIT]=CMD_FLAG_MAXIMAL; server_command_status[CMD_MODE_READER]=CMD_FLAG_MAXIMAL; server_command_status[CMD_AUTHINFO]=CMD_FLAG_MAXIMAL; server_command_status[CMD_POST]=(code==200 ? CMD_FLAG_MAXIMAL : CMD_FLAG_TESTED); write_command(CMD_MODE_READER, 0, NULL); ret=return_code(); /* On place juste XMODE READER au cas ou...*/ /* Non nécéssaire (trn4 ne le fait pas) */ /* if (ret>400) { raw_write_server("XMODE READER\r\n", 14); ret=return_code(); } */ /* Authentification */ if ((ret<500) && (Options.auth_cmd)) { return run_auth_cmd(); } if ((ret<500) && (Options.auth_user)) { char *strvar[2]; strvar[0]="user"; rc=conversion_to_utf8(Options.auth_user,&trad,0,(size_t)(-1)); strvar[1]=trad; write_command(CMD_AUTHINFO,2,strvar); if (rc==0) free(trad); ret=return_code(); if ((ret>300) && (ret<400)) { strvar[0]="pass"; if (Options.auth_pass) { rc=conversion_to_utf8(Options.auth_pass,&trad,0,(size_t)(-1)); strvar[1]=trad; } else { char *strpipo; /* on peut supposer que ça n'arrive que la première fois */ special=_("Le serveur demande un mot de passe.\n"); rc=conversion_from_utf8(special, &tmptrad, 0, (size_t)(-1)); rc2=conversion_to_terminal(tmptrad,&trad,0,(size_t)(-1)); fputs(trad,stderr); if (rc2==0) free(trad); if (rc==0) free(tmptrad); special=_("Mot de passe : "); rc=conversion_from_utf8(special, &tmptrad, 0, (size_t)(-1)); rc2=conversion_to_terminal(tmptrad,&trad,0,(size_t)(-1)); strpipo=getpass(trad); if (rc2==0) free(trad); if (rc==0) free(tmptrad); if (strpipo!=NULL) { rc=conversion_from_terminal(strpipo,&(Options.auth_pass), 0,(size_t)(-1)); if (rc!=0) Options.auth_pass=safe_flstrdup(Options.auth_pass); rc=conversion_to_utf8(Options.auth_pass,&trad,0,(size_t)(-1)); strvar[1]=trad; } else { strvar[1]=""; rc=1; } } if (Options.auth_pass) { write_command(CMD_AUTHINFO,2,strvar); ret=return_code(); if (rc==0) free(trad); } else ret=502; } if (ret==502) code=ret; } return code; }