[PATCH 2/3] cifs.upcall: fix usage message and segfault with no args

Jeff Layton jlayton at redhat.com
Tue Jul 15 17:10:28 GMT 2008


Some small cleanups to cifs.upcall. Move the usage message to its own
function. Fix usage message to print if we don't have a key after
processing options. Make the -v option print the version to stdout
and then exit.

Signed-off-by: Jeff Layton <jlayton at redhat.com>
---
 source/client/cifs.upcall.c |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/source/client/cifs.upcall.c b/source/client/cifs.upcall.c
index bbf5e6d..3860f33 100644
--- a/source/client/cifs.upcall.c
+++ b/source/client/cifs.upcall.c
@@ -200,6 +200,13 @@ int cifs_resolver(const key_serial_t key, const char *key_descr)
 	return 0;
 }
 
+void
+usage(const char *prog)
+{
+	syslog(LOG_WARNING, "Usage: %s [-c] [-v] key_serial", prog);
+	fprintf(stderr, "Usage: %s [-c] [-v] key_serial\n", prog);
+}
+
 int main(const int argc, char *const argv[])
 {
 	struct cifs_spnego_msg *keydata = NULL;
@@ -215,10 +222,6 @@ int main(const int argc, char *const argv[])
 	char *buf, *hostname = NULL;
 
 	openlog(prog, 0, LOG_DAEMON);
-	if (argc < 1) {
-		syslog(LOG_WARNING, "Usage: %s [-c] key_serial", prog);
-		goto out;
-	}
 
 	while ((c = getopt(argc, argv, "cv")) != -1) {
 		switch (c) {
@@ -227,9 +230,8 @@ int main(const int argc, char *const argv[])
 			break;
 			}
 		case 'v':{
-			syslog(LOG_WARNING, "version: %s", CIFSSPNEGO_VERSION);
-			fprintf(stderr, "version: %s", CIFSSPNEGO_VERSION);
-			break;
+			printf("version: %s\n", CIFSSPNEGO_VERSION);
+			goto out;
 			}
 		default:{
 			syslog(LOG_WARNING, "unknow option: %c", c);
@@ -237,6 +239,13 @@ int main(const int argc, char *const argv[])
 			}
 		}
 	}
+
+	/* is there a key? */
+	if (argc <= optind) {
+		usage(prog);
+		goto out;
+	}
+
 	/* get key and keyring values */
 	errno = 0;
 	key = strtol(argv[optind], NULL, 10);
-- 
1.5.5.1



More information about the samba-technical mailing list