Diff for /embedaddon/rsync/authenticate.c between versions 1.1.1.2 and 1.1.1.3

version 1.1.1.2, 2013/10/14 07:51:14 version 1.1.1.3, 2016/11/01 09:54:32
Line 2 Line 2
  * Support rsync daemon authentication.   * Support rsync daemon authentication.
  *   *
  * Copyright (C) 1998-2000 Andrew Tridgell   * Copyright (C) 1998-2000 Andrew Tridgell
 * Copyright (C) 2002-2013 Wayne Davison * Copyright (C) 2002-2015 Wayne Davison
  *   *
  * This program is free software; you can redistribute it and/or modify   * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by   * it under the terms of the GNU General Public License as published by
Line 102  static const char *check_secret(int module, const char Line 102  static const char *check_secret(int module, const char
         char pass2[MAX_DIGEST_LEN*2];          char pass2[MAX_DIGEST_LEN*2];
         const char *fname = lp_secrets_file(module);          const char *fname = lp_secrets_file(module);
         STRUCT_STAT st;          STRUCT_STAT st;
        int fd, ok = 1;        int ok = 1;
         int user_len = strlen(user);          int user_len = strlen(user);
         int group_len = group ? strlen(group) : 0;          int group_len = group ? strlen(group) : 0;
         char *err;          char *err;
           FILE *fh;
   
        if (!fname || !*fname || (fd = open(fname, O_RDONLY)) < 0)        if (!fname || !*fname || (fh = fopen(fname, "r")) == NULL)
                 return "no secrets file";                  return "no secrets file";
   
        if (do_fstat(fd, &st) == -1) {        if (do_fstat(fileno(fh), &st) == -1) {
                 rsyserr(FLOG, errno, "fstat(%s)", fname);                  rsyserr(FLOG, errno, "fstat(%s)", fname);
                 ok = 0;                  ok = 0;
         } else if (lp_strict_modes(module)) {          } else if (lp_strict_modes(module)) {
Line 123  static const char *check_secret(int module, const char Line 124  static const char *check_secret(int module, const char
                 }                  }
         }          }
         if (!ok) {          if (!ok) {
                close(fd);                fclose(fh);
                 return "ignoring secrets file";                  return "ignoring secrets file";
         }          }
   
         if (*user == '#') {          if (*user == '#') {
                 /* Reject attempt to match a comment. */                  /* Reject attempt to match a comment. */
                close(fd);                fclose(fh);
                 return "invalid username";                  return "invalid username";
         }          }
   
         /* Try to find a line that starts with the user (or @group) name and a ':'. */          /* Try to find a line that starts with the user (or @group) name and a ':'. */
         err = "secret not found";          err = "secret not found";
        while ((user || group) && read_line_old(fd, line, sizeof line, 1)) {        while ((user || group) && fgets(line, sizeof line, fh) != NULL) {
                const char **ptr, *s;                const char **ptr, *s = strtok(line, "\n\r");
                 int len;                  int len;
                if (*line == '@') {                if (!s)
                         continue;
                 if (*s == '@') {
                         ptr = &group;                          ptr = &group;
                         len = group_len;                          len = group_len;
                        s = line+1;                        s++;
                 } else {                  } else {
                         ptr = &user;                          ptr = &user;
                         len = user_len;                          len = user_len;
                         s = line;  
                 }                  }
                 if (!*ptr || strncmp(s, *ptr, len) != 0 || s[len] != ':')                  if (!*ptr || strncmp(s, *ptr, len) != 0 || s[len] != ':')
                         continue;                          continue;
Line 158  static const char *check_secret(int module, const char Line 160  static const char *check_secret(int module, const char
                 *ptr = NULL; /* Don't look for name again. */                  *ptr = NULL; /* Don't look for name again. */
         }          }
   
        close(fd);        fclose(fh);
   
         memset(line, 0, sizeof line);          memset(line, 0, sizeof line);
         memset(pass2, 0, sizeof pass2);          memset(pass2, 0, sizeof pass2);
Line 277  char *auth_server(int f_in, int f_out, int module, con Line 279  char *auth_server(int f_in, int f_out, int module, con
                         /* See if authorizing user is a real user, and if so, see                          /* See if authorizing user is a real user, and if so, see
                          * if it is in a group that matches tok+1 wildmat. */                           * if it is in a group that matches tok+1 wildmat. */
                         if (auth_uid_groups_cnt < 0) {                          if (auth_uid_groups_cnt < 0) {
                                gid_t gid_list[64];                                item_list gid_list = EMPTY_ITEM_LIST;
                                 uid_t auth_uid;                                  uid_t auth_uid;
                                 auth_uid_groups_cnt = sizeof gid_list / sizeof (gid_t);  
                                 if (!user_to_uid(line, &auth_uid, False)                                  if (!user_to_uid(line, &auth_uid, False)
                                 || getallgroups(auth_uid, gid_list, &auth_uid_groups_cnt) != NULL)                                 || getallgroups(auth_uid, &gid_list) != NULL)
                                         auth_uid_groups_cnt = 0;                                          auth_uid_groups_cnt = 0;
                                 else {                                  else {
                                           gid_t *gid_array = gid_list.items;
                                           auth_uid_groups_cnt = gid_list.count;
                                         if ((auth_uid_groups = new_array(char *, auth_uid_groups_cnt)) == NULL)                                          if ((auth_uid_groups = new_array(char *, auth_uid_groups_cnt)) == NULL)
                                                 out_of_memory("auth_server");                                                  out_of_memory("auth_server");
                                         for (j = 0; j < auth_uid_groups_cnt; j++)                                          for (j = 0; j < auth_uid_groups_cnt; j++)
                                                auth_uid_groups[j] = gid_to_group(gid_list[j]);                                                auth_uid_groups[j] = gid_to_group(gid_array[j]);
                                 }                                  }
                         }                          }
                         for (j = 0; j < auth_uid_groups_cnt; j++) {                          for (j = 0; j < auth_uid_groups_cnt; j++) {

Removed from v.1.1.1.2  
changed lines
  Added in v.1.1.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>