How can I obtain an array with uid and names?
I could iterate from 0 to 99999 and do a getpwnam().
However most machines have less than 5 accounts, so it's not optimal. I don't know what framework is responsible for this and thus I have no clue what to search for.
Is there a more optimal solution that can traverse the accounts?
Edit: Right after I posted I discovered getpwent() for traversing accounts.
setpwent();
struct passwd *pw;
while ((pw = getpwent())) printf("%d\n", pw->pw_uid);
endpwent();
However that doesn't indicate wether an account is a System Preferences account or not.
So still how does one obtain the System Preferences accounts?
Edit: I have found the commandline equivalent of this, the dscl command.
prompt> dscl . -list /Users UniqueID
_mysql 74
_postfix 27
_spotlight 89
_sshd 75
_windowserver 88
_www 70
daemon 1
johndoe 501
nobody -2
root 0
Use getgrnam("staff") to get a group record for the staff group. The gr_mem member, while not explained in detail by the manpage, appears to be an array of user names terminated by a NULL pointer.
To find which users are administrators, do the same thing with the admin group.
Related
With Candy Machine V2 is there any way to limit the number of usages for each whitelist token to a certain number? For example, I would like to send each whitelist user one token that can be used to mint 3 times, and then it is burned so it can't be used more than that. This would be ideal.
Or would I need to send each whitelist user 3 different tokens and then burn each one after it is used once?
You have to read the whitelist docs (deprecated js-CLI and sugar).
You have 2 options about how the whitelist token will be used: burnEveryTime or neverBurn.
If you set burnEveryTime then each time the user mint 1 WL-token will be burned (make sure ur WL-token has 0 decimals in order to burn exactly 1 unit).
If you set neverBurn then the user will be able to mint with 1 WL-token any number of NFTs.
So in order to allow the user to mint X times with its WL-token you have to send him the exact amount of WL-token that you wanna allow each user to mint and set burnEveryTime, so the person will be able to Mint X NFTs and he will burn 1 WL-token per mint, so X burned WL-tokens.
Context: I'm getting the current Ruby process ID.
Process.pid #=> 95291
Process.ppid #=> 95201
Process.uid #=> 501
Process.gid #=> 20
Process.euid #=> 501
Process.egid #=> 20
In order:
pid: The is the process ID (PID) of the process you call the Process.pid method in.
ppid: The PID of the parent process (the process that spawned the current one). For example, if you run ruby test.rb in a bash shell, PPID in that process would be the PID of Bash.
uid: The UNIX ID of the user the process is running under.
euid: The effective user ID that the process is running under. The EUID determines what a program is allowed to do, based on what the user with this UID is allowed to do. Typically the same as uid, but can be different with commands like sudo.
gid: The UNIX group ID the program is running under.
egid: Like euid, but for groups.
PID:
In Linux, an executable stored on disk is called a program, and a program loaded into memory and running is called a process. When a process is started, it is given a unique number called process ID (PID) that identifies that process to the system. If you ever need to kill a process, for example, you can refer to it by its PID.
PPID:
In addition to a unique process ID, each process is assigned a parent process ID (PPID) that tells which process started it. The PPID is the PID of the process’s parent.
For example, if process1 with a PID of 101 starts a process named process2, then process2 will be given a unique PID, such as 3240, but it will be given the PPID of 101. It’s a parent-child relationship. A single parent process may spawn several child processes, each with a unique PID but all sharing the same PPID.
UID:
Unix-like operating systems identify users within the kernel by a value called a user identifier, often abbreviated to UID or User ID. The UID, along with the GID and other access control criteria, is used to determine which system resources a user can access. The password file maps textual usernames to UIDs, but in the kernel, only UID's are used.
EUID:
The effective UID (euid) of a process is used for most access checks. It is also used as the owner for files created by that process.
GID:
A group identifier, often abbreviated to GID, is a numeric value used to represent a specific group. The range of values for a GID varies amongst different systems; at the very least, a GID can be between 0 and 32,767, with one restriction: the login group for the superuser must have GID 0.
EGID:
The effective GID (egid) of a process also affects access control and may also affect file creation, depending on the semantics of the specific kernel implementation in use and possibly the mount options used.
Refer these articles for more information:
What are PID and PPID?
Meaning of PID, PPID and TGID
User identifier
Group identifier
In addition to the above comprehensive answers, I would like to share few linux commands and corresponding outputs which may help materialize the difference between real and effective user id/group for current logged in user myuser:
Real user and group names and numeric ID
$ id
uid=1000(myuser) gid=1000(myuser) groups=1000(myuser),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),119(lpadmin),130(lxd),131(sambashare)
Effective user and group names and numeric ID
$ sudo id
uid=0(root) gid=0(root) groups=0(root)
From the WMI namespace root\rsop\user\<user_SID> I can fetch an array of SecurityGroups using the WQL Select SecurityGroups from RSOP_Session. I end up with a list of SIDs similar to the following:
S-1-5-21-xxxxxxxxxx-xxxxxxxxxx-604776629-999
S-1-1-0
S-1-5-21-xxxxxxxxxx-xxxxxxxxxx-682003330-9999
S-1-5-32-545
S-1-5-32-544
S-1-5-4
S-1-5-11
S-1-2-0
S-1-5-21-xxxxxxxxxx-xxxxxxxxxx-604776629-888
S-1-5-21-xxxxxxxxxx-xxxxxxxxxx-604776629-77777
S-1-5-21-xxxxxxxxxx-xxxxxxxxxx-604776629-66666
S-1-5-21-xxxxxxxxxx-xxxxxxxxxx-604776629-55555
S-1-5-21-xxxxxxxxxx-xxxxxxxxxx-604776629-44444
My question: How do I retrieve the caption (name) of those SIDs? Some of them belongs to the domain, and yet some others belong to I'm not sure who/what/where... (the problem, of course, is the latter)
Process the SAM and SYSTEM hives with YARU (Yet Another Registry Utility) and generate a Password Hash Report from the Report menu, using the "Extracted hives" option for exported hives and the "Live System" option for the system which you are using.
YARU can be found for download at:
https://www.tzworks.net/download_links.php
YARU is located in the middle of the list under Registry and Event Log Analysis.
I am new to snmp, and I am trying to figure out what OID's I should get/trap to see if my printers, switches (and servers) is running? I do not need to know the details - just a simple test. I have successfully med get, getbulk, (and walk) request from a device, both from bash and iReasoning MIB browser.
Edit:
Maybe the
.1.3.6.1.2.1.1.3.0
Name/OID: sysUpTime.0; Value (TimeTicks): 194 hours 43 seconds (69844352)
is used for just that!? What happens when something is wrong? -will this be reset immediately? -or will it just stop counting? or is it just the time since last power on?
Printers
You should use the Printer MIBv2 to monitior printer error status for jams...
hrPrinterDetectedErrorState reports printer errors such as low toner, jams, etc... the RFC contains details on what specific codes mean
hrDeviceStatus will reveal the big picture ability of the printer to handle tasks. For more info, see Printer MIBv2, Section 2.2.13.2
sysUpTime.0 is an OID that reports the time a system's SNMP stack has been up (reference RFC 1213: MIB-II). If this value is returned and incrementing, it's a 99% safe bet that a printer is up. Most people use sysUpTime to detect whether the device has rebooted for some reason; if that happens, you'll see a sudden decrease in sysUpTime.0, unless your last value was around 248 days (where a 32-bit counter would roll).
Ethernet Switches
Checking the basic health of ethernet switches is usually done with checks to sysDescr.0 or sysUpTime.0; the problem with this heuristic comes if you care about the up/down status of particular links... at that point, you need to check values from ifOperStatus, which is indexed by ifIndex and uses interface names from ifName. See the following examples...
[mpenning#Hotcoffee ~]$ ## Walk ifName correlated to ifIndex
[mpenning#Hotcoffee ~]$ snmpwalk -v 2c -c Public 172.25.116.6 .1.3.6.1.2.1.31.1.1.1.1
iso.3.6.1.2.1.31.1.1.1.1.1 = STRING: "Fa0/0"
iso.3.6.1.2.1.31.1.1.1.1.2 = STRING: "Nu0"
[mpenning#Hotcoffee ~]$ ## Walk ifOperStatus (up==1)
[mpenning#Hotcoffee ~]$ snmpwalk -v 2c -c Public 172.25.116.6 .1.3.6.1.2.1.2.2.1.8
iso.3.6.1.2.1.2.2.1.8.1 = INTEGER: 1
iso.3.6.1.2.1.2.2.1.8.2 = INTEGER: 1
[mpenning#Hotcoffee ~]$
Thus we know from the example that both interface "Fa0/0" (index: 1) and "Nu0" (index: 2) have an ifOperStatus of "up"; the index value is the last integer returned in the OID of the results.
Scripting
I assume you will use bash for your monitoring scripts; if so, check out Net-SNMP for your SNMP manager
I'm trying to figure out the available disk space programmatically in windows. For this, I need to first get a list of the available drives, then check which of those are local drives and then query the available bytes on each local drive.
I'm a bit stuck on the first part, where the API presents two functions:
GetLogicalDrives (http://msdn.microsoft.com/en-us/library/aa364972(VS.85).aspx) which gives you a DWORD with the bits set (bit 0 if drive A is present, bit 1 if drive B etc)
GetLogicalDriveStrings (http://msdn.microsoft.com/en-us/library/aa364975(VS.85).aspx) which gives you the actual strings.
Now, although I'll be using strings later on, I'd prefer using the first option for querying. However, on my system a DWORD is typedef-ed to "unsigned long", which is 4 bytes, whereas drive letters only range A-Z (26 - i think - characters). Obviously, one can define more than 26 drives on their system (however unlikely they are to do so) - so I was wondering if there was any convention for those drives. Can someone point me to a resource on this?
Thanks.
DWORD is always 4 bytes, regardless of the system (it's a Win32 type).
The maximum for drive letters in Windows is 26. Because English alphabet has only 26 letters :). However, Windows allows two ways to mount a volume:
to a drive letter
to a directory (on an NTFS volume).
You can mount one volume to multiple locations (but no more than one drive letter, IIRC). A GUI for this task is presented by Control Panel -> Administrative Tools -> Computer Management -> Disk Management.
If you want to have more than 26 drives with the additional drives being redirects to already active drives and are okay with them not working properly in most programs, then you can assign more with the following method (be warned they won't even show up in the file explorer):
subst ♪: C:\Temp\
cd /D ♪:\
and to delete them (also they aren't preserved through restarts):
subst /D ♪:
You can enumerate all volumes and their mount points as described in this article.
You could use WMI. The following WMI query should list all drives:
SELECT * FROM Win32_DiskDrive
It it not sufficient to enumerate MS-DOS drives (there can be at most 26 of them, by the way, although each can be bound twice, once globally and once locally in your session), a volume can, for example, be mounted to a directory. What you want is probably to enumerate all volumes in the system, using FindFirstVolume et al. Take a look at the associated MSDN example.