mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 18:04:25 +09:00
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
This commit is contained in:
@@ -32,7 +32,46 @@ char *rsa=NULL;
|
|||||||
|
|
||||||
list *groups;
|
list *groups;
|
||||||
list *users;
|
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;
|
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){
|
int group_callback(const char *shortvar, const char *var, const char *arguments, const char *value, lc_flags_t flags, void *extra){
|
||||||
switch(flags){
|
switch(flags){
|
||||||
case LC_FLAGS_SECTIONSTART:
|
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));
|
current_group=malloc(sizeof(struct group));
|
||||||
memset(current_group,0,sizeof(struct group));
|
memset(current_group,0,sizeof(struct group));
|
||||||
groups=list_add(groups,arguments,current_group);
|
groups=list_add(groups,arguments,current_group);
|
||||||
|
current_group_name=strdup(arguments);
|
||||||
break;
|
break;
|
||||||
case LC_FLAGS_SECTIONEND:
|
case LC_FLAGS_SECTIONEND:
|
||||||
printf("end of group\n\n");
|
printf("end of group\n\n");
|
||||||
@@ -55,6 +95,45 @@ int group_callback(const char *shortvar, const char *var, const char *arguments,
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("%s - %s\n", shortvar, value);
|
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;
|
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;
|
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 parse_config(char *file){
|
||||||
int r;
|
int r;
|
||||||
printf("Parsing configuration file %s\n",file);
|
printf("Parsing configuration file %s\n",file);
|
||||||
@@ -96,5 +201,6 @@ int parse_config(char *file){
|
|||||||
if(r<0)
|
if(r<0)
|
||||||
printf("lc_process_file=%d,%s\n",r,lc_geterrstr());
|
printf("lc_process_file=%d,%s\n",r,lc_geterrstr());
|
||||||
lc_cleanup();
|
lc_cleanup();
|
||||||
|
list_config();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,3 +38,13 @@ void *list_find(list *ptr, const char *key){
|
|||||||
}
|
}
|
||||||
return NULL;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,9 +10,11 @@ typedef struct list_struct {
|
|||||||
|
|
||||||
list *list_add(list *ptr, const char *key, void *data);
|
list *list_add(list *ptr, const char *key, void *data);
|
||||||
void *list_find(list *ptr, const char *key);
|
void *list_find(list *ptr, const char *key);
|
||||||
|
void list_set(list *ptr, const char *key, void *data);
|
||||||
|
|
||||||
struct group {
|
struct group {
|
||||||
list *users;
|
list *users;
|
||||||
char *chroot;
|
char *chroot;
|
||||||
int uid;
|
char *uid;
|
||||||
int gid;
|
char *gid;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ Hostkeydsa /etc/ssh/ssh_host_dsa_key
|
|||||||
</group>
|
</group>
|
||||||
<group users>
|
<group users>
|
||||||
user test
|
user test
|
||||||
|
user aris
|
||||||
chroot $HOME/
|
chroot $HOME/
|
||||||
</group>
|
</group>
|
||||||
<group world>
|
<group world>
|
||||||
|
|||||||
Reference in New Issue
Block a user