c - 如何在 mac 10.7 和/或 10.8 上编译 pam_radius

标签 c

如何使用 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”不完整 结构体时区tz;

最佳答案

该代码相当旧(最新修改为 2007 年)。就其本身而言,这不一定是问题。

gettimeofday() 的“结构时区”问题通过包含 #include <sys/time.h> 来修复按照 POSIX。

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.
$

警告

我只得到了要编译的代码;我没有测试过!

关于c - 如何在 mac 10.7 和/或 10.8 上编译 pam_radius,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13772655/

相关文章:

c - 堆栈 - 计算 C 中的后缀表达式

c - 初学c,工程不编译?

c - 我尝试通过创建一个 int 来切换一个特定的结构,但找不到错误

c - 在循环链表的开头插入

c - vector 的长度,初学者

c - 伯克利数据库 - 重复条目段错误

c - "Macros for minimum-width integer constants"的目的是什么

c - 在 D 中使用 apr_array_push 追加数组

c - 标准 C 是否接受 `{0}` 作为任何结构的初始值设定项?

c - C语言中的if-else条件