aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-16 16:20:32 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-16 16:20:32 +0000
commita2cce56134e6bf5024b4e8e86816e719cea8bfb2 (patch)
treed9c8c424c73ef8949dcd02e44f639c0068d2f29e
parent59f04bfddd47a963d0039094003fe82412df3ab5 (diff)
downloadlibssh-a2cce56134e6bf5024b4e8e86816e719cea8bfb2.tar.gz
libssh-a2cce56134e6bf5024b4e8e86816e719cea8bfb2.tar.xz
libssh-a2cce56134e6bf5024b4e8e86816e719cea8bfb2.zip
Add a better match() function.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@510 7dcaeef0-15fb-0310-b436-a5af3365683c
-rw-r--r--libssh/dh.c45
1 files changed, 21 insertions, 24 deletions
diff --git a/libssh/dh.c b/libssh/dh.c
index 9a70eb4c..94710b72 100644
--- a/libssh/dh.c
+++ b/libssh/dh.c
@@ -4,6 +4,7 @@
* This file is part of the SSH Library
*
* Copyright (c) 2003-2008 by Aris Adamantiadis
+ * Copyright (c) 2009 by Andreas Schneider <mail@cynapses.org>
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@@ -847,32 +848,28 @@ STRING *ssh_get_pubkey(SSH_SESSION *session){
return string_copy(session->current_crypto->server_pubkey);
}
-/* XXX i doubt it is still needed, or may need some fix */
static int match(const char *group, const char *object){
- char *ptr,*saved;
- char *end;
- ptr=strdup(group);
- if (ptr == NULL) {
- return -1;
- }
- saved=ptr;
- while(1){
- end=strchr(ptr,',');
- if(end)
- *end=0;
- if(!strcmp(ptr,object)){
- free(saved);
- return 0;
- }
- if(end)
- ptr=end+1;
- else{
- free(saved);
- return -1;
- }
+ const char *p;
+ const char *z;
+
+ p = z = group;
+ do {
+ p = strchr(z, ',');
+ if (p == NULL) {
+ if (strcmp(z, object) == 0) {
+ return 1;
+ }
+ return 0;
+ } else {
+ if (strncmp(z, object, p - z) == 0) {
+ return 1;
+ }
}
- /* not reached */
- return 1;
+ z = p + 1;
+ } while(1);
+
+ /* not reached */
+ return 0;
}
static int sig_verify(SSH_SESSION *session, PUBLIC_KEY *pubkey, SIGNATURE *signature,