Import Debian changes 1.2.2-1
[quagga-debian.git] / debian / patches / 0002-80_vtysh__vtysh.c__privs.patch
1 From: Debian QA Group <packages@qa.debian.org>
2 Date: Sat, 12 Nov 2016 01:16:08 +1100
3 Subject: 80_vtysh__vtysh.c__privs
4
5 ---
6  vtysh/vtysh.c | 20 ++++++++++++++++++++
7  1 file changed, 20 insertions(+)
8
9 diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c
10 index 9a8aedd..d182363 100644
11 --- a/vtysh/vtysh.c
12 +++ b/vtysh/vtysh.c
13 @@ -26,6 +26,8 @@
14  #include <sys/wait.h>
15  #include <sys/resource.h>
16  #include <sys/stat.h>
17 +#include <sys/types.h>
18 +#include <grp.h>
19  
20  #include <readline/readline.h>
21  #include <readline/history.h>
22 @@ -2101,6 +2103,9 @@ write_config_integrated(void)
23    FILE *fp;
24    char *integrate_sav = NULL;
25  
26 +  /* Setting file permissions */
27 +  struct group *quagga_vty_group;
28 +
29    integrate_sav = malloc (strlen (integrate_default) +
30                           strlen (CONF_BACKUP_EXT) + 1);
31    strcpy (integrate_sav, integrate_default);
32 @@ -2128,6 +2133,21 @@ write_config_integrated(void)
33    vtysh_config_dump (fp);
34  
35    fclose (fp);
36 +       
37 +  errno = 0;
38 +  if ((quagga_vty_group = getgrnam(VTY_GROUP)) == NULL) 
39 +    {
40 +      fprintf (stdout, "%% Can't get group %s: %s (%d)\n",
41 +        VTY_GROUP, strerror(errno), errno);
42 +      return CMD_WARNING;
43 +    }    
44 +
45 +  if ((chown(integrate_default, -1, quagga_vty_group->gr_gid)) != 0)
46 +    {
47 +      fprintf (stdout,"%% Can't chown configuration file %s: %s (%d)\n", 
48 +       integrate_default, strerror(errno), errno);
49 +      return CMD_WARNING;
50 +    }
51  
52    if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
53      {