mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-08-05 20:55:46 +03:00
fixed null pointer into options and ssh_set_error()
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@138 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
@@ -205,7 +205,15 @@ typedef struct signature_struct {
|
|||||||
#endif
|
#endif
|
||||||
} SIGNATURE;
|
} SIGNATURE;
|
||||||
|
|
||||||
|
|
||||||
|
struct error_struct {
|
||||||
|
/* error handling */
|
||||||
|
int error_code;
|
||||||
|
char error_buffer[ERROR_BUFFERLEN];
|
||||||
|
};
|
||||||
|
|
||||||
struct ssh_options_struct {
|
struct ssh_options_struct {
|
||||||
|
struct error_struct error;
|
||||||
char *banner; /* explicit banner to send */
|
char *banner; /* explicit banner to send */
|
||||||
char *username;
|
char *username;
|
||||||
char *host;
|
char *host;
|
||||||
@@ -275,14 +283,6 @@ struct channel_struct {
|
|||||||
int blocking;
|
int blocking;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct error_struct {
|
|
||||||
/* error handling */
|
|
||||||
int error_code;
|
|
||||||
char error_buffer[ERROR_BUFFERLEN];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct ssh_session {
|
struct ssh_session {
|
||||||
struct error_struct error;
|
struct error_struct error;
|
||||||
struct socket *socket;
|
struct socket *socket;
|
||||||
|
@@ -275,11 +275,11 @@ void ssh_options_set_banner(SSH_OPTIONS *opt, char *banner){
|
|||||||
*/
|
*/
|
||||||
int ssh_options_set_wanted_algos(SSH_OPTIONS *opt,int algo, char *list){
|
int ssh_options_set_wanted_algos(SSH_OPTIONS *opt,int algo, char *list){
|
||||||
if(algo > SSH_LANG_S_C || algo < 0){
|
if(algo > SSH_LANG_S_C || algo < 0){
|
||||||
ssh_set_error(NULL,SSH_REQUEST_DENIED,"algo %d out of range",algo);
|
ssh_set_error(opt,SSH_REQUEST_DENIED,"algo %d out of range",algo);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if( (!opt->use_nonexisting_algo) && !verify_existing_algo(algo,list)){
|
if( (!opt->use_nonexisting_algo) && !verify_existing_algo(algo,list)){
|
||||||
ssh_set_error(NULL,SSH_REQUEST_DENIED,"Setting method : no algorithm "
|
ssh_set_error(opt,SSH_REQUEST_DENIED,"Setting method : no algorithm "
|
||||||
"for method \"%s\" (%s)\n",ssh_kex_nums[algo],list);
|
"for method \"%s\" (%s)\n",ssh_kex_nums[algo],list);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -289,7 +289,7 @@ int ssh_options_set_wanted_algos(SSH_OPTIONS *opt,int algo, char *list){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *get_username_from_uid(int uid){
|
static char *get_username_from_uid(SSH_OPTIONS *opt, int uid){
|
||||||
struct passwd *pwd;
|
struct passwd *pwd;
|
||||||
char *user;
|
char *user;
|
||||||
while((pwd=getpwent())){
|
while((pwd=getpwent())){
|
||||||
@@ -300,7 +300,7 @@ static char *get_username_from_uid(int uid){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
endpwent();
|
endpwent();
|
||||||
ssh_set_error(NULL,SSH_FATAL,"uid %d doesn't exist !",uid);
|
ssh_set_error(opt,SSH_FATAL,"uid %d doesn't exist !",uid);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,7 +314,7 @@ int ssh_options_default_username(SSH_OPTIONS *opt){
|
|||||||
opt->username=strdup(user);
|
opt->username=strdup(user);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
user=get_username_from_uid(getuid());
|
user=get_username_from_uid(opt,getuid());
|
||||||
if(user){
|
if(user){
|
||||||
opt->username=user;
|
opt->username=user;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -483,7 +483,7 @@ int ssh_options_getopt(SSH_OPTIONS *options, int *argcptr, char **argv){
|
|||||||
save[current++]=argv[optind++];
|
save[current++]=argv[optind++];
|
||||||
|
|
||||||
if(usersa && usedss){
|
if(usersa && usedss){
|
||||||
ssh_set_error(NULL,SSH_FATAL,"either RSA or DSS must be chosen");
|
ssh_set_error(options,SSH_FATAL,"either RSA or DSS must be chosen");
|
||||||
cont=0;
|
cont=0;
|
||||||
}
|
}
|
||||||
ssh_set_verbosity(debuglevel);
|
ssh_set_verbosity(debuglevel);
|
||||||
|
4
sample.c
4
sample.c
@@ -379,8 +379,10 @@ int main(int argc, char **argv){
|
|||||||
unsigned char hash[MD5_DIGEST_LEN];
|
unsigned char hash[MD5_DIGEST_LEN];
|
||||||
|
|
||||||
options=ssh_options_new();
|
options=ssh_options_new();
|
||||||
if(ssh_options_getopt(options,&argc, argv))
|
if(ssh_options_getopt(options,&argc, argv)){
|
||||||
|
fprintf(stderr,"error parsing command line :%s\n",ssh_get_error(options));
|
||||||
usage();
|
usage();
|
||||||
|
}
|
||||||
opts(argc,argv);
|
opts(argc,argv);
|
||||||
signal(SIGTERM,do_exit);
|
signal(SIGTERM,do_exit);
|
||||||
if(user)
|
if(user)
|
||||||
|
Reference in New Issue
Block a user