| 1 | /* |
| 2 | ** Copyright 2004 Double Precision, Inc. See COPYING for |
| 3 | ** distribution information. |
| 4 | */ |
| 5 | |
| 6 | #include "courier_auth_config.h" |
| 7 | #include "auth.h" |
| 8 | #include "pkglibdir.h" |
| 9 | #include "pkgincludedir.h" |
| 10 | #include "authdaemonrc.h" |
| 11 | #include "authldaprc.h" |
| 12 | #include "authmysqlrc.h" |
| 13 | #include "authpgsqlrc.h" |
| 14 | #include "sbindir.h" |
| 15 | #include "mailusergroup.h" |
| 16 | #include "packageversion.h" |
| 17 | |
| 18 | #include <stdio.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <string.h> |
| 21 | #include <pwd.h> |
| 22 | #include <grp.h> |
| 23 | |
| 24 | static const char rcsid[]="$Id: authinfo.c,v 1.11 2005/09/03 20:43:20 mrsam Exp $"; |
| 25 | |
| 26 | static int getmuid() |
| 27 | { |
| 28 | struct passwd *pw=getpwnam(MAILUSER); |
| 29 | |
| 30 | if (pw == NULL) |
| 31 | { |
| 32 | perror("Cannot obtain information for user " MAILUSER); |
| 33 | exit(1); |
| 34 | } |
| 35 | |
| 36 | return (pw->pw_uid); |
| 37 | } |
| 38 | |
| 39 | static int getmgid() |
| 40 | { |
| 41 | struct group *gr=getgrnam(MAILGROUP); |
| 42 | |
| 43 | if (gr == NULL) |
| 44 | { |
| 45 | perror("Cannot obtain information for groupid " MAILGROUP); |
| 46 | exit(1); |
| 47 | } |
| 48 | |
| 49 | return (gr->gr_gid); |
| 50 | } |
| 51 | |
| 52 | static unsigned getver(const char **a) |
| 53 | { |
| 54 | unsigned n=0; |
| 55 | static const char dig[]="0123456789"; |
| 56 | static const char *p; |
| 57 | |
| 58 | while (**a) |
| 59 | { |
| 60 | if (**a == '.') |
| 61 | { |
| 62 | ++*a; |
| 63 | break; |
| 64 | } |
| 65 | |
| 66 | if ((p=strchr(dig, **a)) != NULL) |
| 67 | n=n*10 + p-dig; |
| 68 | |
| 69 | ++*a; |
| 70 | } |
| 71 | return n; |
| 72 | } |
| 73 | |
| 74 | static int versioncmp(const char *a, const char *b) |
| 75 | { |
| 76 | while (*a && *b) |
| 77 | { |
| 78 | unsigned va=getver(&a); |
| 79 | unsigned vb=getver(&b); |
| 80 | |
| 81 | if (va < vb) |
| 82 | return -1; |
| 83 | if (va > vb) |
| 84 | return 1; |
| 85 | } |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | int main(int argc, char **argv) |
| 90 | { |
| 91 | int n; |
| 92 | |
| 93 | for (n=1; n<argc; n++) |
| 94 | { |
| 95 | if (strcmp(argv[n], "--version") == 0) |
| 96 | { |
| 97 | printf("%s\n", PKGVERSION); |
| 98 | } |
| 99 | |
| 100 | if (strncmp(argv[n], "--version=", 10) == 0) |
| 101 | { |
| 102 | printf("%s\n", |
| 103 | versioncmp(argv[n]+10, PKGVERSION) <= 0 |
| 104 | ? "yes":"no"); |
| 105 | } |
| 106 | |
| 107 | if (strcmp(argv[n], "--ldflags") == 0) |
| 108 | { |
| 109 | printf("-L%s\n", |
| 110 | PKGLIBDIR); |
| 111 | } |
| 112 | if (strcmp(argv[n], "--cppflags") == 0) |
| 113 | { |
| 114 | #if HAVE_NOSTDHEADERDIR |
| 115 | printf("-I%s\n", PKGINCLUDEDIR); |
| 116 | #endif |
| 117 | ; |
| 118 | } |
| 119 | if (strcmp(argv[n], "--configfiles") == 0) |
| 120 | { |
| 121 | printf("userdb=%s\n" |
| 122 | "authdaemonrc=%s\n" |
| 123 | "authldaprc=%s\n" |
| 124 | "authmysqlrc=%s\n" |
| 125 | "authpgsqlrc=%s\n" |
| 126 | "mailuser=%s\n" |
| 127 | "mailgroup=%s\n" |
| 128 | "mailuid=%d\n" |
| 129 | "mailgid=%d\n" |
| 130 | "sbindir=%s\n", |
| 131 | USERDB, |
| 132 | AUTHDAEMONRC, |
| 133 | AUTHLDAPRC, |
| 134 | AUTHMYSQLRC, |
| 135 | AUTHPGSQLRC, |
| 136 | MAILUSER, |
| 137 | MAILGROUP, |
| 138 | getmuid(), |
| 139 | getmgid(), |
| 140 | SBINDIR); |
| 141 | } |
| 142 | } |
| 143 | return (0); |
| 144 | } |