uhttpd: make it work without shadow password support
authorJo-Philipp Wich <jow@openwrt.org>
Sat, 6 Nov 2010 16:19:04 +0000 (16:19 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sat, 6 Nov 2010 16:19:04 +0000 (16:19 +0000)
SVN-Revision: 23897

package/uhttpd/src/Makefile
package/uhttpd/src/uhttpd-utils.c
package/uhttpd/src/uhttpd-utils.h

index 06d61bdef3b3e7b9d64aa2edb764c8d815ffa247..6dcc3555f196928ab72de7eb498ee6668d868079 100644 (file)
@@ -13,6 +13,12 @@ LIB = -Wl,--export-dynamic -lcrypt -ldl
 TLSLIB =
 LUALIB =
 
+HAVE_SHADOW=$(shell echo 'int main(void){ return !getspnam("root"); }' | \
+       $(CC) -include shadow.h -xc -o/dev/null - 2>/dev/null && echo yes)
+
+ifeq ($(HAVE_SHADOW),yes)
+  CFLAGS += -DHAVE_SHADOW
+endif
 
 world: compile
 
index 3821eb54cb18df8328d79d583d80d3a0bd7dc4bd..9f9a5dd6a7f4d3dd5cc081d21178d5708f038e00 100644 (file)
@@ -610,7 +610,10 @@ struct auth_realm * uh_auth_add(char *path, char *user, char *pass)
 {
        struct auth_realm *new = NULL;
        struct passwd *pwd;
+
+#ifdef HAVE_SHADOW
        struct spwd *spwd;
+#endif
 
        if((new = (struct auth_realm *)malloc(sizeof(struct auth_realm))) != NULL)
        {
@@ -625,6 +628,7 @@ struct auth_realm * uh_auth_add(char *path, char *user, char *pass)
                /* given password refers to a passwd entry */
                if( (strlen(pass) > 3) && !strncmp(pass, "$p$", 3) )
                {
+#ifdef HAVE_SHADOW
                        /* try to resolve shadow entry */
                        if( ((spwd = getspnam(&pass[3])) != NULL) && spwd->sp_pwdp )
                        {
@@ -632,8 +636,11 @@ struct auth_realm * uh_auth_add(char *path, char *user, char *pass)
                                        min(strlen(spwd->sp_pwdp), sizeof(new->pass) - 1));
                        }
 
+                       else
+#endif
+
                        /* try to resolve passwd entry */
-                       else if( ((pwd = getpwnam(&pass[3])) != NULL) && pwd->pw_passwd &&
+                       if( ((pwd = getpwnam(&pass[3])) != NULL) && pwd->pw_passwd &&
                                (pwd->pw_passwd[0] != '!') && (pwd->pw_passwd[0] != 0)
                        ) {
                                memcpy(new->pass, pwd->pw_passwd,
index 3514ce1caca730337caf04a926de0f212b5ac01a..6a0a395a9130c0bb89e932f64a54a8cd5ddf143a 100644 (file)
 #include <stdarg.h>
 #include <fcntl.h>
 #include <pwd.h>
-#include <shadow.h>
 #include <sys/stat.h>
 
+#ifdef HAVE_SHADOW
+#include <shadow.h>
+#endif
+
 #define min(x, y) (((x) < (y)) ? (x) : (y))
 #define max(x, y) (((x) > (y)) ? (x) : (y))