diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2005-08-28 23:56:01 +0000 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2005-08-28 23:56:01 +0000 |
commit | 0de0dca16d1caf6c712fb4b50d4ff7c7e25d5129 (patch) | |
tree | 34a1f29f23f3716a416b227c4886f91f7c7bd0e8 /sftp_server/config.c | |
parent | 8510d2abe49baf0c081ac52323d6a29ea94bab84 (diff) | |
download | libssh-0de0dca16d1caf6c712fb4b50d4ff7c7e25d5129.tar.gz libssh-0de0dca16d1caf6c712fb4b50d4ff7c7e25d5129.tar.xz libssh-0de0dca16d1caf6c712fb4b50d4ff7c7e25d5129.zip |
more ACL on directories. Not already enabled.
First Pam code. looks like it works more or less.
it needs a file in /etc/pam.d to be activated
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@22 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'sftp_server/config.c')
-rw-r--r-- | sftp_server/config.c | 93 |
1 files changed, 90 insertions, 3 deletions
diff --git a/sftp_server/config.c b/sftp_server/config.c index 0f735c2c..be69d077 100644 --- a/sftp_server/config.c +++ b/sftp_server/config.c @@ -23,6 +23,7 @@ MA 02111-1307, USA. */ #include <stdio.h> #include <unistd.h> #include <string.h> +#include <stdlib.h> #include "server.h" /* shortvar is "port" in "port 22" */ @@ -32,6 +33,7 @@ char *rsa=NULL; list *groups; list *users; +struct dir *root_dir=NULL; /* users is a list of users. The key of this list is the user name. the data of the list is a list of groups. both data & key from this list is the group name */ @@ -137,17 +139,47 @@ int group_callback(const char *shortvar, const char *var, const char *arguments, } return LC_CBRET_OKAY; } +struct dir *create_directory(const char *directory); +struct dir *current_dir=NULL; +int append_groups(list **plist, const char *groups){ + char *begin=strdup(groups); + char *ptr; + char *grp=begin; + do{ + ptr=strchr(grp,','); + if(ptr){ + *ptr=0; + ++ptr; + } + while(*grp==' ') + ++grp; + if(!list_find(*plist,grp)) + *plist=list_add(*plist,grp,strdup(grp)); + grp=ptr; + } while (grp); + return 0; +} int dir_callback(const char *shortvar, const char *var, const char *arguments, const char *value, lc_flags_t flags, void *extra){ switch(flags){ case LC_FLAGS_SECTIONSTART: - printf("new dir %s\n",arguments); + if(current_dir){ + printf("Cannot define a directory into a directory !\n"); + return LC_CBRET_ERROR; + } + current_dir=create_directory(arguments); break; case LC_FLAGS_SECTIONEND: - printf("end of dir\n\n"); + current_dir=NULL; break; default: - printf("%s - %s\n",shortvar, value); + if(!strcasecmp(shortvar,"list")) + append_groups(¤t_dir->List,value); + if(!strcasecmp(shortvar,"read")) + append_groups(¤t_dir->Read,value); + if(!strcasecmp(shortvar,"write")) + append_groups(¤t_dir->Write,value); +// printf("%s - %s\n",shortvar, value); } return LC_CBRET_OKAY; } @@ -178,6 +210,61 @@ void list_config(){ } } +char **cut_directory(const char *dir){ + char *tmp=strdup(dir); + char *ptr; + char *ret[128]; + char **answer; + int i=0; + while(tmp && *tmp && i<128){ + while(*tmp=='/') + ++tmp; + ptr=strchr(tmp,'/'); + if(ptr){ + *ptr=0; + ++ptr; + } + ret[i]=strdup(tmp); + tmp=ptr; + i++; + } + answer=malloc((i+1)*sizeof(char *)); + memcpy(answer,ret,sizeof(char *)*i); + answer[i]=NULL; + return answer; +} + +struct dir *dir_new(){ + struct dir *dir=malloc(sizeof(struct dir)); + memset(dir,0,sizeof(*dir)); + return dir; +} +/* it doesn't really create the directory. it makes the tree to the directory + * and returns a link to the last node */ +struct dir *create_directory(const char *directory){ + char **tokens=cut_directory(directory); + int i=0; + struct dir *dir,*ptr; + if(!root_dir){ + root_dir=dir_new(); + root_dir->name=""; + } + dir=root_dir; + for(i=0;tokens[i];++i){ + ptr=list_find(dir->subdir,tokens[i]); + if(!ptr){ + ptr=dir_new(); + ptr->name=strdup(tokens[i]); + dir->subdir=list_add(dir->subdir,tokens[i],ptr); + } + dir=ptr; + } + for(i=0;tokens[i];++i) + free(tokens[i]); + free(tokens); + return dir; +} + int parse_config(char *file){ int r; printf("Parsing configuration file %s\n",file); |