/** * @brief replace a dns by a new * @param old_dns the old dns * @param new_dns the new dns * @return Return 1 if the dns is replace, else 0 */ int exalt_dns_replace(const char* old_dns, const char* new_dns) { char buf[1024], buf2[1024], buf3[1024];; FILE* fw, *fr; EXALT_ASSERT_RETURN(old_dns!=NULL); EXALT_ASSERT_RETURN(new_dns!=NULL); EXALT_ASSERT_RETURN(exalt_is_address(new_dns)); ecore_file_cp(EXALT_RESOLVCONF_FILE, EXALT_TEMP_FILE); fr = fopen(EXALT_TEMP_FILE, "ro"); EXALT_ASSERT_RETURN(fr!=NULL); fw = fopen(EXALT_RESOLVCONF_FILE, "w"); EXALT_ASSERT_ADV(fw!=NULL,EXALT_FCLOSE(fr);return 0,"f!=NULL failed"); sprintf(buf,"nameserver %s\n",old_dns); sprintf(buf3,"nameserver %s\n",new_dns); while(fgets(buf2,1024,fr)) if( strcmp(buf,buf2) != 0) fwrite( buf2, sizeof(char), strlen(buf2), fw); else fwrite( buf3, sizeof(char), strlen(buf3), fw); EXALT_FCLOSE(fr); EXALT_FCLOSE(fw); remove(EXALT_TEMP_FILE); return 1; }
Etk_Bool bootpanel_ethlist_checkbox_change_cb(Etk_Object *object, Etk_Tree_Row *row, void *data) { Etk_Tree_Col* col; char* interface; Etk_Bool checked; boot_panel *pnl; pnl = (boot_panel*) data; col = ETK_TREE_COL(object); EXALT_ASSERT_RETURN(col!=NULL); EXALT_ASSERT_RETURN(row!=NULL); EXALT_ASSERT_RETURN(pnl!=NULL); etk_tree_row_fields_get(row, col, NULL, &interface, NULL); etk_tree_row_fields_get(row, col, &checked, NULL, NULL); //we change the state of the checkbox because it will be update when the daemon will update the configuration (see main_window.c::mainwindow_notify_cb()) bootpanel_update_interface(interface, pnl); if(checked) exalt_dbus_bootprocess_iface_add(exalt_conn,interface); else exalt_dbus_bootprocess_iface_remove(exalt_conn,interface); return ETK_TRUE; }
/* * @brief add an interface in the configuration file * @param interface the interface name * @param file the configuration file * @return Returns 1 if success */ int waiting_iface_add(const char* interface,const char* file) { Exalt_Ethernet* eth; Boot_Process_List *l; EXALT_ASSERT_RETURN(interface!=NULL); EXALT_ASSERT_RETURN(file!=NULL); l= waiting_iface_load(file); //add the new interface Boot_Process_Elt *elt = malloc(sizeof(Boot_Process_Elt)); EXALT_STRDUP(elt->interface,interface); l->l = evas_list_append(l->l, elt); //save the new list waiting_iface_save(l,file); waiting_iface_free(&l); //we send a broadcast on dbus eth = exalt_eth_get_ethernet_byname(interface); if(eth) eth_cb(eth,EXALTD_ETH_CB_WAITINGBOOT_CHANGE,exaltd_conn); return 1; }
/* * @brief test if an interface is in the configuration file * @param interface the interface name * @param file the configuration file * @return Returns 1 if the interface is in, else 0 */ int waiting_iface_is_inconf(const char* interface,const char* file) { Exalt_Ethernet* eth; int is; Boot_Process_List *l; EXALT_ASSERT_RETURN(file!=NULL); EXALT_ASSERT_RETURN(interface!=NULL); l = waiting_iface_load(file); eth = exalt_eth_get_ethernet_byname(interface); is = waiting_iface_is(l,eth); waiting_iface_free(&l); return is; }
/** * @brief add a dns * @param dns the news dns * @return Return 1 if the dns is add, else -0 */ int exalt_dns_add(const char* dns) { char buf[1024]; FILE* f; EXALT_ASSERT_RETURN(dns!=NULL); EXALT_ASSERT_RETURN(exalt_is_address(dns)); f = fopen(EXALT_RESOLVCONF_FILE, "a"); EXALT_ASSERT_RETURN(f!=NULL); sprintf(buf,"nameserver %s\n", dns); fwrite( buf, sizeof(char), strlen(buf), f); EXALT_FCLOSE(f); return 1; }
/** * @brief get the dns list * @return Return the dns list */ Ecore_List* exalt_dns_get_list() { FILE* f; char buf[1024]; char *addr; Ecore_List* l; f = fopen(EXALT_RESOLVCONF_FILE, "ro"); EXALT_ASSERT_RETURN(f!=NULL); l = ecore_list_new(); l->free_func = free; while(fgets(buf,1024,f)) { buf[strlen(buf)-1] = '\0'; //jump nameserver if(strlen(buf) > 13) { addr = buf + 11; if(exalt_is_address(addr)) ecore_list_append(l, strdup(addr)); } } EXALT_FCLOSE(f); return l; }
/* * @brief set the timeout * @param timeout the timeout value * @param file the configuration file * @return Returns 1 if success */ int waiting_timeout_set(int timeout, const char* file) { Exalt_Ethernet* eth; Boot_Process_List *l; EXALT_ASSERT_RETURN(file!=NULL); l= waiting_iface_load(file); l->timeout = timeout; //save the new list waiting_iface_save(l,file); waiting_iface_free(&l); /*we can't send a broadcast without specify a interface * that's why we create a special ethernet struct without name :) */ eth = exalt_eth_new("No interface is specify with the signal EXALTD_ETH_CB_WAITINGBOOT_CHANGE"); if(eth) eth_cb(eth,EXALTD_ETH_CB_WAITINGBOOT_TIMEOUT_CHANGE,exaltd_conn); exalt_eth_free(eth); return 1; }
/** * @brief Load the driver of an <ireless interface from the configuration file * @param file the configuration file * @param udi the hal udi of the interface * @return Returns the state */ char* exalt_eth_driver_load(const char* file, const char* udi) { Exalt_Eth_Save *s = _exalt_eet_eth_load(file, udi); EXALT_ASSERT_RETURN(s!=NULL); char* driver = s->driver; exalt_conn_free(s->connection); EXALT_FREE(s); return driver; }
/** * @brief Load the configuration of an interface from the configuration file * @param file the configuration file * @param udi the hal udi of the interface * @return Returns the state */ Exalt_Connection* exalt_eth_conn_load(const char* file, const char* udi) { Exalt_Eth_Save *s = _exalt_eet_eth_load(file, udi); EXALT_ASSERT_RETURN(s!=NULL); Exalt_Connection *c = s->connection; EXALT_FREE(s->driver); EXALT_FREE(s); return c; }
/** * @brief Load the state (up/down) of an interface from the configuration file * @param file the configuration file * @param udi the hal udi of the interface * @return Returns the state */ Exalt_Enum_State exalt_eth_state_load(const char* file, const char* udi) { Exalt_Eth_Save *s = _exalt_eet_eth_load(file, udi); EXALT_ASSERT_RETURN(s!=NULL); Exalt_Enum_State st = s->state; EXALT_FREE(s->driver); exalt_conn_free(s->connection); EXALT_FREE(s); return st; }
Etk_Tree_Row * bootpanel_findrow(char* interface, boot_panel* pnl) { Etk_Tree_Row* row; char* row_name; EXALT_ASSERT_RETURN(interface!=NULL); EXALT_ASSERT_RETURN(pnl!=NULL); row = etk_tree_first_row_get(ETK_TREE(pnl->eth_list)); while(row) { etk_tree_row_fields_get(row, pnl->eth_col0, NULL, &row_name, NULL); if(strcmp(row_name,interface)==0) return row; row = etk_tree_row_next_get(row); } return NULL; }
/* * @brief return true is the interface eth is in the list * @param l the list of interface * @param eth the interface * @return Returns 1 if yes, else 0 */ int waiting_iface_is(const Boot_Process_List* l,const Exalt_Ethernet* eth) { int find = 0; Evas_List *elt; Boot_Process_Elt *data; EXALT_ASSERT_RETURN(l!=NULL); EXALT_ASSERT_RETURN(eth!=NULL); elt = l->l; while(!find && elt) { data = evas_list_data(elt); if(data->interface && strcmp(exalt_eth_get_name(eth),data->interface) == 0) find = 1; else elt = evas_list_next(elt); } return find; }
Exalt_Configuration* exalt_conf_new() { Exalt_Configuration* c; c = calloc(1,sizeof(Exalt_Configuration)); EXALT_ASSERT_RETURN(c!=NULL); c->mode = EXALT_DHCP; c->cmd_after_apply = NULL; return c; }
/** * @brief delete a dns * @param dns the dns * @return Return 1 if the dns is delete, else 0 */ int exalt_dns_delete(const char* dns) { char buf[1024], buf2[1024]; FILE* fw, *fr; EXALT_ASSERT_RETURN(dns!=NULL); ecore_file_cp(EXALT_RESOLVCONF_FILE, EXALT_TEMP_FILE); fr = fopen(EXALT_TEMP_FILE, "ro"); EXALT_ASSERT_RETURN(fr!=NULL); fw = fopen(EXALT_RESOLVCONF_FILE, "w"); EXALT_ASSERT_ADV(fw!=NULL,EXALT_FCLOSE(fr);return 0,"f!=NULL failed"); sprintf(buf,"nameserver %s\n",dns); while(fgets(buf2,1024,fr)) if( strcmp(buf,buf2) != 0) fwrite( buf2, sizeof(char), strlen(buf2), fw); EXALT_FCLOSE(fr); EXALT_FCLOSE(fw); remove(EXALT_TEMP_FILE); return 1; }
/* * @brief get the timeout * @param timeout the timeout value * @param file the configuration file * @return Returns the timeout if success */ int waiting_timeout_get(const char* file) { int timeout; Boot_Process_List *l; EXALT_ASSERT_RETURN(file!=NULL); l = waiting_iface_load(file); timeout = l->timeout; waiting_iface_free(&l); return timeout; }
/* * @brief remove an interface in the configuration file * @param interface the interface name * @param file the configuration file * @return Returns 1 if success */ int waiting_iface_remove(const char* interface,const char* file) { Exalt_Ethernet* eth; Boot_Process_List *l = waiting_iface_load(file); EXALT_ASSERT_RETURN(file!=NULL); EXALT_ASSERT_RETURN(interface!=NULL); l = waiting_iface_load(file); eth = exalt_eth_get_ethernet_byname(interface); waiting_iface_done(l,eth); //save the new list waiting_iface_save(l,file); waiting_iface_free(&l); //we send a broadcast on dbus if(eth) eth_cb(eth,EXALTD_ETH_CB_WAITINGBOOT_CHANGE,exaltd_conn); return 1; }
/** * @brief save the configuration of a card * @param file the configuration file * @param eth the card * @return Return 1 if success, else 0 */ int exalt_eth_save(const char* file, Exalt_Ethernet* eth) { Exalt_Eth_Save s; EXALT_ASSERT_RETURN(eth!=NULL); s.state = exalt_eth_is_up(eth); s.connection = exalt_eth_get_connection(eth); if(exalt_eth_is_wireless(eth)) s.driver = exalt_wireless_get_wpasupplicant_driver(exalt_eth_get_wireless(eth)); else s.driver = "wext"; return _exalt_eet_eth_save(file, &s, exalt_eth_get_udi(eth)); }
/** * @brief Load the information about an interface from the configuration file * The information are saved in a Exalt_Eth_Save structure * @param file the configuration file * @param udi the hal udi of the interface * @return Returns the information */ Exalt_Eth_Save* _exalt_eet_eth_load(const char* file, const char* udi) { Exalt_Eth_Save *data = NULL; Eet_Data_Descriptor *edd; Eet_File *f; edd = _exalt_eth_save_edd_new(); f = eet_open(file, EET_FILE_MODE_READ); EXALT_ASSERT_RETURN(f!=NULL); data = eet_data_read(f, edd, udi); eet_close(f); eet_data_descriptor_free(edd); return data; }
/** * @brief Load the connection associated to an essid from the configuration file * @param file the configuration file * @param essid the essid * @return Returns the connection if success, else NULL */ Exalt_Connection* _exalt_eet_wireless_conn_load(const char*file, const char* essid) { Exalt_Connection *data = NULL; Eet_Data_Descriptor *edd; Eet_File *f; edd = exalt_conn_edd_new(); f = eet_open(file, EET_FILE_MODE_READ); EXALT_ASSERT_RETURN(f!=NULL); data = eet_data_read(f, edd, essid); eet_close(f); eet_data_descriptor_free(edd); return data; }
Eet_Data_Descriptor * exalt_conf_edd_new(Eet_Data_Descriptor* edd_network) { static Eet_Data_Descriptor_Class eddc; Eet_Data_Descriptor *edd; EXALT_ASSERT_RETURN(edd_network!=NULL); eet_eina_stream_data_descriptor_class_set(&eddc, sizeof (eddc), "Configuration", sizeof(Exalt_Configuration)); edd = eet_data_descriptor_stream_new(&eddc); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Exalt_Configuration, "dhcp", mode, EET_T_INT); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Exalt_Configuration, "ip", ip, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Exalt_Configuration, "netmask", netmask, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Exalt_Configuration, "gateway", gateway, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Exalt_Configuration, "wireless", wireless, EET_T_SHORT); EET_DATA_DESCRIPTOR_ADD_SUB(edd, Exalt_Configuration, "network", network, edd_network); EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Exalt_Configuration, "cmd_after_apply", cmd_after_apply, EET_T_STRING); return edd; }
short exalt_conf_valid_is(Exalt_Configuration* c) { short valid = 1; EXALT_ASSERT_RETURN(c!=NULL); if(exalt_conf_mode_get(c) == EXALT_STATIC) { if(!exalt_address_is(exalt_conf_ip_get(c)) || (exalt_conf_gateway_get(c) && !exalt_address_is(exalt_conf_gateway_get(c))) || !exalt_address_is(exalt_conf_netmask_get(c))) valid = 0; } /*if(valid && exalt_conf_wireless_is(c)) { if(!exalt_is_essid(exalt_conf_essid_get(c)) || !exalt_is_key(exalt_conf_key_get(c),exalt_conf_encryption_mode_get(c))) valid = 0; } */ return valid; }
/** * @brief save the wpa_supplicant configuration for a wireless interface * This configuration is saved in the wpa_supplicant configuration file * @param w the wireless card * @return Return 1 if success, else -0 */ int exalt_conf_save_wpasupplicant(Exalt_Wireless *w) { FILE *fw; Exalt_Ethernet *eth; Exalt_Connection *c; int enc_mode; EXALT_ASSERT_RETURN(w!=NULL); eth = exalt_wireless_get_ethernet(w); c = exalt_eth_get_connection(eth); EXALT_ASSERT_RETURN(exalt_conn_is_valid(c)); EXALT_ASSERT_RETURN(exalt_conn_is_wireless(c)); //its more easy to recreate a new file //so we don't modify the old file, just delete it :) remove(EXALT_WPA_CONF_FILE); //recreate the file EXALT_ASSERT_RETURN(ecore_file_mkpath(EXALT_WPA_CONF_FILE_DIR) != 0); //save the new configuration fw = fopen(EXALT_WPA_CONF_FILE,"w"); fprintf(fw,EXALT_WPA_CONF_HEADER); //add the new essid fprintf(fw,"network={\n"); fprintf(fw,"\tssid=\"%s\"\n",exalt_conn_get_essid(c)); enc_mode = exalt_conn_get_encryption_mode(c); if(enc_mode == EXALT_ENCRYPTION_WPA_PSK_CCMP_ASCII) { fprintf(fw,"\tscan_ssid=1\n"); fprintf(fw,"\tproto=WPA\n"); fprintf(fw,"\tkey_mgmt=WPA-PSK\n"); fprintf(fw,"\tpairwise=CCMP\n"); fprintf(fw,"\tgroup=CCMP\n"); fprintf(fw,"\tpsk=\"%s\"\n",exalt_conn_get_key(c)); } else if(enc_mode==EXALT_ENCRYPTION_WPA_PSK_TKIP_ASCII) { fprintf(fw,"\tscan_ssid=1\n"); fprintf(fw,"\tproto=WPA\n"); fprintf(fw,"\tkey_mgmt=WPA-PSK\n"); fprintf(fw,"\tpairwise=TKIP\n"); fprintf(fw,"\tgroup=TKIP\n"); fprintf(fw,"\tpsk=\"%s\"\n",exalt_conn_get_key(c)); } else if(enc_mode==EXALT_ENCRYPTION_WPA2_PSK_CCMP_ASCII) { fprintf(fw,"\tscan_ssid=1\n"); fprintf(fw,"\tproto=WPA2\n"); fprintf(fw,"\tkey_mgmt=WPA-PSK\n"); fprintf(fw,"\tpairwise=CCMP\n"); fprintf(fw,"\tgroup=CCMP\n"); fprintf(fw,"\tpsk=\"%s\"\n",exalt_conn_get_key(c)); } else if(enc_mode==EXALT_ENCRYPTION_WPA2_PSK_TKIP_ASCII) { fprintf(fw,"\tscan_ssid=1\n"); fprintf(fw,"\tproto=WPA2\n"); fprintf(fw,"\tkey_mgmt=WPA-PSK\n"); fprintf(fw,"\tpairwise=TKIP\n"); fprintf(fw,"\tgroup=TKIP\n"); fprintf(fw,"\tpsk=\"%s\"\n",exalt_conn_get_key(c)); } fprintf(fw,"}\n"); fclose(fw); return 1; }
/** * @brief save the connection associated to an essid * @param file the file where save * @param c the connection * @return Return 1 if success, else 0 */ int exalt_wireless_conn_save(const char* file, Exalt_Connection* c) { EXALT_ASSERT_RETURN(c!=NULL); return _exalt_eet_wireless_conn_save(file, c); }