Added password prompting. Added - susmb - mounting of SMB/CIFS shares via FUSE
(HTM) git clone git://git.codemadness.org/susmb
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 75faa5048782f604cec733a804c331b36859f1f6
(DIR) parent 74f8aa75a21a15d0a9bd036ce850b65c210fa7ee
(HTM) Author: Geoff Johnstone <geoffSHEEP.johnstoneFROG@googlemail.com>
Date: Fri, 30 May 2008 18:33:29 +0100
Added password prompting.
Added
Diffstat:
M Makefile | 14 ++++++++------
M conffile.c | 8 ++++++--
M conffile.h | 2 +-
M config.rng | 4 +++-
M options.h | 2 +-
A password.c | 79 +++++++++++++++++++++++++++++++
A password.h | 24 ++++++++++++++++++++++++
M usmb.c | 11 +++++++++--
M usmb.h | 11 ++++++-----
M utils.c | 12 ++++++++++++
M utils.h | 5 +++--
M version.h | 2 +-
M xml.h | 7 ++++---
13 files changed, 157 insertions(+), 24 deletions(-)
---
(DIR) diff --git a/Makefile b/Makefile
@@ -23,7 +23,7 @@ BINDIR = $(PREFIX)/bin
CFLAGS += -Wall -Wextra -Werror -std=c99 -pedantic -O \
-I$(SAMBA)/include -D_BSD_SOURCE -DFUSE_USE_VERSION=26 \
- -DHAVE_UTIME_H
+ -DHAVE_UTIME_H -DMUSTCHECK='__attribute__ ((warn_unused_result))'
LDLIBS = -lsmbclient
LDFLAGS = -L$(SAMBA)/lib
@@ -34,8 +34,8 @@ CFLAGS += $(shell pkg-config --cflags $(PACKAGES))
LDLIBS += $(shell pkg-config --libs-only-l $(PACKAGES))
LDFLAGS += $(shell pkg-config --libs-only-L $(PACKAGES))
-SOURCES = conffile.c options.c usmb.c usmb_dir.c usmb_file.c utils.c \
- version.c xml.c
+SOURCES = conffile.c options.c password.c usmb.c usmb_dir.c usmb_file.c \
+ utils.c version.c xml.c
OBJECTS = $(SOURCES:.c=.o)
PROGRAM = usmb
@@ -95,12 +95,14 @@ tar:
.PHONY: all debug dist install install-strip uninstall clean distclean tar
-conffile.o: conffile.c utils.h xml.h config.rng.h
+conffile.o: conffile.c password.h utils.h xml.h config.rng.h
options.o: options.c options.h utils.h version.h
-usmb.o: usmb.c conffile.h options.h usmb.h usmb_dir.h usmb_file.h \
- utils.h version.h
+password.o: password.c password.h utils.h
+usmb.o: usmb.c conffile.h options.h usmb.h usmb_dir.h usmb_file.h utils.h \
+ version.h
usmb_dir.o: usmb_dir.c usmb_dir.h usmb.h utils.h
usmb_file.o: usmb_file.c usmb_file.h usmb.h utils.h
utils.o: utils.c utils.h
version.o: version.c version.h
xml.o: xml.c xml.h utils.h
+
(DIR) diff --git a/conffile.c b/conffile.c
@@ -18,6 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "password.h"
#include "utils.h"
#include "xml.h"
#include "config.rng.h"
@@ -98,7 +99,10 @@ bool conffile_get_mount (const char *filename, const char *key,
(void)do_xpath_text (ctx, "credentials", creds, "domain", domain);
if (!do_xpath_text (ctx, "credentials", creds, "username", username)) break;
- if (!do_xpath_text (ctx, "credentials", creds, "password", password)) break;
+
+ if (!do_xpath_text (ctx, "credentials", creds, "password", password) &&
+ !password_read (password))
+ break;
xmlXPathFreeContext (ctx);
xmlFreeDoc (doc);
@@ -110,7 +114,7 @@ bool conffile_get_mount (const char *filename, const char *key,
fputs ("Invalid configuration.\n", stderr);
xfree (*username);
- xfree (*password);
+ clear_and_free (*password);
xfree (*domain);
xfree (creds);
xfree (*options);
(DIR) diff --git a/conffile.h b/conffile.h
@@ -23,5 +23,5 @@
char **server, char **share,
char **mountpoint, char **options,
char **domain, char **username,
- char **password);
+ char **password) MUSTCHECK;
#endif
(DIR) diff --git a/config.rng b/config.rng
@@ -24,7 +24,9 @@
<element name="domain"> <text /> </element>
</optional>
<element name="username"> <text /> </element>
- <element name="password"> <text /> </element>
+ <optional>
+ <element name="password"> <text /> </element>
+ </optional>
</element>
</define>
(DIR) diff --git a/options.h b/options.h
@@ -18,7 +18,7 @@
#define OPTIONS_H
bool parse_args (int *argc, char ***argv,
- const char **mountid, const char **out_conffile);
+ const char **mountid, const char **out_conffile) MUSTCHECK;
void build_fuse_args (const char *options, const char *mountpoint,
int *out_argc, char ***out_argv);
(DIR) diff --git a/password.c b/password.c
@@ -0,0 +1,79 @@
+/* usmb - mount SMB shares via FUSE and Samba
+ * Copyright (C) 2006-2008 Geoff Johnstone
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+#include "password.h"
+#include "utils.h"
+
+
+bool password_read (char **out)
+{
+ struct termios attr, new;
+
+ assert (NULL != out);
+ *out = NULL;
+
+ if (0 != tcgetattr (STDIN_FILENO, &attr))
+ {
+ perror ("tcgetattr");
+ fputs ("Cannot configure terminal to read password securely.\n", stderr);
+ return false;
+ }
+
+ new = attr;
+ new.c_lflag &= ~ECHO;
+
+ if (0 != tcsetattr (STDIN_FILENO, TCSAFLUSH, &new))
+ {
+ perror ("tcsetattr");
+ fputs ("Cannot configure terminal to read password securely.\n", stderr);
+ return false;
+ }
+
+ bool ok = false;
+ char buff[1024];
+
+ fputs ("\nPassword: ", stdout);
+ fflush (stdout);
+ ok = (buff == fgets (buff, sizeof (buff), stdin));
+ fputc ('\n', stdout);
+
+ if (0 != tcsetattr (STDIN_FILENO, TCSAFLUSH, &attr))
+ {
+ perror ("tcsetattr");
+ fputs ("Failed to reset terminal.\n", stderr);
+ }
+
+ // strip a trailing '\n'.
+ {
+ size_t len = strlen (buff);
+
+ if ((0 < len) && ('\n' == buff[len - 1]))
+ buff[len - 1] = '\0';
+ }
+
+ *out = xstrdup (buff);
+ DEBUG (fprintf (stderr, "Password: %s\n", *out));
+
+ return (NULL != *out);
+}
+
(DIR) diff --git a/password.h b/password.h
@@ -0,0 +1,24 @@
+/* usmb - mount SMB shares via FUSE and Samba
+ * Copyright (C) 2006-2008 Geoff Johnstone
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PASSWORD_H
+ #define PASSWORD_H
+
+ #include <stdbool.h>
+
+ bool password_read (char **out) MUSTCHECK;
+
+#endif
(DIR) diff --git a/usmb.c b/usmb.c
@@ -245,7 +245,7 @@ static bool create_share_name (const char *server, const char *sharename)
static void free_strings (char *sharename)
{
xfree (sharename);
- xfree (password);
+ clear_and_free (password);
xfree (username);
xfree (domain);
xfree (options);
@@ -260,6 +260,12 @@ int main (int argc, char **argv)
const char *conffile, *mountid;
char *sharename = NULL;
+ if (sizeof (uint64_t) < sizeof (uintptr_t))
+ {
+ fputs ("usmb is not supported on this platform.\n", stderr);
+ return EXIT_FAILURE;
+ }
+
{
static char conf[256];
snprintf (conf, sizeof (conf), "%s/.usmb.conf", getenv ("HOME"));
@@ -269,6 +275,8 @@ int main (int argc, char **argv)
if (!parse_args (&argc, &argv, &mountid, &conffile))
return EXIT_FAILURE;
+ show_about (stdout);
+
if (!check_conf_perms (conffile) ||
!conffile_get_mount (conffile, mountid,
&server, &sharename, &mountpoint, &options,
@@ -283,7 +291,6 @@ int main (int argc, char **argv)
}
DEBUG (fprintf (stderr, "Username: %s\\%s\n", domain, username));
- show_about (stdout);
int fuse_argc;
char **fuse_argv;
(DIR) diff --git a/usmb.h b/usmb.h
@@ -21,18 +21,19 @@
extern SMBCCTX *ctx;
- char * make_url (const char *path);
+ char * make_url (const char *path) MUSTCHECK;
- static inline int smbcfile_to_fd (SMBCFILE *file)
+ /* fuse_file_info uses a uint64_t for a "File handle" */
+ static inline uint64_t smbcfile_to_fd (SMBCFILE *file)
{
- return (NULL == file) ? -1 : (int)file;
+ return (uint64_t)(uintptr_t)file;
}
- static inline SMBCFILE * fd_to_smbcfile (int fd)
+ static inline SMBCFILE * fd_to_smbcfile (uint64_t fd)
{
- return (SMBCFILE *)fd;
+ return (SMBCFILE *)(uintptr_t)fd;
}
#endif
(DIR) diff --git a/utils.c b/utils.c
@@ -108,3 +108,15 @@ void xfree (const void *ptr)
free ((void *)ptr);
}
+
+void clear_and_free (char *ptr)
+{
+ if (NULL != ptr)
+ {
+ for (char *pch = ptr; '\0' != *pch; ++pch)
+ *pch = '\0';
+
+ free (ptr);
+ }
+}
+
(DIR) diff --git a/utils.h b/utils.h
@@ -25,8 +25,9 @@
#define DEBUG(x) ((void)0)
#endif
- char * concat_strings (int num, ...);
- char * xstrdup (const char *in);
+ char * concat_strings (int num, ...) MUSTCHECK;
+ char * xstrdup (const char *in) MUSTCHECK;
void xfree (const void *ptr);
+ void clear_and_free (char *ptr);
#endif
(DIR) diff --git a/version.h b/version.h
@@ -19,7 +19,7 @@
#include <stdio.h>
- #define USMB_VERSION 0x20080421
+ #define USMB_VERSION 0x20080530
// a - alpha, b - beta, p - pre-release, s - stable
#define USMB_VERSION_STATUS 's'
(DIR) diff --git a/xml.h b/xml.h
@@ -23,11 +23,12 @@
#include <stdbool.h>
- bool xml_validate_relaxng (xmlDocPtr doc, const char *schema);
+ bool xml_validate_relaxng (xmlDocPtr doc, const char *schema) MUSTCHECK;
bool xml_xpath_attr_value (xmlXPathContextPtr ctx,
char *xpath,
const char *attribute,
- char **out);
- bool xml_xpath_text (xmlXPathContextPtr ctx, char *xpath, char **out);
+ char **out) MUSTCHECK;
+ bool xml_xpath_text (xmlXPathContextPtr ctx,
+ char *xpath, char **out) MUSTCHECK;
#endif