如何在 macports=2.1.2 xcode-4.5.2 gcc47 的现代 mac osx 10.7 或 10.8 系统上编译 pam_radius_auth (http://freeradius.org/pam_radius_auth/)。
我收到很多错误,包括但不限于:
pam_radius_auth.c:358:23: 错误: 变量的类型不完整 'struct timezone' struct timezone tz;
如何在 macports=2.1.2 xcode-4.5.2 gcc47 的现代 mac osx 10.7 或 10.8 系统上编译 pam_radius_auth (http://freeradius.org/pam_radius_auth/)。
我收到很多错误,包括但不限于:
pam_radius_auth.c:358:23: 错误: 变量的类型不完整 'struct timezone' struct timezone tz;
该代码相当旧(最新修改为 2007 年)。就其本身而言,这不一定是个问题。
gettimeofday()
通过包含#include <sys/time.h>
每个 POSIX来解决“结构时区”问题。
pam_get_item()
通过注释掉周围的#ifdef sun
和#endif
保护来解决未声明 etc的问题#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.
$
我只有要编译的代码;我没有测试它!