| 1 | # ProFTPD 1.3.x on AIX |
| 2 | |
| 3 | There are two issues when compiling on AIX systems that can be worked around |
| 4 | using the proper configure command lines. |
| 5 | |
| 6 | One problem involves the less than optimal default shared object search path |
| 7 | that the IBM linker inserts into executables. The second problem is |
| 8 | compilaton failure stemming from an incompatibility with the `<string.h>` |
| 9 | header file when the IBM compiler attempts to inline some string functions. |
| 10 | |
| 11 | Also, a minor usage note: do _not_ use the `--enable-autoshadow` or |
| 12 | `--enable-shadow` configure options when configuring ProFTPD for AIX. AIX |
| 13 | does not use the shadow libraries. |
| 14 | |
| 15 | ## Executive Summary |
| 16 | |
| 17 | If you are using the IBM `xlc/cc` compiler with the IBM `ld` linker: |
| 18 | ```sh |
| 19 | env CC=cc \ |
| 20 | CFLAGS='-D_NO_PROTO' \ |
| 21 | LDFLAGS='-blibpath:/usr/lib:/lib:/usr/local/lib' \ |
| 22 | ./configure ... |
| 23 | ``` |
| 24 | If you are using the GNU `gcc` compiler with the IBM `ld` linker: |
| 25 | ```sh |
| 26 | env CC=gcc \ |
| 27 | LDFLAGS='-Wl,-blibpath:/usr/lib:/lib:/usr/local/lib' \ |
| 28 | ./configure ... |
| 29 | ``` |
| 30 | |
| 31 | If you are using the GNU `gcc` compiler with the GNU `ld` linker, something |
| 32 | like this ought to work (untested): |
| 33 | ```sh |
| 34 | env CC=gcc \ |
| 35 | LDFLAGS='-Wl,-rpath,/usr/lib,-rpath,/lib,-rpath,/usr/local/lib' \ |
| 36 | ./configure ... |
| 37 | ``` |
| 38 | |
| 39 | Note that the library paths shown here are for example use only. You may need |
| 40 | to use different paths on your system, particularly when linking with any |
| 41 | optional libraries (_e.g._ krb5, ldap, mysql, _etc._). |
| 42 | |
| 43 | ## Compiling with the GNU compiler |
| 44 | |
| 45 | It is recommend that `gcc-3.3.2` _not_ be used when compiling ProFTPD on AIX. |
| 46 | There were problems reported of session processes going into endless loops. |
| 47 | Using `gcc-4.1.0` or later should work properly. |
| 48 | |
| 49 | ## Linking with the IBM or GNU linker |
| 50 | |
| 51 | There is a potential security problem when using the IBM linker. Unlike other |
| 52 | Unix systems, by default the IBM linker automatically will use the compile-time |
| 53 | library search path as the runtime shared library search path. The use of |
| 54 | relative paths in the runtime library search path is an especially acute |
| 55 | security problem for _suid_ or _sgid_ programs. |
| 56 | |
| 57 | This default behavior is documented, so it is not considered a bug by IBM. |
| 58 | However, some _suid_ programs that have shipped with AIX have included insecure |
| 59 | library search paths and are vulnerable to privilege elevation exploits. |
| 60 | |
| 61 | This may not be such a serious a security problem for ProFTPD, since it is not |
| 62 | installed _suid_ or _sgid_. Nonetheless, it is wise to configure the |
| 63 | runtime shared library search path with a reasonable setting. For instance, |
| 64 | consider potential problems from searching NFS mounted directories. |
| 65 | |
| 66 | An existing AIX executable's library search path can be displayed: |
| 67 | ```sh |
| 68 | dump -H progname |
| 69 | ``` |
| 70 | |
| 71 | The runtime library search patch should be specified explicitly at build time |
| 72 | using the `-blibpath` option: |
| 73 | ```sh |
| 74 | cc -blibpath:/usr/lib:/lib:/usr/local/lib |
| 75 | |
| 76 | gcc -Wl,-blibpath:/usr/lib:/lib:/usr/local/lib |
| 77 | ``` |
| 78 | |
| 79 | See the `ld` documentation, not just that of `xlc/cc`, for further information |
| 80 | on the IBM linker flags. Alternatively, an insecure library search path can be |
| 81 | avoided using `-bnolibpath`, which causes the default path to be used (either |
| 82 | the value of the `LIBPATH` environment variable, if defined, or |
| 83 | `/usr/lib:/lib`, if not). |
| 84 | |
| 85 | It has been reported that at least some versions of GNU `ld` (_e.g._ 2.9.1) |
| 86 | have emulated this default linking behavior on AIX platforms. However, GNU |
| 87 | `ld` uses `-rpath` to set the runtime library search path, rather than the IBM |
| 88 | `ld -blibpath` or the Sun `ld -R` options: |
| 89 | ```sh |
| 90 | gcc -Wl,-rpath,/usr/lib,-rpath,/lib,-rpath,/usr/local/lib |
| 91 | ``` |
| 92 | |
| 93 | Again, consult the GNU `ld` documentation for further information. Note that |
| 94 | using the `gcc` compiler does not imply that it uses the GNU `ld` linker. In |
| 95 | fact, it is more common to use the IBM system linker. |
| 96 | |
| 97 | The upshot of all this is that you should tell `configure` what to use for the |
| 98 | runtime shared library search path. This can be done by setting `LDFLAGS` on |
| 99 | the `configure` command line, possibly like this: |
| 100 | ```sh |
| 101 | env CC=cc \ |
| 102 | LDFLAGS='-blibpath:/usr/lib:/lib:/usr/local/lib' \ |
| 103 | ./configure ... |
| 104 | |
| 105 | env CC=gcc \ |
| 106 | LDFLAGS='-Wl,-blibpath:/usr/lib:/lib:/usr/local/lib' \ |
| 107 | ./configure ... |
| 108 | ``` |
| 109 | |
| 110 | In addition to setting the runtime library search path during the original |
| 111 | software build, the IBM linker can relink an existing _unstripped_ executable |
| 112 | using a new runtime library search path: |
| 113 | ```sh |
| 114 | cc -blibpath:/usr/lib:/lib:/usr/local/lib -lm -ldl \ |
| 115 | -o progname.new progname |
| 116 | |
| 117 | gcc -Wl,-blibpath:/usr/lib:/lib:/usr/local/lib -lm -ldl \ |
| 118 | -o progname.new progname |
| 119 | ``` |
| 120 | where the `-l` options refer to shared libraries, which can be determined from |
| 121 | the output of: |
| 122 | ```sh |
| 123 | dump -Hv progname |
| 124 | ``` |
| 125 | which displays shared library information. A basic `proftpd` executable |
| 126 | probably will not require any `-l` options at all. |
| 127 | |
| 128 | ## Compiling with the IBM xlc/cc compiler |
| 129 | |
| 130 | There is a problem with the `index` and `rindex` macros defined in |
| 131 | `<string.h>`. Apparently, these are used as part of an attempt to inline |
| 132 | string functions when the `__STR__` C preprocessor macro is defined. Conflicts |
| 133 | with these definitions will cause compilation failures. |
| 134 | |
| 135 | The work-around is to undefine the `__STR__` C preprocessor macro, which is |
| 136 | predefined by the IBM compiler. This can be done on the `configure` command |
| 137 | line by adding `-U__STR__` to the `CPPFLAGS` variable: |
| 138 | ```sh |
| 139 | env CC=cc CPPFLAGS='-U__STR__' ./configure ... |
| 140 | ``` |
| 141 | |
| 142 | However, with newer versions of ProFTPD, it has been found that the following |
| 143 | combination works better when compiling: |
| 144 | ```sh |
| 145 | env CC=cc CFLAGS='-D_NO_PROTO' ./configure ... |
| 146 | ``` |
| 147 | |
| 148 | ## Sendfile support in AIX |
| 149 | |
| 150 | It appears that the `sendfile(2)` function in AIX 5.3 (specifically AIX |
| 151 | 5300-04-02) is faulty. If you are running ProFTPD 1.3.0 or later on AIX, |
| 152 | place the following in your `proftpd.conf`: |
| 153 | ```text |
| 154 | UseSendfile off |
| 155 | ``` |
| 156 | Failure to do so can result in downloads of files that end up being the wrong |
| 157 | size (downloaded files being far too large, _etc_). |