Compare commits

...
14 Commits
Author SHA1 Message Date
Mattias WalströmandGitHub 2291e9fd11 Merge pull request #979 from kernelkit/copy-owner
Fix annoying "permission denied" when saving running-config
2025-03-11 16:04:43 +01:00
Richard Alpe 095c9c331e bin: copy: fix return type of in_group()
Signed-off-by: Richard Alpe <richard@bit42.se>
2025-03-11 13:31:55 +01:00
Richard Alpe b8fc8b7f62 bin: copy: fix segfault for one argument
The code assumes both SRC and DST is passed, here we ensure this
early.

Prior to this patch:
root@host:~$ copy foo
Segmentation fault (core dumped)

Signed-off-by: Richard Alpe <richard@bit42.se>
2025-03-11 09:30:46 +01:00
Richard Alpe 95931c8c0a bin: copy: add newline to same-same error message
Signed-off-by: Richard Alpe <richard@bit42.se>
2025-03-11 09:30:19 +01:00
Richard Alpe dd788f5611 bin: copy: save errno in chown error path
Prior to this patch the errno value was overwritten by getgrgid()
making the printouts invalid:

Error: setting group owner wheel (10) on /cfg/startup-config.cfg:
Success

Signed-off-by: Richard Alpe <richard@bit42.se>
2025-03-10 16:18:20 +01:00
Richard Alpe 5d99c12089 bin: copy: use dirname() to derive parent directory
Cosmetic change intended to improve code readability.

Signed-off-by: Richard Alpe <richard@bit42.se>
2025-03-10 16:16:52 +01:00
Richard Alpe 03437fc936 bin: copy: use NGROUPS_MAX when probing user groups
Avoid a theoretical race between getting the number of groups a user
belongs to and actually processing them. We should not need to check
the return value of getgrouplist() as we know the number of groups fit
inside the buffer.

Signed-off-by: Richard Alpe <richard@bit42.se>
2025-03-10 14:52:22 +01:00
Mattias WalströmandGitHub 56a086ef52 Merge pull request #978 from kernelkit/update-kernel
Upgrade kernel to 6.12.18 (LTS)
2025-03-10 10:52:42 +01:00
Mattias Walström 3f3fb4eeb4 Upgrade kernel to 6.12.18 (LTS) 2025-03-09 19:27:12 +01:00
Joachim Wiberg 4998e320c5 doc: update ChangeLog with copy command fix
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-03-09 16:50:27 +01:00
Joachim Wiberg 496d56e975 cli: fix dir command's $HOME when not logged in as root
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-03-09 16:46:30 +01:00
Joachim Wiberg 82df624ae9 cli: show file extension of copy src and dst on tab completion
As per earlier decsision, the .cfg suffix is no longer implied when a
user copy to a regular file, so we should allow tab completion in the
copy command to show foo.cfg, otherwise the copy command will fail.

Skip /cfg/startup-config.cfg since it's treated as a special case and
added to the list by the infix_datastore() plugin function.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-03-09 16:44:41 +01:00
Joachim Wiberg 5021a1da88 bin: copy: set group owner on (new) files
When copying a file to a directory, the file should be accessible (read
+ write) by all members of the group that are allowed write access.

E.g., an 'admin' level user creating a new file /cfg/foo.cfg should
result in the file being owned by $LOGNAME:wheel with 0660 perms,
because /cfg is root:wheel.

Writing to already existing file, e.g., created by 'root' at first boot,
say /cfg/startup-config.cfg should be possible by all members of the
'wheel' group.  In this case thef file already exists as root:wheel and
any user trying to chgrp it will fail, this is fine.

Fixes #977

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-03-09 16:44:23 +01:00
Joachim Wiberg df1fc6f2d7 bin: copy: reduce confusion username vs user -> remote_user
For future readers, the user paramenter to the copy() function is
actually the remote user in any curl command.

Also, realign columns in infix_config[].

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-03-09 16:44:18 +01:00
35 changed files with 138 additions and 57 deletions
+5 -1
View File
@@ -21,7 +21,11 @@ dir()
if [ -d "$1" ]; then
dir "$1"
else
dir "$HOME"
if [ "$USER" = "root" ]; then
dir "$HOME"
else
dir "/home/$USER"
fi
dir "/cfg"
dir "/log"
fi
+1 -1
View File
@@ -27,7 +27,7 @@ BR2_ROOTFS_POST_BUILD_SCRIPT="${BR2_EXTERNAL_INFIX_PATH}/board/common/post-build
BR2_ROOTFS_POST_IMAGE_SCRIPT="${BR2_EXTERNAL_INFIX_PATH}/board/common/post-image.sh"
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.12.17"
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.12.18"
BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="${BR2_EXTERNAL_INFIX_PATH}/board/aarch64/linux_defconfig"
BR2_LINUX_KERNEL_INSTALL_TARGET=y
+1 -1
View File
@@ -27,7 +27,7 @@ BR2_ROOTFS_POST_BUILD_SCRIPT="${BR2_EXTERNAL_INFIX_PATH}/board/common/post-build
BR2_ROOTFS_POST_IMAGE_SCRIPT="${BR2_EXTERNAL_INFIX_PATH}/board/common/post-image.sh"
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.12.17"
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.12.18"
BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="${BR2_EXTERNAL_INFIX_PATH}/board/aarch64/linux_defconfig"
BR2_LINUX_KERNEL_INSTALL_TARGET=y
+1 -1
View File
@@ -26,7 +26,7 @@ BR2_ROOTFS_POST_BUILD_SCRIPT="board/qemu/x86_64/post-build.sh ${BR2_EXTERNAL_INF
BR2_ROOTFS_POST_IMAGE_SCRIPT="${BR2_EXTERNAL_INFIX_PATH}/board/common/post-image.sh"
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.12.17"
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.12.18"
BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="${BR2_EXTERNAL_INFIX_PATH}/board/x86_64/linux_defconfig"
BR2_LINUX_KERNEL_INSTALL_TARGET=y
+1 -1
View File
@@ -26,7 +26,7 @@ BR2_ROOTFS_POST_BUILD_SCRIPT="board/qemu/x86_64/post-build.sh ${BR2_EXTERNAL_INF
BR2_ROOTFS_POST_IMAGE_SCRIPT="${BR2_EXTERNAL_INFIX_PATH}/board/common/post-image.sh"
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.12.17"
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.12.18"
BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="${BR2_EXTERNAL_INFIX_PATH}/board/x86_64/linux_defconfig"
BR2_LINUX_KERNEL_INSTALL_TARGET=y
+3 -1
View File
@@ -8,7 +8,7 @@ All notable changes to the project are documented in this file.
-------------------------
### Changes
- Upgrade Linux kernel to 6.12.17 (LTS)
- Upgrade Linux kernel to 6.12.18 (LTS)
- Upgrade Buildroot to 2024.02.11 (LTS)
- Add support for link aggregation (lag), static (balance-xor) and LACP
- Add support for the [i.MX 8M Plus EVK][EVK]
@@ -31,6 +31,8 @@ All notable changes to the project are documented in this file.
- Fix #956: CLI `copy` command complains it cannot change owner when
copying `factory-config` to `running-config`. Bogus error, the
latter is not really a file
- Fix #977: "Operation not permitted" when saving `running-config` to
`startup-config` (harmless warning but annoying and concerning)
[EVK]: https://www.nxp.com/design/design-center/development-boards-and-designs/8MPLUSLPD4-EVK
@@ -1,4 +1,4 @@
From 764d64007818692f4a9a82c0ac7766b2dd82c3fb Mon Sep 17 00:00:00 2001
From 38625958e097c63ec25fddfbbf606c4b157cd058 Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Tue, 12 Mar 2024 10:27:24 +0100
Subject: [PATCH 01/26] [FIX] net: dsa: mv88e6xxx: Fix timeout on waiting for
@@ -1,4 +1,4 @@
From 0099e32f3b63edad9f465219495f6802535d9289 Mon Sep 17 00:00:00 2001
From b41039e6b8db5a484950aa8e839d13029c7f0424 Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Wed, 27 Mar 2024 15:52:43 +0100
Subject: [PATCH 02/26] net: dsa: mv88e6xxx: Improve indirect register access
@@ -1,4 +1,4 @@
From 130493d0f62dec37a8223ade52fabfe33d79613c Mon Sep 17 00:00:00 2001
From 31d3700b09b634676ab88f0f3469538903b12ace Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Mon, 22 Apr 2024 23:18:01 +0200
Subject: [PATCH 03/26] net: dsa: mv88e6xxx: Honor ports being managed via
@@ -1,4 +1,4 @@
From 5aec34b0adc86212a7625d1063c7c5d5acb5b998 Mon Sep 17 00:00:00 2001
From d048a31995fa82ccde7dc12df27b8162ae31762c Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Wed, 24 Apr 2024 22:41:04 +0200
Subject: [PATCH 04/26] net: dsa: mv88e6xxx: Limit rsvd2cpu policy to user
@@ -1,4 +1,4 @@
From 79d0413fef67198612b1ea33a178a68c09f2577a Mon Sep 17 00:00:00 2001
From a255c151a82221cccc896d6be5817c037cc563bb Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Thu, 16 Nov 2023 19:44:32 +0100
Subject: [PATCH 05/26] net: dsa: mv88e6xxx: Add LED infrastructure
@@ -1,4 +1,4 @@
From 173f8b38d70b6f2d03190e7301f289d19ba9ca68 Mon Sep 17 00:00:00 2001
From 2d2c9fdd45ab42b725b4a063b4444661b30bc59c Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Thu, 16 Nov 2023 21:59:35 +0100
Subject: [PATCH 06/26] net: dsa: mv88e6xxx: Add LED support for 6393X
@@ -1,4 +1,4 @@
From a036cd8a5a662d4d0f3a05d2f9280173fa1d02af Mon Sep 17 00:00:00 2001
From 91465d6568ea89cdf9e0092c1ff35a757aef5116 Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Tue, 28 May 2024 10:38:42 +0200
Subject: [PATCH 07/26] net: dsa: tag_dsa: Use tag priority as initial
@@ -1,4 +1,4 @@
From baaa565a877b373fc7e52c30b9b48455655a50f3 Mon Sep 17 00:00:00 2001
From fb892bdcfd4b7784a0506058b3e56c6055b4e4e8 Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Tue, 16 Jan 2024 16:00:55 +0100
Subject: [PATCH 08/26] net: dsa: Support MDB memberships whose L2 addresses
@@ -1,4 +1,4 @@
From 837c6528a52d96911ab2fe4bd9fa75f7ae37805e Mon Sep 17 00:00:00 2001
From a569ea3aa01cea0eef5181f1a4d5f06260c3ca6a Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Thu, 21 Mar 2024 19:12:15 +0100
Subject: [PATCH 09/26] net: dsa: Support EtherType based priority overrides
@@ -1,4 +1,4 @@
From c3009c9ad93711d1412ddaa88e55798670ec371a Mon Sep 17 00:00:00 2001
From 8e61cdafeabd25b88e591d7f9593fbc65453328a Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Fri, 22 Mar 2024 16:15:43 +0100
Subject: [PATCH 10/26] net: dsa: mv88e6xxx: Support EtherType based priority
@@ -1,4 +1,4 @@
From 1bb3fb000a2ad4dbea232c912ac95528a3bed481 Mon Sep 17 00:00:00 2001
From 9ddfb92b70bd73bacd358b699d30a8b8fd05b813 Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Tue, 28 May 2024 11:04:22 +0200
Subject: [PATCH 11/26] net: dsa: mv88e6xxx: Add mqprio qdisc support
@@ -1,4 +1,4 @@
From 0011185b1f3eeecd42c3b283013304bde4c16040 Mon Sep 17 00:00:00 2001
From fcf728f4442e961fc8361bba0d58aba8712f6893 Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Wed, 29 May 2024 13:20:41 +0200
Subject: [PATCH 12/26] net: dsa: mv88e6xxx: Use VLAN prio over IP when both
@@ -1,4 +1,4 @@
From 6fa5c1461fb90a2fe61a6d44220b53e10328c503 Mon Sep 17 00:00:00 2001
From c7fb329301a2889540d6416b1ec9145a00de443c Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Tue, 26 Nov 2024 19:45:59 +0100
Subject: [PATCH 13/26] [FIX] net: dsa: mv88e6xxx: Trap locally terminated
@@ -1,4 +1,4 @@
From ac15cb37e0f2fd2a06fe44cb0c505c22beac3205 Mon Sep 17 00:00:00 2001
From 31909f3d1f148d0bee1047abb76b890bf40bcb94 Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Tue, 19 Sep 2023 18:38:10 +0200
Subject: [PATCH 14/26] net: phy: marvell10g: Support firmware loading on
@@ -1,4 +1,4 @@
From 89fa5e4b03368186c4481b035d591d4e456ea942 Mon Sep 17 00:00:00 2001
From c7c930ee6d4003f8fda995b03cf7cbaf148ea58e Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Tue, 21 Nov 2023 20:15:24 +0100
Subject: [PATCH 15/26] net: phy: marvell10g: Fix power-up when strapped to
@@ -1,4 +1,4 @@
From 2c81264647131f894a6ee688521125e24af6d71c Mon Sep 17 00:00:00 2001
From 16fb7c5087266f173d8a5a3bf72f6798f702038f Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Wed, 15 Nov 2023 20:58:42 +0100
Subject: [PATCH 16/26] net: phy: marvell10g: Add LED support for 88X3310
@@ -1,4 +1,4 @@
From 55a4f6db87d9bc2d9a36385516f7f8c9dc9bb94c Mon Sep 17 00:00:00 2001
From 1c7ecd73741ecb39efd3b51720c81a15cf22e464 Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Tue, 12 Dec 2023 09:51:05 +0100
Subject: [PATCH 17/26] net: phy: marvell10g: Support LEDs tied to a single
@@ -1,4 +1,4 @@
From ab4964108f87924d3d8312e7eb9e715927cfcef6 Mon Sep 17 00:00:00 2001
From c6dd269683ee65b1a2879692379fba13cae40bd5 Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Wed, 27 Mar 2024 10:10:19 +0100
Subject: [PATCH 18/26] net: phy: Do not resume PHY when attaching
@@ -1,4 +1,4 @@
From a90e27c6ff44ba51c238d74f96b2dd5780efa892 Mon Sep 17 00:00:00 2001
From 604f9a09bf90c6dcec29b946851c59847ad368a7 Mon Sep 17 00:00:00 2001
From: Joachim Wiberg <troglobit@gmail.com>
Date: Mon, 4 Mar 2024 16:47:28 +0100
Subject: [PATCH 19/26] net: bridge: avoid classifying unknown multicast as
@@ -1,4 +1,4 @@
From 2eb0593e9847fd9a74172401731fea313b65b17a Mon Sep 17 00:00:00 2001
From 8c489b7e9abc123d1808546cd1dd8428b5482088 Mon Sep 17 00:00:00 2001
From: Joachim Wiberg <troglobit@gmail.com>
Date: Tue, 5 Mar 2024 06:44:41 +0100
Subject: [PATCH 20/26] net: bridge: Ignore router ports when forwarding L2
@@ -1,4 +1,4 @@
From 335960dd51d1ab81dff18d15e2b8323e77bd24b1 Mon Sep 17 00:00:00 2001
From 55e616c4e37d316b5d9266390dc13531d0bbd765 Mon Sep 17 00:00:00 2001
From: Joachim Wiberg <troglobit@gmail.com>
Date: Thu, 4 Apr 2024 16:36:30 +0200
Subject: [PATCH 21/26] net: bridge: drop delay for applying strict multicast
@@ -1,4 +1,4 @@
From e7f01bd6272ea87c378fc71ae27e09e5753ee423 Mon Sep 17 00:00:00 2001
From 186ecab132b86588eb6c1e93bcc33f3c5cc95c03 Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Thu, 16 May 2024 14:51:54 +0200
Subject: [PATCH 22/26] net: bridge: Differentiate MDB additions from
@@ -1,4 +1,4 @@
From 0ac0da2def4c5aae12b86ca1a366baf7ca29cf82 Mon Sep 17 00:00:00 2001
From e31128eb97256ae37bda13e8c02a1f53b92b3524 Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Fri, 24 Nov 2023 23:29:55 +0100
Subject: [PATCH 23/26] nvmem: layouts: onie-tlv: Let device probe even when
@@ -1,4 +1,4 @@
From 62dbe3579ce0c385bfd93232d9f7d5fafa5739c9 Mon Sep 17 00:00:00 2001
From 1e31630dd13b534d70440826df9c3b01c85966e7 Mon Sep 17 00:00:00 2001
From: Joachim Wiberg <troglobit@gmail.com>
Date: Mon, 29 Apr 2024 15:14:51 +0200
Subject: [PATCH 24/26] usb: core: adjust log level for unauthorized devices
@@ -1,4 +1,4 @@
From 2f0b42f7003a330de9922ed2c06f809a82e8a031 Mon Sep 17 00:00:00 2001
From cfb28602d7b9425f75fc37acdb123634e5717c2a Mon Sep 17 00:00:00 2001
From: Joachim Wiberg <troglobit@gmail.com>
Date: Thu, 16 Jan 2025 12:35:12 +0100
Subject: [PATCH 25/26] net: dsa: mv88e6xxx: collapse disabled state into
@@ -1,4 +1,4 @@
From 38e3fb928cbfb20870effe2f84834c8a81e8f40a Mon Sep 17 00:00:00 2001
From 5474cc6141ebdb748eea0b4ee6b79cce8b084585 Mon Sep 17 00:00:00 2001
From: Tobias Waldekranz <tobias@waldekranz.com>
Date: Wed, 12 Feb 2025 22:03:14 +0100
Subject: [PATCH 26/26] net: dsa: mv88e6xxx: Only activate LAG offloading when
+95 -24
View File
@@ -3,8 +3,10 @@
#include <getopt.h>
#include <pwd.h>
#include <grp.h>
#include <stdio.h>
#include <stdarg.h>
#include <libgen.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -23,11 +25,11 @@ struct infix_ds {
};
struct infix_ds infix_config[] = {
{ "startup-config", "startup", SR_DS_STARTUP, 1, "/cfg/startup-config.cfg" },
{ "running-config", "running", SR_DS_RUNNING, 1, NULL },
{ "candidate-config", "candidate", SR_DS_CANDIDATE, 1, NULL },
{ "operational-config", "operational", SR_DS_OPERATIONAL, 1, NULL },
{ "factory-config", "factory-default", SR_DS_FACTORY_DEFAULT, 0, NULL }
{ "startup-config", "startup", SR_DS_STARTUP, 1, "/cfg/startup-config.cfg" },
{ "running-config", "running", SR_DS_RUNNING, 1, NULL },
{ "candidate-config", "candidate", SR_DS_CANDIDATE, 1, NULL },
{ "operational-config", "operational", SR_DS_OPERATIONAL, 1, NULL },
{ "factory-config", "factory-default", SR_DS_FACTORY_DEFAULT, 0, NULL }
};
static const char *prognm = "copy";
@@ -64,6 +66,9 @@ end:
}
}
/*
* Current system user, same as sysrepo user
*/
static char *getuser(void)
{
const struct passwd *pw;
@@ -79,18 +84,83 @@ static char *getuser(void)
return pw->pw_name;
}
/*
* If UNIX user is in UNIX group of directory containing file,
* return 1, otherwise 0.
*
* E.g., writing to /cfg/foo, where /cfg is owned by root:wheel,
* should result in the file being owned by $LOGNAME:wheel with
* 0660 perms for other users in same group.
*/
static int in_group(const char *user, const char *fn, gid_t *gid)
{
char path[PATH_MAX];
const struct passwd *pw;
int i, num = 0, rc = 0;
struct stat st;
gid_t *groups;
char *dir;
pw = getpwnam(user);
if (!pw)
return 0;
strlcpy(path, fn, sizeof(path));
dir = dirname(path);
if (stat(dir, &st))
return 0;
num = NGROUPS_MAX;
groups = malloc(num * sizeof(gid_t));
if (!groups) {
perror("in_group() malloc");
return 0;
}
getgrouplist(user, pw->pw_gid, groups, &num);
for (i = 0; i < num; i++) {
if (groups[i] == st.st_gid) {
*gid = st.st_gid;
rc = 1;
break;
}
}
free(groups);
return rc;
}
/*
* Set group owner so other users with same directory permissions can
* read/write the file as well. E.g., an 'admin' level user in group
* 'wheel' writing a new file to `/cfg` should be possible to read and
* write to by other administrators.
*
* This function is called only when the file has been successfully
* copied or created in a file system directory. This is why we can
* safely ignore any EPERM errors to chown(), below, because if the file
* already existed, created by another user, we are not allowed to chgrp
* it. The sole purpose of this function is to allow other users in the
* same group to access the file in the future.
*/
static void set_owner(const char *fn, const char *user)
{
struct passwd *pw;
gid_t gid = 9999;
if (!fn)
return; /* not an error, e.g., running-config is not a file */
pw = getpwnam(user);
if (pw && !chmod(fn, 0660) && !chown(fn, pw->pw_uid, pw->pw_gid))
return;
if (!in_group(user, fn, &gid))
return; /* user not in parent directory's group */
fprintf(stderr, ERRMSG "setting owner %s on %s: %s\n", user, fn, strerror(errno));
if (chown(fn, -1, gid) && errno != EPERM) {
int _errno = errno;
const struct group *gr = getgrgid(gid);
fprintf(stderr, ERRMSG "setting group owner %s (%d) on %s: %s\n",
gr ? gr->gr_name : "<unknown>", gid, fn, strerror(_errno));
}
}
static const char *infix_ds(const char *text, struct infix_ds **ds)
@@ -108,20 +178,21 @@ static const char *infix_ds(const char *text, struct infix_ds **ds)
}
static int copy(const char *src, const char *dst, const char *user)
static int copy(const char *src, const char *dst, const char *remote_user)
{
struct infix_ds *srcds = NULL, *dstds = NULL;
char temp_file[20] = "/tmp/copy.XXXXXX";
const char *tmpfn = NULL;
sr_session_ctx_t *sess;
const char *fn = NULL;
const char *username;
sr_conn_ctx_t *conn;
const char *user;
char adjust[256];
mode_t oldmask;
int rc = 0;
oldmask = umask(0660);
/* rw for user and group only */
oldmask = umask(0006);
src = infix_ds(src, &srcds);
if (!src)
@@ -131,11 +202,11 @@ static int copy(const char *src, const char *dst, const char *user)
goto err;
if (!strcmp(src, dst)) {
fprintf(stderr, ERRMSG "source and destination are the same, aborting.");
fprintf(stderr, ERRMSG "source and destination are the same, aborting.\n");
goto err;
}
username = getuser();
user = getuser();
/* 1. Regular ds copy */
if (srcds && dstds) {
@@ -157,13 +228,13 @@ static int copy(const char *src, const char *dst, const char *user)
if (sr_session_start(conn, dstds->datastore, &sess)) {
fprintf(stderr, ERRMSG "unable to open transaction to %s\n", dst);
} else {
sr_nacm_set_user(sess, username);
sr_nacm_set_user(sess, user);
rc = sr_copy_config(sess, NULL, srcds->datastore, timeout * 1000);
if (rc)
emsg(sess, ERRMSG "unable to copy configuration, err %d: %s\n",
rc, sr_strerror(rc));
else
set_owner(dstds->path, username);
set_owner(dstds->path, user);
}
rc = sr_disconnect(conn);
@@ -187,11 +258,11 @@ static int copy(const char *src, const char *dst, const char *user)
if (rc)
fprintf(stderr, ERRMSG "failed exporting %s to %s\n", src, fn);
else {
rc = systemf("curl %s -LT %s %s", user, fn, dst);
rc = systemf("curl %s -LT %s %s", remote_user, fn, dst);
if (rc)
fprintf(stderr, ERRMSG "failed uploading %s to %s\n", src, dst);
else
set_owner(dst, username);
set_owner(dst, user);
}
goto err;
}
@@ -219,7 +290,7 @@ static int copy(const char *src, const char *dst, const char *user)
if (rc)
fprintf(stderr, ERRMSG "failed copy %s to %s\n", src, fn);
else
set_owner(fn, username);
set_owner(fn, user);
} else if (dstds) {
if (!dstds->sysrepocfg) {
fprintf(stderr, ERRMSG "not possible to import to this datastore.\n");
@@ -245,7 +316,7 @@ static int copy(const char *src, const char *dst, const char *user)
}
if (tmpfn)
rc = systemf("curl %s -Lo %s %s", user, fn, src);
rc = systemf("curl %s -Lo %s %s", remote_user, fn, src);
if (rc) {
fprintf(stderr, ERRMSG "failed downloading %s", src);
} else {
@@ -274,7 +345,7 @@ static int copy(const char *src, const char *dst, const char *user)
}
}
rc = systemf("curl %s -Lo %s %s", user, fn, src);
rc = systemf("curl %s -Lo %s %s", remote_user, fn, src);
} else if (strstr(dst, "://")) {
fn = cfg_adjust(src, NULL, adjust, sizeof(adjust));
if (!fn) {
@@ -286,7 +357,7 @@ static int copy(const char *src, const char *dst, const char *user)
if (access(fn, F_OK))
fprintf(stderr, ERRMSG "no such file %s, aborting.", fn);
else
rc = systemf("curl %s -LT %s %s", user, fn, dst);
rc = systemf("curl %s -LT %s %s", remote_user, fn, dst);
} else {
if (!access(dst, F_OK)) {
if (!yorn("Overwrite existing file %s", dst)) {
@@ -347,7 +418,7 @@ int main(int argc, char *argv[])
if (timeout < 0)
timeout = 120;
if (optind >= argc)
if (argc - optind != 2)
return usage(1);
src = argv[optind++];
+4
View File
@@ -28,6 +28,10 @@ int files(const char *path, const char *stripext)
if (d->d_type != DT_REG || d->d_name[0] == '.')
continue;
/* skip startup in /cfg, listed by plugin */
if (!strcmp(path, "/cfg") && !strcmp(d->d_name, "startup-config.cfg"))
continue;
strlcpy(name, d->d_name, sizeof(name));
if (stripext) {
size_t pos = has_ext(name, stripext);
+1 -1
View File
@@ -102,7 +102,7 @@ int infix_datastore(kcontext_t *ctx)
}
done:
return systemf("files /cfg .cfg");
return systemf("files /cfg");
}
int infix_erase(kcontext_t *ctx)