openssh.patch.alias 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. Index: servconf.c
  2. --- servconf.c.orig Fri Jan 23 12:03:10 2004
  3. +++ servconf.c Fri Mar 12 12:28:21 2004
  4. @@ -101,6 +101,9 @@
  5. options->client_alive_count_max = -1;
  6. options->authorized_keys_file = NULL;
  7. options->authorized_keys_file2 = NULL;
  8. +#ifdef USE_ALIAS
  9. + options->num_alias = 0;
  10. +#endif
  11. /* Needs to be accessable in many places */
  12. use_privsep = -1;
  13. @@ -268,6 +271,9 @@
  14. sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
  15. sGssAuthentication, sGssCleanupCreds,
  16. sUsePrivilegeSeparation,
  17. +#ifdef USE_ALIAS
  18. + sAlias,
  19. +#endif
  20. sDeprecated, sUnsupported
  21. } ServerOpCodes;
  22. @@ -366,6 +372,9 @@
  23. { "authorizedkeysfile", sAuthorizedKeysFile },
  24. { "authorizedkeysfile2", sAuthorizedKeysFile2 },
  25. { "useprivilegeseparation", sUsePrivilegeSeparation},
  26. +#ifdef USE_ALIAS
  27. + { "alias", sAlias },
  28. +#endif
  29. { NULL, sBadOption }
  30. };
  31. @@ -898,6 +907,26 @@
  32. while (arg)
  33. arg = strdelim(&cp);
  34. break;
  35. +
  36. +#ifdef USE_ALIAS
  37. + case sAlias:
  38. + if (options->num_alias >= MAX_ALIAS) {
  39. + fatal("%s line %d: too many user alias defined.",
  40. + filename, linenum);
  41. + }
  42. + arg = strdelim(&cp);
  43. + if (arg == NULL || arg[0] == '\0')
  44. + fatal("%s line %d: missing user name alias(es).",
  45. + filename, linenum);
  46. + options->alias[options->num_alias].alias = xstrdup(arg);
  47. + arg = strdelim(&cp);
  48. + if (arg == NULL || arg[0] == '\0')
  49. + fatal("%s line %d: missing user name to map alias '%s' to.",
  50. + filename, linenum, options->alias[options->num_alias].alias);
  51. + options->alias[options->num_alias].user = xstrdup(arg);
  52. + options->num_alias++;
  53. + break;
  54. +#endif
  55. case sUnsupported:
  56. logit("%s line %d: Unsupported option %s",
  57. Index: servconf.h
  58. --- servconf.h.orig Wed Dec 31 01:37:34 2003
  59. +++ servconf.h Fri Mar 12 11:36:15 2004
  60. @@ -125,6 +125,14 @@
  61. char *authorized_keys_file; /* File containing public keys */
  62. char *authorized_keys_file2;
  63. int use_pam; /* Enable auth via PAM */
  64. +#ifdef USE_ALIAS
  65. +#define MAX_ALIAS 256
  66. + u_int num_alias;
  67. + struct {
  68. + char *alias; /* the alias list to match */
  69. + char *user; /* the username to map to */
  70. + } alias[MAX_ALIAS];
  71. +#endif
  72. } ServerOptions;
  73. void initialize_server_options(ServerOptions *);
  74. Index: auth1.c
  75. --- auth1.c.orig Sat Nov 22 04:15:30 2003
  76. +++ auth1.c Fri Mar 12 12:30:48 2004
  77. @@ -26,6 +26,9 @@
  78. #include "session.h"
  79. #include "uidswap.h"
  80. #include "monitor_wrap.h"
  81. +#ifdef USE_ALIAS
  82. +#include "match.h"
  83. +#endif
  84. /* import */
  85. extern ServerOptions options;
  86. @@ -280,6 +283,10 @@
  87. {
  88. u_int ulen;
  89. char *user, *style = NULL;
  90. +#ifdef USE_ALIAS
  91. + int i, n;
  92. + char *cp;
  93. +#endif
  94. /* Get the name of the user that we wish to log in as. */
  95. packet_read_expect(SSH_CMSG_USER);
  96. @@ -290,6 +297,25 @@
  97. if ((style = strchr(user, ':')) != NULL)
  98. *style++ = '\0';
  99. +
  100. +#ifdef USE_ALIAS
  101. + for (i = 0; i < options.num_alias; i++) {
  102. + if (match_pattern_list(user, options.alias[i].alias, strlen(options.alias[i].alias), 0) == 1) {
  103. + if (style != NULL) {
  104. + n = strlen(options.alias[i].user) + 1 + strlen(style) + 1;
  105. + cp = xmalloc(n);
  106. + snprintf(cp, n, "%s:%s", options.alias[i].user, style);
  107. + style = strchr(cp, ':');
  108. + *style++ = '\0';
  109. + }
  110. + else
  111. + cp = xstrdup(options.alias[i].user);
  112. + xfree(user);
  113. + user = cp;
  114. + break;
  115. + }
  116. + }
  117. +#endif
  118. authctxt->user = user;
  119. authctxt->style = style;
  120. Index: auth2.c
  121. --- auth2.c.orig Mon Nov 17 11:13:41 2003
  122. +++ auth2.c Fri Mar 12 12:30:48 2004
  123. @@ -35,6 +35,9 @@
  124. #include "dispatch.h"
  125. #include "pathnames.h"
  126. #include "monitor_wrap.h"
  127. +#ifdef USE_ALIAS
  128. +#include "match.h"
  129. +#endif
  130. #ifdef GSSAPI
  131. #include "ssh-gss.h"
  132. @@ -134,6 +137,10 @@
  133. Authmethod *m = NULL;
  134. char *user, *service, *method, *style = NULL;
  135. int authenticated = 0;
  136. +#ifdef USE_ALIAS
  137. + int i, n;
  138. + char *cp;
  139. +#endif
  140. if (authctxt == NULL)
  141. fatal("input_userauth_request: no authctxt");
  142. @@ -146,6 +153,25 @@
  143. if ((style = strchr(user, ':')) != NULL)
  144. *style++ = 0;
  145. +
  146. +#ifdef USE_ALIAS
  147. + for (i = 0; i < options.num_alias; i++) {
  148. + if (match_pattern_list(user, options.alias[i].alias, strlen(options.alias[i].alias), 0) == 1) {
  149. + if (style != NULL) {
  150. + n = strlen(options.alias[i].user) + 1 + strlen(style) + 1;
  151. + cp = xmalloc(n);
  152. + snprintf(cp, n, "%s:%s", options.alias[i].user, style);
  153. + style = strchr(cp, ':');
  154. + *style++ = '\0';
  155. + }
  156. + else
  157. + cp = xstrdup(options.alias[i].user);
  158. + xfree(user);
  159. + user = cp;
  160. + break;
  161. + }
  162. + }
  163. +#endif
  164. if (authctxt->attempt++ == 0) {
  165. /* setup auth context */
  166. Index: sshd_config.5
  167. --- sshd_config.5.orig Wed Feb 18 04:31:24 2004
  168. +++ sshd_config.5 Fri Mar 12 11:44:55 2004
  169. @@ -61,6 +61,16 @@
  170. keywords and their meanings are as follows (note that
  171. keywords are case-insensitive and arguments are case-sensitive):
  172. .Bl -tag -width Ds
  173. +.It Cm Alias
  174. +Specifies an optional mapping of a list of user name aliases onto
  175. +real user names. The first argument is a comma separated list of
  176. +user name aliases (optionally prefixed with '!' for negation) to
  177. +match. The characters `*' and `?' can be used as wildcards in the
  178. +alias patterns. The second argument is the real user name onto
  179. +which the aliases are mapped. This allows the use of appealing
  180. +virtual login names (like `anonymous') instead of their physical
  181. +counterparts (like `anoncvs').
  182. +.Pp
  183. .It Cm AllowGroups
  184. This keyword can be followed by a list of group name patterns, separated
  185. by spaces.