/* * GProFTPD - A GTK+ frontend for the ProFTPD standalone server. * Copyright (C) 2001 - 2006 Magnus Loef (Magnus-swe) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * */ #include #include #include #include #include "widgets.h" #include "gettext.h" #include "allocate.h" #include "functions.h" #include "show_info.h" #include "dir_treeview_funcs.h" /* Temporary for option deprecations */ extern char global_version[1024]; /* The current directory beeing added and limited. */ gchar *dir; /* If row_pos=0 then this toplevel ftp directory is set */ extern gchar *homedir; /* Wether theres a problem with directory additions. */ extern int global_dir_error; /* The 18 checkbox values */ gchar *dir_val[19]; /* The users profile to be appended */ extern char *user_profile; extern long num_rows; extern int row_pos; /* Get the number of rows in the treeview */ gboolean num_rows_func(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, struct w *widgets) { num_rows++; return FALSE; } void append_limit_cmds() { int i = 0, has_limit = 0; /* Overwrite selected, add "Allowoverwrite on" before the directory limits */ if( dir_val[6] ) strcat(user_profile, "AllowOverwrite on\n"); /* ALLOW CMDs. Iter the 18 checkboxes */ strcat(user_profile, "\n AllowAll\n\n"); /* DENY CMDs. Iter the 18 checkboxes */ has_limit = 0; strcat(user_profile, "\n DenyAll\n\n"); } /* For each in the directory treeview */ gboolean dirs_foreach(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, struct w *widgets) { gchar *info = NULL; int i = 0; /* Iter the 18 checkboxes on each row and save the values */ for(i=1; i<19; i++) gtk_tree_model_get(model, iter, i, &dir_val[i], -1); /* Get the directory on this row */ gtk_tree_model_get(model, iter, 0, &dir, -1); /* Dont add directories with lengths < 5 */ if( dir == NULL || strlen((char *)dir) < 5 ) { if( strlen((char *)dir) < 1 ) info = g_strdup_printf(_("Invalid directory path: NONE")); else info = g_strdup_printf(_("Invalid directory path: %s"), dir); show_info(info); g_free(info); if( dir !=NULL ) g_free(dir); global_dir_error = 1; /* Return true so it stops iterating */ return TRUE; } /* This is the first toplevel home directory */ if( row_pos == 0 ) { row_pos++; /* Set homedir globally */ homedir = g_strdup_printf("%s", dir); /* Need write: 1 2 4 5 6 7 8 10 */ if( dir_val[1] || dir_val[2] || dir_val[4] || dir_val[5] || dir_val[6] || dir_val[7] || dir_val[8] || dir_val[10] ) make_dir_chmod(dir, "0777"); /* Does mkdir -p, no need to check if it exists */ else make_dir_chmod(dir, "0777"); /* 0755 Noone else can write either... limited by the server. */ if( dir !=NULL ) g_free(dir); /* Return true so it stops iterating */ return TRUE; } row_pos++; /* Ignore the first/home dir */ if( row_pos > 2 ) { /* Add the rest of the users directories */ /* Need write: 1 2 4 5 6 7 8 10 */ if( dir_val[1] || dir_val[2] || dir_val[4] || dir_val[5] || dir_val[6] || dir_val[7] || dir_val[8] || dir_val[10] ) make_dir_chmod(dir, "0777"); /* Does mkdir -p, no need to check if it exists */ else make_dir_chmod(dir, "0777"); /* 0755 Noone else can write either... limited by the server. */ strcat(user_profile, "\n"); append_limit_cmds(); strcat(user_profile, "\n"); } if( dir !=NULL ) g_free(dir); /* Return false to keep foreach func going */ return FALSE; }