Questions tagged [getpwuid]

getpwuid - UNIX/POSIX function to get the password file entry for a user ID

16 questions
9
votes
3 answers

should I free pointer returned by getpwuid() in Linux?

After I call getpwuid(uid), I have a reference to a pointer. Should I free that pointer when I don't use it anymore? Reading the man pages, it says that it makes reference to some static area, that may be overwritten by subsequent calls to the same…
Gabriel
  • 2,313
  • 9
  • 29
  • 41
5
votes
3 answers

getpwuid() returns NULL for LDAP user

I'm having issues retrieving current user information of Red Hat Enterprise 6 where the user is an LDAP user? I have some code (actually part of an installation tool) that needs to retrieve the user name, home directory and other details. It is…
dtopham75
  • 620
  • 6
  • 14
4
votes
2 answers

How do I get user and group information in Perl on Windows?

Perl has several built-in functions for accessing /etc/passwd on Unix systems (and elsewhere when supported) for user and group information. For instance, my $name = getpwuid($uid); will return the user name given the user ID, or undef if there is…
Ville Koskinen
3
votes
0 answers

random crash with getpwuid()

I have a function that converts uids to usernames, char *uid2name (uid_t uid) { struct passwd *pwd = getpwuid (uid); if (pwd) return strdup (pwd->pw_name); return NULL; } And I call it with: name = uid2name (atoi…
daisy
  • 22,498
  • 29
  • 129
  • 265
2
votes
3 answers

Weird behavior of getpwnam

#include #include #include int main(void) { printf("%s %s\n", getpwnam("steve")->pw_name, getpwnam("root")->pw_name); printf("%d %d\n", getpwnam("steve")->pw_uid, getpwnam("root")->pw_uid); …
Steve Lau
  • 658
  • 7
  • 13
2
votes
0 answers

Platform-independent way to get the user's home directory in C++

Currently, when I want to get the user's home directory in C++, I do: #include const char* get_home_directory() { struct passwd *pw = getpwuid(getuid()); return (pw == nullptr ? nullptr : pw->pw_dir); } but this relies on getpwuid,…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
2
votes
1 answer

A second getpwuid call appears to overwrite old value

Here's a small C program that prints (well, supposed to print) the real and effective IDs of a process when the file has the setuid flag set. In this program, when I call getpwuid a second time (L.No 38), it tends to overwrite the value of the…
pmn
  • 187
  • 1
  • 1
  • 10
2
votes
1 answer

SVK synk and scheduled task

I'm trying to automate a SVK sync process. After configuring SVK mirrors, I wrote a batch file with the following svk sync -a >> svk.log &2>1 then I add a Windows Scheduled task running under my administrative account. in svk.log I read The…
Stefano
  • 740
  • 1
  • 6
  • 17
1
vote
2 answers

Why I am getting "getuid was not declared in that scope" error?

#include #include #include std::string impPath() { char *name; struct passwd *pass; pass = getpwuid(getuid()); name = pass->pw_name; std::string PATH = "/home"; PATH.append("/"); …
shobhit
  • 91
  • 3
  • 12
1
vote
1 answer

list of uids / names of System Preferences > Accounts

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…
neoneye
  • 50,398
  • 25
  • 166
  • 151
1
vote
1 answer

Safe way to use the result of getpwnam()/getpwuid()?

I'm working on Linux and FreeBSD. When I use getpwnam() or getpwuid(), I get a pointer to a passwd struct. What's the safe way to use the char* members of that passwd struct? The man page says this struct is a static object but will be overwritten…
Wang Tuma
  • 893
  • 5
  • 14
  • 24
1
vote
2 answers

valgrind reports getpwuid() leaks in c++ with Ubuntu

I have the following C++ file, pwd01.cpp: #include #include int main() { passwd* pwd = getpwuid(getuid()); } I compile this with the following command: g++ pwd01.cpp -Wall -o pwd01 On Ubuntu 12.04.1 LTS / gcc version…
flexatone
  • 149
  • 1
  • 6
0
votes
1 answer

Read files in a directory using readdir_r and sort using qsort

I am trying to write a program in C that reads files from a directory and detects the name, user, group, and size of each file. The information for each file is stored in a struct array and sorted by file name using qsort. The sorted files are…
Paddyngton
  • 55
  • 1
  • 8
0
votes
1 answer

Memory leak in si_user_byuid/getpwuid originating from CPSharedResourcesDirectory in iOS

I am at the optimizing/analysing phase of a product that will go live in a couple of weeks, and I am astonished to find some leaks that do not (I believe) originate from my code. One of them is the strdup/malloc leak present in iOS 5.1.1, for which…
Ælex
  • 14,432
  • 20
  • 88
  • 129
0
votes
1 answer

How do I get getpwuid to work in my mac app?

I'm trying to get my sandboxed mac app to get to the user's real home folder. This is what I tried const char *home = getpwent()->pw_dir; NSString *path = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:home …
dot
  • 2,823
  • 7
  • 38
  • 52
1
2