aboutsummaryrefslogtreecommitdiff
path: root/sftp_server
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2005-08-28 17:24:04 +0000
committerAris Adamantiadis <aris@0xbadc0de.be>2005-08-28 17:24:04 +0000
commit8510d2abe49baf0c081ac52323d6a29ea94bab84 (patch)
tree7d6ee5f21069f9336acded6b76e3e31ebfbb4547 /sftp_server
parentdc0c5c4cfeefae2abc41d2475ed69e8fa26af1ee (diff)
downloadlibssh-8510d2abe49baf0c081ac52323d6a29ea94bab84.tar.gz
libssh-8510d2abe49baf0c081ac52323d6a29ea94bab84.tar.xz
libssh-8510d2abe49baf0c081ac52323d6a29ea94bab84.zip
youhou it works :)
to compile libconfig, configure it, then the makefile will work. to run, either make install make config or add its path to LD_LIBRARY_PATH. git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@21 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'sftp_server')
-rw-r--r--sftp_server/config.c106
-rw-r--r--sftp_server/list.c10
-rw-r--r--sftp_server/server.h6
-rw-r--r--sftp_server/sftp.conf1
4 files changed, 121 insertions, 2 deletions
diff --git a/sftp_server/config.c b/sftp_server/config.c
index 422e2575..0f735c2c 100644
--- a/sftp_server/config.c
+++ b/sftp_server/config.c
@@ -32,7 +32,46 @@ char *rsa=NULL;
list *groups;
list *users;
+/* 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 */
struct group *current_group=NULL;
+char *current_group_name;
+int add_user(char *user){
+ list *groups_from_user;
+// list *the_user;
+ printf("add_user(%s)\n",user);
+ if(!list_find(current_group->users,user)){
+ current_group->users=list_add(current_group->users,user,strdup(user));
+ }
+ groups_from_user=list_find(users,user);
+ if(!groups_from_user){
+ // the user isn't registered yet
+ groups_from_user=list_add(NULL,current_group_name,current_group_name);
+ users=list_add(users,user,groups_from_user);
+ } else {
+ // add the group name to the list of groups the user is bound to.
+ if(!list_find(groups_from_user,current_group_name)) // don't add it if it is already set
+ list_set(users,user,list_add(groups_from_user,current_group_name,current_group_name));
+ }
+ return 0;
+}
+
+int add_group(char *group){
+ struct group *grp=list_find(groups,group);
+ list *usr;
+ if(!grp){
+ printf("no such group %s\n",group);
+ return -1;
+ }
+ usr=grp->users;
+ while(usr){
+ add_user(usr->key);
+ usr=usr->next;
+ }
+ return 0;
+}
+
int group_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:
@@ -48,6 +87,7 @@ int group_callback(const char *shortvar, const char *var, const char *arguments,
current_group=malloc(sizeof(struct group));
memset(current_group,0,sizeof(struct group));
groups=list_add(groups,arguments,current_group);
+ current_group_name=strdup(arguments);
break;
case LC_FLAGS_SECTIONEND:
printf("end of group\n\n");
@@ -55,6 +95,45 @@ int group_callback(const char *shortvar, const char *var, const char *arguments,
break;
default:
printf("%s - %s\n", shortvar, value);
+ if(!strcasecmp(shortvar,"user")){
+ char *ptr;
+ char *user=(char *)value;
+ do{
+ ptr=strchr(user,',');
+ if(ptr){
+ *ptr=0;
+ ++ptr;
+ }
+ while(*user==' ')
+ ++user;
+ add_user(user);
+ user=ptr;
+ } while (user);
+ }
+ if(!strcasecmp(shortvar,"group")){
+ char *ptr;
+ char *group=(char *)value;
+ do{
+ ptr=strchr(group,',');
+ if(ptr){
+ *ptr=0;
+ ++ptr;
+ }
+ while(*group==' ')
+ ++group;
+ add_group(group);
+ group=ptr;
+ } while (group);
+ }
+ if(!strcasecmp(shortvar,"uid")){
+ current_group->uid=strdup(value);
+ }
+ if(!strcasecmp(shortvar,"gid")){
+ current_group->gid=strdup(value);
+ }
+ if(!strcasecmp(shortvar,"chroot")){
+ current_group->chroot=strdup(value);
+ }
}
return LC_CBRET_OKAY;
}
@@ -73,6 +152,32 @@ int dir_callback(const char *shortvar, const char *var, const char *arguments, c
return LC_CBRET_OKAY;
}
+void list_config(){
+ list *ptr=groups;
+ list *user;
+ printf("listing groups\n");
+ while(ptr){
+ printf("group %s\n",ptr->key);
+ user=((struct group *)ptr->data)->users;
+ while(user){
+ printf(" user %s\n",user->key);
+ user=user->next;
+ }
+ ptr=ptr->next;
+ }
+ printf("listing users\n");
+ user=users;
+ while(user){
+ printf("user %s\n",user->key);
+ ptr=user->data;
+ while(ptr){
+ printf(" group %s\n",ptr->key);
+ ptr=ptr->next;
+ }
+ user=user->next;
+ }
+}
+
int parse_config(char *file){
int r;
printf("Parsing configuration file %s\n",file);
@@ -96,5 +201,6 @@ int parse_config(char *file){
if(r<0)
printf("lc_process_file=%d,%s\n",r,lc_geterrstr());
lc_cleanup();
+ list_config();
return 0;
}
diff --git a/sftp_server/list.c b/sftp_server/list.c
index 2677c6aa..b14126c2 100644
--- a/sftp_server/list.c
+++ b/sftp_server/list.c
@@ -38,3 +38,13 @@ void *list_find(list *ptr, const char *key){
}
return NULL;
}
+
+void list_set(list *ptr, const char *key, void *data){
+ while(ptr){
+ if(!strcmp(key,ptr->key)){
+ ptr->data=data;
+ return;
+ }
+ ptr=ptr->next;
+ }
+}
diff --git a/sftp_server/server.h b/sftp_server/server.h
index 92749141..b211ca73 100644
--- a/sftp_server/server.h
+++ b/sftp_server/server.h
@@ -10,9 +10,11 @@ typedef struct list_struct {
list *list_add(list *ptr, const char *key, void *data);
void *list_find(list *ptr, const char *key);
+void list_set(list *ptr, const char *key, void *data);
+
struct group {
list *users;
char *chroot;
- int uid;
- int gid;
+ char *uid;
+ char *gid;
};
diff --git a/sftp_server/sftp.conf b/sftp_server/sftp.conf
index e3fa4696..f17aae83 100644
--- a/sftp_server/sftp.conf
+++ b/sftp_server/sftp.conf
@@ -12,6 +12,7 @@ Hostkeydsa /etc/ssh/ssh_host_dsa_key
</group>
<group users>
user test
+ user aris
chroot $HOME/
</group>
<group world>