如何在现代mac osx 10.7或10.8系统上使用macports = 2.1.2 xcode-4.5.2 gcc47编译pam_radius_auth(http://freeradius.org/pam_radius_auth/)。
我收到很多错误,包括但不限于:
pam_radius_auth.c:358:23:错误:变量的类型'struct timezone'不完整 struct timezone tz;
答案 0 :(得分:1)
代码相当陈旧(2007年的最新修改)。就其本身而言,这不一定是个问题。
gettimeofday()
的'struct timezone'问题通过在每个POSIX中加入#include <sys/time.h>
来解决。
通过在pam_get_item()
周围发表#ifdef sun
和#endif
保护,可以修复#include <security/pam_appl.h>
等未声明的问题。
pam_radius_auth.c:886:24: warning: passing 'int *' to parameter of type 'socklen_t *' (aka 'unsigned int *') converts
between pointers to integer types with different sign [-Wpointer-sign]
0, &saremote, &salen)) < 0) {
^~~~~~
/usr/include/sys/socket.h:615:25: note: passing argument to parameter here
socklen_t * __restrict) __DARWIN_ALIAS_C(recvfrom);
可以通过更改:
来解决int salen, total_length;
为:
int total_length;
socklen_t salen;
问题:
pam_radius_auth.c:1104:12: warning: incompatible pointer types assigning to 'const char *' from
'const char **'dereference with * [-Wincompatible-pointer-types]
user = userinfo;
可以通过将行更改为:
来解决user = *userinfo;
问题:
md5.c:176:27: warning: 'memset' call operates on objects of type 'struct MD5Context' while the size is based on a
different type 'struct MD5Context *' [-Wsizeof-pointer-memaccess]
memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
~~~ ^~~
md5.c:176:27: note: did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)?
memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
可以通过将行更改为:
来修复 memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
(这是一个令人印象深刻的警告!)
随着这些变化:
$ make
cc -Wall -fPIC -c pam_radius_auth.c -o pam_radius_auth.o
cc -Wall -fPIC -c -o md5.o md5.c
ld -Bshareable pam_radius_auth.o md5.o -lpam -o pam_radius_auth.so
ld: unknown option: -Bshareable
make: *** [pam_radius_auth.so] Error 1
$
makefile指出更多现代版本的GCC支持-shared
(但猜测ld -Bshareable
适用于大多数地方)。那么,让我们试试:
$ cc -shared -o pam_radius_auth.so *.o -lpam
$
--- pam_radius-1.3.17/Makefile 2007-03-25 21:22:11.000000000 -0700
+++ pam_radius-1.3.17.fixed/Makefile 2012-12-07 20:26:17.000000000 -0800
@@ -55,7 +55,8 @@
# gcc -shared pam_radius_auth.o md5.o -lpam -lc -o pam_radius_auth.so
#
pam_radius_auth.so: pam_radius_auth.o md5.o
- ld -Bshareable pam_radius_auth.o md5.o -lpam -o pam_radius_auth.so
+ gcc -shared pam_radius_auth.o md5.o -lpam -lc -o pam_radius_auth.so
+# ld -Bshareable pam_radius_auth.o md5.o -lpam -o pam_radius_auth.so
######################################################################
#
--- pam_radius-1.3.17/md5.c 2007-03-25 21:21:07.000000000 -0700
+++ pam_radius-1.3.17.fixed/md5.c 2012-12-07 20:11:17.000000000 -0800
@@ -173,7 +173,8 @@
MD5Transform(ctx->buf, (uint32_t *) ctx->in);
byteReverse((unsigned char *) ctx->buf, 4);
memcpy(digest, ctx->buf, 16);
- memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
+ //memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
+ memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
}
#ifndef ASM_MD5
--- pam_radius-1.3.17/pam_radius_auth.c 2007-03-26 02:36:13.000000000 -0700
+++ pam_radius-1.3.17.fixed/pam_radius_auth.c 2012-12-07 20:13:21.000000000 -0800
@@ -57,9 +57,9 @@
#include <limits.h>
#include <errno.h>
-#ifdef sun
+//#ifdef sun
#include <security/pam_appl.h>
-#endif
+//#endif
#include <security/pam_modules.h>
#include "pam_radius_auth.h"
@@ -766,7 +766,9 @@
talk_radius(radius_conf_t *conf, AUTH_HDR *request, AUTH_HDR *response,
char *password, char *old_password, int tries)
{
- int salen, total_length;
+ //int salen, total_length;
+ socklen_t salen;
+ int total_length;
fd_set set;
struct timeval tv;
time_t now, end;
@@ -1099,7 +1101,7 @@
DPRINT(LOG_DEBUG, "Got PAM_RUSER name %s", userinfo);
if (!strcmp("root", user)) {
- user = userinfo;
+ user = *userinfo;
DPRINT(LOG_DEBUG, "Username now %s from ruser", user);
} else {
DPRINT(LOG_DEBUG, "Skipping ruser for non-root auth");
--- pam_radius-1.3.17/pam_radius_auth.h 2007-03-25 22:35:31.000000000 -0700
+++ pam_radius-1.3.17.fixed/pam_radius_auth.h 2012-12-07 20:07:34.000000000 -0800
@@ -15,6 +15,7 @@
#include <stdarg.h>
#include <utmp.h>
#include <time.h>
+#include <sys/time.h>
#include <netinet/in.h>
#include <netdb.h>
#include <fcntl.h>
将补丁保存为pam_radius.patch
。将源提取到子目录pam_radius-1.3.17
。使用以下方法应用补丁:
$ cd pam_radius-1.3.17
$ patch -p1 --dry-run -i ../pam_radius.patch --verbose
Hmm... Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|--- pam_radius-1.3.17/Makefile 2007-03-25 21:22:11.000000000 -0700
|+++ pam_radius-1.3.17.fixed/Makefile 2012-12-07 20:26:17.000000000 -0800
--------------------------
Patching file Makefile using Plan A...
Hunk #1 succeeded at 55.
Hmm... The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|--- pam_radius-1.3.17/md5.c 2007-03-25 21:21:07.000000000 -0700
|+++ pam_radius-1.3.17.fixed/md5.c 2012-12-07 20:11:17.000000000 -0800
--------------------------
Patching file md5.c using Plan A...
Hunk #1 succeeded at 173.
Hmm... The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|--- pam_radius-1.3.17/pam_radius_auth.c 2007-03-26 02:36:13.000000000 -0700
|+++ pam_radius-1.3.17.fixed/pam_radius_auth.c 2012-12-07 20:13:21.000000000 -0800
--------------------------
Patching file pam_radius_auth.c using Plan A...
Hunk #1 succeeded at 57.
Hunk #2 succeeded at 766.
Hunk #3 succeeded at 1101.
Hmm... The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|--- pam_radius-1.3.17/pam_radius_auth.h 2007-03-25 22:35:31.000000000 -0700
|+++ pam_radius-1.3.17.fixed/pam_radius_auth.h 2012-12-07 20:07:34.000000000 -0800
--------------------------
Patching file pam_radius_auth.h using Plan A...
Hunk #1 succeeded at 15.
done
$
这是一个干涸的;删除该选项以实际应用补丁。
使用以下方法在Mac OS X 10.7.5上测试:
$ cc --version
Apple clang version 4.1 (tags/Apple/clang-421.11.65) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.2
Thread model: posix
$
使用GCC 4.7.1编译时,我收到一个残留警告:
$ make CC=gcc
gcc -Wall -fPIC -c pam_radius_auth.c -o pam_radius_auth.o
pam_radius_auth.c: In function ‘pam_private_session’:
pam_radius_auth.c:1290:7: warning: variable ‘ctrl’ set but not used [-Wunused-but-set-variable]
gcc -Wall -fPIC -c -o md5.o md5.c
gcc -shared pam_radius_auth.o md5.o -lpam -lc -o pam_radius_auth.so
$ gcc --version
gcc (GCC) 4.7.1
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$
我只有编译的代码;我没有测试它!