Sponsored Content
Top Forums Shell Programming and Scripting Problems understanding example code Post 302338840 by Makaer on Wednesday 29th of July 2009 04:39:30 AM
Old 07-29-2009
Problems understanding example code

I am really new to UNIX and programming in general and so apologies if this thread is a bit simple.

I have searched and found a piece of sample code for a training program I am currently undertaking, but seeing as I am relatively new, I dont completely understand how it works.

Here is the code:

file=$1
set -- $(ls -ld $file)

perms=$1
owner=$3

[[ "$perms" = ?r???????? ]] && owner_read=YES
[[ "$perms" = ??w??????? ]] && owner_write=YES
[[ "$perms" = ???x?????? ]] && owner_exec=YES

[[ "$perms" = ????r????? ]] && group_read=YES
[[ "$perms" = ?????w???? ]] && group_write=YES
[[ "$perms" = ??????x??? ]] && group_exec=YES

[[ "$perms" = ???????r?? ]] && world_read=YES
[[ "$perms" = ????????w? ]] && world_write=YES
[[ "$perms" = ?????????x ]] && world_exec=YES

echo "perms: $perms"
echo "OWNER $owner ${owner_read:-NO} ${owner_write:-NO} ${owner_exec:-NO}"
echo "GROUP ${group_read:-NO} ${group_write:-NO} ${group_exec:-NO}"
echo "WORLD ${world_read:-NO} ${world_write:-NO} ${world_exec:-NO}"
Basically I understand how the script works generally, but I am just wondering whether the [[ ]] is equal to a shorthand if statement?

Also is ${owner_read:-NO} checking if the result from the above statement is null and then if so printing "NO"?

Sorry if this is a bit simple.

Thanks for any help.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Understanding Code in IF LOOP

Hello All, I would like to know and understand the difference between the below 3 IF loops and also if possible what are the different other parameters i could use other than those mentioed in the below lF LOOP conditions, appreciate your help. Thanks, Sam. (1 Reply)
Discussion started by: Ariean
1 Replies

2. UNIX for Dummies Questions & Answers

Problems understanding example code

I am really new to UNIX and programming in general and so apologies if this thread is a bit simple. I have searched and found a piece of sample code for a training program I am currently undertaking, but seeing as I am relatively new, I dont completely understand how it works. Here is the... (6 Replies)
Discussion started by: Makaer
6 Replies

3. UNIX Desktop Questions & Answers

Understanding the code

hello all, May i know what is this "DEBUG_ME $DEBUG_CMD main" doing in the below code. I am confused with alias also "alias DEBUG_ME='#'". Thanks for your help. set -x alias DEBUG_ME='#' if ; then . /product/apps/informatica/v7/pc/ExtProc/debug.ksh "$1" fi # Declaring the... (1 Reply)
Discussion started by: Ariean
1 Replies

4. Programming

Problems understanding pipes

I am trying to create a csh clone, but am having problems implementing piped commands. Specifically, the below code simply hangs after input of ls | grep <text> It does however filter the output and display it correctly, but it appears that grep hasn't exited and my shell never comes back to the... (16 Replies)
Discussion started by: ab_tall
16 Replies

5. Shell Programming and Scripting

Help understanding Perl code.

Well, I found myself trying to fix some Perl code (Ive never done any Perl in my life) and I pinpointed the place where the bug could be. But to be sure I have to know what does a few line of code mean: $files_lim =~ (/^\d*$/) $files_lim =~ (/^\d*h$/)$files_age =~ s/h//The code where this was... (0 Replies)
Discussion started by: RedSpyder
0 Replies

6. Shell Programming and Scripting

Help understanding some Perl code.

Well, I found myself trying to fix some Perl code (Ive never done any Perl in my life) and I pinpointed the place where the bug could be. But to be sure I have to know what does a few line of code mean: $files_lim =~ (/^\d*$/) $files_lim =~ (/^\d*h$/) $files_age =~ s/h// The code where... (2 Replies)
Discussion started by: RedSpyder
2 Replies

7. Programming

Understanding perl code

What is the difference between the two statements below? A: $a->{"$fruit"}->{"$color"}->{size} = $size B: $size = $a->{"$fruit"}->{"$color"}->{size} Please assist. Thanks! (0 Replies)
Discussion started by: onlinelearner02
0 Replies

8. Shell Programming and Scripting

Help with perl code understanding

Hi, I need to understand below perl code, can some one advise me. perl -MDate::Parse -e'BEGIN{$main::now=time;$main::old=(time-60*30)}' -nE'if(/^(\w+\s+\d+\s+\d+:\d+:\d+)/) {$t=str2time $1; $t > $old && $t < $now && print}' (1 Reply)
Discussion started by: learnbash
1 Replies

9. UNIX for Dummies Questions & Answers

Understanding bash code

I am not able to understand below line in unix bash shell.Could anyone explain what it will do result="${path1}/*${var1}*${var2}*wssreligibleitem*.csv" path1 is defined and it is a directory path var1 is defined and it holds string value like abc var2 is defined and it holds string value like... (6 Replies)
Discussion started by: vamsi.valiveti
6 Replies

10. Programming

Understanding Assembly Code

As the title suggests, I want to better understand the following assembly code: section .text global main ; must be declared for linker (gcc) main: ; tell linker entry point mov edx, len ; message length mov ecx, msg ; message to write... (2 Replies)
Discussion started by: Azrael
2 Replies
avc_add_callback(3)					     SELinux API documentation					       avc_add_callback(3)

NAME
avc_add_callback - additional event notification for SELinux userspace object managers. SYNOPSIS
#include <selinux/selinux.h> #include <selinux/avc.h> int avc_add_callback(int (*callback)(uint32_t event, security_id_t ssid, security_id_t tsid, security_class_t tclass, access_vector_t perms, access_vector_t *out_retained), uint32_t events, security_id_t ssid, security_id_t tsid, security_class_t tclass, access_vector_t perms); DESCRIPTION
avc_add_callback is used to register callback functions on security events. The purpose of this functionality is to allow userspace object managers to take additional action when a policy change, usually a policy reload, causes permissions to be granted or revoked. events is the bitwise-or of security events on which to register the callback; see SECURITY EVENTS below. ssid, tsid, tclass, and perms specify the source and target SID's, target class, and specific permissions that the callback wishes to moni- tor. The special symbol SECSID_WILD may be passed as the source or target and will cause any SID to match. callback is the callback function provided by the userspace object manager. The event argument indicates the security event which occured; the remaining arguments are interpreted according to the event as described below. The return value of the callback should be zero on suc- cess, -1 on error with errno set appropriately (but see RETURN VALUE below). SECURITY EVENTS
In all cases below, ssid and/or tsid may be set to SECSID_WILD, indicating that the change applies to all source and/or target SID's. Unless otherwise indicated, the out_retained parameter is unused. AVC_CALLBACK_GRANT Previously denied permissions are now granted for ssid, tsid with respect to tclass. perms indicates the permissions to grant. AVC_CALLBACK_TRY_REVOKE Previously granted permissions are now conditionally revoked for ssid, tsid with respect to tclass. perms indicates the permissions to revoke. The callback should set out_retained to the subset of perms which are retained as migrated permissions. Note that out_retained is ignored if the callback returns -1. AVC_CALLBACK_REVOKE Previously granted permissions are now unconditionally revoked for ssid, tsid with respect to tclass. perms indicates the permis- sions to revoke. AVC_CALLBACK_RESET Indicates that the cache was flushed. The SID, class, and permission arguments are unused and are set to NULL. AVC_CALLBACK_AUDITALLOW_ENABLE The permissions given by perms should now be audited when granted for ssid, tsid with respect to tclass. AVC_CALLBACK_AUDITALLOW_DISABLE The permissions given by perms should no longer be audited when granted for ssid, tsid with respect to tclass. AVC_CALLBACK_AUDITDENY_ENABLE The permissions given by perms should now be audited when denied for ssid, tsid with respect to tclass. AVC_CALLBACK_AUDITDENY_DISABLE The permissions given by perms should no longer be audited when denied for ssid, tsid with respect to tclass. RETURN VALUE
On success, avc_add_callback returns zero. On error, -1 is returned and errno is set appropriately. A return value of -1 from a callback is interpreted as a failed policy operation. If such a return value is encountered, all remaining callbacks registered on the event are called. In threaded mode, the netlink handler thread may then terminate and cause the userspace AVC to return EINVAL on all further permission checks until avc_destroy(3) is called. In non-threaded mode, the permission check on which the error occurred will return -1 and the value of errno encountered to the caller. In both cases, a log message is produced and the kernel may be notified of the error. ERRORS
ENOMEM An attempt to allocate memory failed. NOTES
If the userspace AVC is running in threaded mode, callbacks registered via avc_add_callback may be executed in the context of the netlink handler thread. This will likely introduce synchronization issues requiring the use of locks. See avc_init(3). Support for dynamic revocation and retained permissions is mostly unimplemented in the SELinux kernel module. The only security event that currently gets excercised is AVC_CALLBACK_RESET. AUTHOR
Eamon Walsh <ewalsh@tycho.nsa.gov> SEE ALSO
avc_init(3), avc_has_perm(3), avc_context_to_sid(3), avc_cache_stats(3), security_compute_av(3) selinux(8) 9 June 2004 avc_add_callback(3)
All times are GMT -4. The time now is 05:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy