diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-11-07 22:15:33 -0600 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-11-07 22:15:33 -0600 |
commit | 7b1ef4aa3f0fbe0b0742a272327ba29325bd917c (patch) | |
tree | 67198cad1ec397a4c8ed35cc0535eb6e07d84a1e | |
parent | d1b9110c038ed1e8d1e1fe2c959377f0a43706a2 (diff) | |
download | horizon-7b1ef4aa3f0fbe0b0742a272327ba29325bd917c.tar.gz horizon-7b1ef4aa3f0fbe0b0742a272327ba29325bd917c.tar.bz2 horizon-7b1ef4aa3f0fbe0b0742a272327ba29325bd917c.tar.xz horizon-7b1ef4aa3f0fbe0b0742a272327ba29325bd917c.zip |
owner: New utility
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | README.rst | 7 | ||||
-rw-r--r-- | owner/CMakeLists.txt | 6 | ||||
-rw-r--r-- | owner/owner.c | 30 | ||||
-rw-r--r-- | tests/spec/owner_spec.rb | 26 |
5 files changed, 70 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 12accf7..99aa25f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,6 +82,7 @@ IF(BUILD_TOOLS) ENDIF(BUILD_TOOLS) IF(INSTALL) add_subdirectory(fetch) + add_subdirectory(owner) ENDIF(INSTALL) @@ -210,6 +210,13 @@ library. This is the primary library for parsing, validating, and executing HorizonScript files, and contains the principal code for Project Horizon. +``owner``: File ownership utility +````````````````````````````````` +The ``owner`` directory includes the source code for the ``hscript-printowner`` +utility, which prints the UID of the owner of a given file. This is used +during HorizonScript shell script execution. + + ``tools``: Tooling and accessories `````````````````````````````````` The ``tools`` directory includes the source code for tools related to Project diff --git a/owner/CMakeLists.txt b/owner/CMakeLists.txt new file mode 100644 index 0000000..961efe7 --- /dev/null +++ b/owner/CMakeLists.txt @@ -0,0 +1,6 @@ +set(OWNER_SRCS + owner.c +) +add_executable(hscript-printowner ${OWNER_SRCS}) + +install(TARGETS hscript-printowner DESTINATION bin) diff --git a/owner/owner.c b/owner/owner.c new file mode 100644 index 0000000..2540421 --- /dev/null +++ b/owner/owner.c @@ -0,0 +1,30 @@ +/* + * owner.c - Implementation of the "print file owner UID" utility + * Project Horizon + * + * Copyright (c) 2019 Adélie Linux and contributors. All rights reserved. + * This code is licensed under the NCSA license. + * + * SPDX-License-Identifier: NCSA + */ + +#include <stdio.h> /* fprintf, perror */ +#include <stdlib.h> /* EXIT_* */ +#include <sys/stat.h> /* stat(3) and friends */ + +int main(int argc, char *argv[]) { + if(argc != 2) { + fprintf(stderr, "hscript-printowner: requires a path or file\n"); + return EXIT_FAILURE; + } + + struct stat buf; + if(stat(argv[1], &buf) != 0) { + perror("hscript-printowner: stat"); + return EXIT_FAILURE; + } + + fprintf(stdout, "%d\n", buf.st_uid); + + return EXIT_SUCCESS; +} diff --git a/tests/spec/owner_spec.rb b/tests/spec/owner_spec.rb new file mode 100644 index 0000000..32719ec --- /dev/null +++ b/tests/spec/owner_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +RSpec.describe 'HorizonScript Owner Print Utility', :type => :aruba do + context "argument passing" do + it "requires an path to be specified" do + run_command 'hscript-printowner' + expect(last_command_started).to have_output(/requires a path or file/) + end + it "requires exactly one path to be specified" do + run_command 'hscript-printowner a b c' + expect(last_command_started).to have_output(/requires a path or file/) + end + end + it "handles inaccessible paths correctly" do + run_command 'hscript-printowner /root/foo' + expect(last_command_started.stderr).to include("Permission denied") + end + it "handles nonexistent paths correctly" do + run_command 'hscript-printowner /nonexistent' + expect(last_command_started.stderr).to include("No such file or directory") + end + it "handles normal paths correctly" do + run_command 'hscript-printowner /' + expect(last_command_started.stdout).to eq("0\n") + end +end |