diff --git a/nmapfe/nmapfe.c b/nmapfe/nmapfe.c index 5c00a8dc2..864b533e2 100644 --- a/nmapfe/nmapfe.c +++ b/nmapfe/nmapfe.c @@ -143,6 +143,8 @@ static void About_callback (void); static void Quit_callback (void); static void Colourize_callback (GtkAction *action, GtkRadioAction *current); +void scanType_cb (GtkComboBox *widget, gpointer data); + GtkWidget *main_win; static GtkActionEntry menu_entries[] = { @@ -188,31 +190,24 @@ static const char *menu_description = " " ""; -static GtkItemFactoryEntry userScanEntries[] = { - { "/Connect Scan", NULL, scanType_changed_fcb, CONNECT_SCAN, NULL }, - { "/Ping Sweep", NULL, scanType_changed_fcb, PING_SCAN, NULL }, - { "/Host List", NULL, scanType_changed_fcb, LIST_SCAN, NULL }, - { "/FTP Bounce Attack", NULL, scanType_changed_fcb, BOUNCE_SCAN, NULL }, - { NULL, NULL, NULL, NO_SCAN, NULL } +static Entry scanentries[] = { + { "SYN Stealth Scan", SYN_SCAN, TRUE }, + { "Connect Scan", CONNECT_SCAN, FALSE }, + { "ACK Stealth Scan", ACK_SCAN, TRUE }, + { "FIN|ACK Stealth Scan", MAIMON_SCAN, TRUE }, + { "FIN Stealth Scan", FIN_SCAN, TRUE }, + { "NULL Stealth Scan", NULL_SCAN, TRUE }, + { "XMas Tree Stealth Scan", XMAS_SCAN, TRUE }, + { "TCP Window Scan", WIN_SCAN, TRUE }, + { "UDP Port Scan", UDP_SCAN, TRUE }, + { "IP Protocol Scan", PROT_SCAN, TRUE }, + { "Ping Sweep", PING_SCAN, FALSE }, + { "Host List", LIST_SCAN, FALSE }, + { "FTP Bounce Attack", BOUNCE_SCAN, FALSE }, + { "Idle Scan", IDLE_SCAN, TRUE }, + { NULL, 0, FALSE } }; -static GtkItemFactoryEntry rootScanEntries[] = { - { "/Connect Scan", NULL, scanType_changed_fcb, CONNECT_SCAN, NULL }, - { "/SYN Stealth Scan", NULL, scanType_changed_fcb, SYN_SCAN, NULL }, - { "/ACK Stealth Scan", NULL, scanType_changed_fcb, ACK_SCAN, NULL }, - { "/FIN|ACK Stealth Scan", NULL, scanType_changed_fcb, MAIMON_SCAN, NULL }, - { "/FIN Stealth Scan", NULL, scanType_changed_fcb, FIN_SCAN, NULL }, - { "/NULL Stealth Scan", NULL, scanType_changed_fcb, NULL_SCAN, NULL }, - { "/XMas Tree Stealth Scan", NULL, scanType_changed_fcb, XMAS_SCAN, NULL }, - { "/TCP Window Scan", NULL, scanType_changed_fcb, WIN_SCAN, NULL }, - { "/UDP Port Scan", NULL, scanType_changed_fcb, UDP_SCAN, NULL }, - { "/IP Protocol Scan", NULL, scanType_changed_fcb, PROT_SCAN, NULL }, - { "/Ping Sweep", NULL, scanType_changed_fcb, PING_SCAN, NULL }, - { "/Host List", NULL, scanType_changed_fcb, LIST_SCAN, NULL }, - { "/FTP Bounce Attack", NULL, scanType_changed_fcb, BOUNCE_SCAN, NULL }, - { "/Idle Scan", NULL, scanType_changed_fcb, IDLE_SCAN, NULL }, - { NULL, NULL, NULL, NO_SCAN, NULL } -}; static GtkItemFactoryEntry throttleEntries[] = { @@ -373,7 +368,23 @@ About_callback (void) { #endif } +static GtkTreeModel * +create_dropdown_store(Entry *data, gboolean is_root) +{ + GtkTreeIter iter; + GtkTreeStore *store; + gint i; + + store = gtk_tree_store_new (1, G_TYPE_STRING); + for (i = 0; data[i].scan; i++) { + if (is_root || (data[i].rootonly == is_root)) { + gtk_tree_store_append(store, &iter, NULL); + gtk_tree_store_set(store, &iter, 0, data[i].scan, -1); + } + } + return GTK_TREE_MODEL (store); +} /* Returns a menubar widget made from the above menu */ static GtkWidget *new_factory_menu(GtkWidget *window, GtkType menuType, const gchar *name, GtkItemFactoryEntry *entries, @@ -553,17 +564,33 @@ GtkAdjustment *adjust; gtk_table_set_row_spacings(GTK_TABLE(table), 5); gtk_container_add(GTK_CONTAINER(frame), table); - opt.scanType = new_factory_menu(NULL, GTK_TYPE_OPTION_MENU, "", - (opt.uid == 0) ? rootScanEntries : userScanEntries, - &opt.scanValue); - opt.scanValue = (opt.uid == 0) ? SYN_SCAN : CONNECT_SCAN; - gtk_option_menu_set_history(GTK_OPTION_MENU(opt.scanType), - opt.scanValue - SCAN_OFFSET); - - /*gtk_object_set(GTK_OBJECT(opt.scanType), "height", 26, NULL);*/ - gtk_table_attach_defaults(GTK_TABLE(table), opt.scanType, 0, 4, 0, 1); - gtk_widget_show(opt.scanType); + /* Create "Scan Type" combobox */ + { + GtkCellRenderer *renderer; + GtkTreeModel *model; + model = create_dropdown_store (scanentries, + (opt.uid == 0) ? TRUE : FALSE); + opt.scanType = gtk_combo_box_new_with_model (model); + g_object_unref (model); + opt.scanValue = (opt.uid == 0) ? SYN_SCAN : CONNECT_SCAN; + + gtk_table_attach_defaults (GTK_TABLE(table), opt.scanType, 0, 4, 0, 1); + gtk_widget_show (opt.scanType); + + renderer = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start ( + GTK_CELL_LAYOUT (opt.scanType), renderer, TRUE); + gtk_cell_layout_set_attributes ( + GTK_CELL_LAYOUT (opt.scanType), renderer, + "text", 0, + NULL); + g_object_unref(renderer); + + g_signal_connect(G_OBJECT(opt.scanType), "changed", + G_CALLBACK (scanType_cb), scanentries); + + } opt.scanRelayLabel = gtk_label_new("Relay Host:"); gtk_label_set_justify(GTK_LABEL(opt.scanRelayLabel), GTK_JUSTIFY_LEFT); @@ -1381,6 +1408,11 @@ GtkAdjustment *adjust; gtk_widget_show(main_vbox); + /* Set default values here because now we can be sure that all the + * widgets have been created. + */ + gtk_combo_box_set_active(GTK_COMBO_BOX (opt.scanType), 0); + display_nmap_command(); return main_win; diff --git a/nmapfe/nmapfe.h b/nmapfe/nmapfe.h index 39d0f880a..42b0d4327 100644 --- a/nmapfe/nmapfe.h +++ b/nmapfe/nmapfe.h @@ -121,6 +121,12 @@ /* #define DEBUG(str) { fprintf(stderr, str); fflush(stderr); } */ +typedef struct { + gchar *scan; + gint scantype; + gboolean rootonly; +} Entry; + /* main menu entries */ enum { diff --git a/nmapfe/nmapfe_sig.c b/nmapfe/nmapfe_sig.c index e28d607ec..02c01a6cb 100644 --- a/nmapfe/nmapfe_sig.c +++ b/nmapfe/nmapfe_sig.c @@ -709,12 +709,29 @@ const char *name = gtk_entry_get_text(GTK_ENTRY(text)); gtk_widget_show(create_fileSelection("Select File", filename, NULL, GTK_ENTRY(text))); } -void scanType_changed_fcb(int *variable, guint action, GtkWidget *w) +void scanType_cb +(GtkComboBox *w, gpointer data) { - if ((variable != NULL) && (w != NULL)) { - *variable = action; + Entry *user = data; + gint i = 0, j, k; - if ((action == PING_SCAN) || (action == LIST_SCAN)) { + j = gtk_combo_box_get_active(w); + + if (opt.uid == 0) { + k = j; + } else { + for (k = 0; user[k].scantype; k++) { + if (user[k].rootonly != TRUE) { + if (i == j) { + break; + } + i++; + } + } + } + opt.scanValue = user[k].scantype; + + if ((opt.scanValue == PING_SCAN) || (opt.scanValue == LIST_SCAN)) { // gtk_widget_set_sensitive(GTK_WIDGET(opt.protportFrame), FALSE); gtk_widget_set_sensitive(GTK_WIDGET(opt.protportType), FALSE); gtk_widget_set_sensitive(GTK_WIDGET(opt.protportLabel), FALSE); @@ -730,7 +747,8 @@ void scanType_changed_fcb(int *variable, guint action, GtkWidget *w) gtk_widget_set_sensitive(GTK_WIDGET(opt.OSInfo), TRUE); } - if ((action == PING_SCAN) || (action == LIST_SCAN) || (action == PROT_SCAN)) { + if ((opt.scanValue == PING_SCAN) || + (opt.scanValue == LIST_SCAN) || (opt.scanValue == PROT_SCAN)) { gtk_widget_set_sensitive(GTK_WIDGET(opt.RPCInfo), FALSE); gtk_widget_set_sensitive(GTK_WIDGET(opt.VersionInfo), FALSE); } else { @@ -738,7 +756,7 @@ void scanType_changed_fcb(int *variable, guint action, GtkWidget *w) gtk_widget_set_sensitive(GTK_WIDGET(opt.VersionInfo), TRUE); } - if ((action == CONNECT_SCAN) || (action == BOUNCE_SCAN)) { + if ((opt.scanValue == CONNECT_SCAN) || (opt.scanValue == BOUNCE_SCAN)) { gtk_widget_set_sensitive(GTK_WIDGET(opt.useDecoy), FALSE); gtk_widget_set_sensitive(GTK_WIDGET(opt.Decoy), FALSE); } else if (opt.uid == 0) { @@ -746,16 +764,17 @@ void scanType_changed_fcb(int *variable, guint action, GtkWidget *w) gtk_widget_set_sensitive(GTK_WIDGET(opt.Decoy), TRUE); } - if ((action != ACK_SCAN) && (action != MAIMON_SCAN) && (action != FIN_SCAN) && - (action != SYN_SCAN) && (action != NULL_SCAN) && (action != XMAS_SCAN) && - (action != WIN_SCAN)) + if ((opt.scanValue != ACK_SCAN) && + (opt.scanValue != MAIMON_SCAN) && (opt.scanValue != FIN_SCAN) && + (opt.scanValue != SYN_SCAN) && (opt.scanValue != NULL_SCAN) && + (opt.scanValue != XMAS_SCAN) && (opt.scanValue != WIN_SCAN)) gtk_widget_set_sensitive(GTK_WIDGET(opt.useFragments), FALSE); else if (opt.uid == 0) gtk_widget_set_sensitive(GTK_WIDGET(opt.useFragments), TRUE); - if ((action == BOUNCE_SCAN) || (action == IDLE_SCAN)) { + if ((opt.scanValue == BOUNCE_SCAN) || (opt.scanValue == IDLE_SCAN)) { gtk_label_set_text(GTK_LABEL(opt.scanRelayLabel), - (action == BOUNCE_SCAN) ? "Bounce Host:" : "Zombie Host:"); + (opt.scanValue == BOUNCE_SCAN) ? "Bounce Host:" : "Zombie Host:"); gtk_widget_set_sensitive(GTK_WIDGET(opt.scanRelayLabel), TRUE); gtk_widget_set_sensitive(GTK_WIDGET(opt.scanRelay), TRUE); gtk_widget_grab_focus(GTK_WIDGET(opt.scanRelay)); @@ -766,8 +785,7 @@ void scanType_changed_fcb(int *variable, guint action, GtkWidget *w) } gtk_object_set(GTK_OBJECT(opt.protportFrame), "label", - (action == PROT_SCAN) ? "Scanned Protocols" : "Scanned Ports", NULL); - } + (opt.scanValue == PROT_SCAN) ? "Scanned Protocols" : "Scanned Ports", NULL); display_nmap_command(); }