Sponsored Content
Top Forums Programming Best way to check for system user and password in C Post 302383433 by royger on Tuesday 29th of December 2009 07:24:21 PM
Old 12-29-2009
Best way to check for system user and password in C

Hello,

I'm implementing a very simple FTP client, and to do the login I would like to check against system users instead of using my own database, so that I can give the proper permissions to the newly created process that I spawn with fork. What's the best way for doing this in C?

I've read about the getpwnam function, that returns a struct passwd that has the field pw_passwd to compare against (using the crypt function), but I'm not sure if this is quite standard, is there any other way to do this?

Thanks, Roger.
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

password check

Hi While using Pipe concept ,if a user enters a "login name" and "paswword" ,then how does a child process check for user password is correct or not and give notification to parent process. (1 Reply)
Discussion started by: riya
1 Replies

2. Solaris

How to check the last login user were doing in the system

Hi, I'm new to solaris/ Unix and would like to know how to check in the system what was the last login user were doing. Is there any way to check this? Thanks in advanced. (1 Reply)
Discussion started by: raziayub
1 Replies

3. UNIX for Advanced & Expert Users

password verification verify password of a user for only first 8 characters

Helo , I m using linux pam library for user and its password authentication. I m creating new user and giving its password.I m giving password of 10 characters.now when I login in as that newly created user its ask me $ su - ram Password: You are required to change your password immediately... (12 Replies)
Discussion started by: amitpansuria
12 Replies

4. Cybersecurity

Periodic check of user password strength

I need to periodically run a check on the passwords of the users (Redhat 5.0) to verify that all passwords meet minimal standards. I remember seeing a script years ago that grabbed the encrypted passwords from the file and checked if they matched any of the encrypted strings in another file, plus... (1 Reply)
Discussion started by: tlynnch
1 Replies

5. UNIX for Dummies Questions & Answers

Check password strength

For moderator: I made a new thread in a proper part of the forum now https://www.unix.com/homework-coursework-questions/137119-user-processes.html But now i wan't to make something which isn't related to a homework, so i hope you won't close this one. Thanks to those two answers, you helped me!... (9 Replies)
Discussion started by: petel1
9 Replies

6. UNIX for Advanced & Expert Users

Check EOF char in Unix. OR To check file has been received completely from a remote system

Advance Thanks. (1) I would like to know any unix/Linux command to check EOF char in a file. (2) Or Any way I can check a file has been reached completely at machine B from machine A. Note that machine A ftp/scp the file to machine B at unknown time. (5 Replies)
Discussion started by: alexalex1
5 Replies

7. Shell Programming and Scripting

How to scp File from root user in one server to say crt user in another server and avoid password?

Can someone help in writing some script through which I can transfer file (scp) from root user in abc server to crt user in hfg server and can give the crt user password in script itself so that it doesn't prompt me every time for password (4 Replies)
Discussion started by: Moon1234
4 Replies

8. HP-UX

How to check password expiration date of particular user?

Hi Guys, I am new to HP-UX and want to find expiration date of particular user please also note i don't have root access on that server. for e.g. i have user abc on my HP box and want to know when its password going to expire and also when its password changed last time. I also try to... (7 Replies)
Discussion started by: Yasin Rakhangi
7 Replies

9. UNIX and Linux Applications

Oracle Database - How to check if user roles and system roles are separated?

I have these two table. How do I see if user roles and system roles are seperated? SQL> desc DBA_ROLES; Name Null? Type ----------------------------------------- -------- ---------------------------- ROLE NOT NULL... (1 Reply)
Discussion started by: alvinoo
1 Replies
GETPWENT(3)						     Library Functions Manual						       GETPWENT(3)

NAME
getpwent, getpwnam, getpwuid, setpwent, endpwent, setpwfile - password file routines SYNOPSIS
#include <pwd.h> struct passwd *getpwent(void) struct passwd *getpwnam(const char *name) struct passwd *getpwuid(uid_t uid) int setpwent(void) void endpwent(void) void setpwfile(const char *file) DESCRIPTION
These functions are used to obtain information from the password file. They return this information in a struct passwd as defined by <pwd.h>: struct passwd { char *pw_name; /* login name */ char *pw_passwd; /* encrypted password */ uid_t pw_uid; /* numeric user id */ gid_t pw_gid; /* numeric group id */ char *pw_gecos; /* user full name and other info */ char *pw_dir; /* user's home directory */ char *pw_shell; /* name of the user's shell */ }; Getpwent() reads the password file entry by entry. Getpwnam() scans the entire password file for the user with the given name. Getpwuid() looks for the first user with the given uid. The setpwent() and endpwent() functions are used to open and later close the password file. With setpwfile() one can specify the file to read other than the normal password file. This only sets the name, the next setpwent() call will open the file. Do not touch the file name while it is active. Use setpwfile(NULL) to revert back to the normal password file. The usual way to scan the password file is (error checking omitted): setpwent(); while ((pw = getpwent()) != NULL) if (appropriate_test(pw)) break; endpwent(); The pw variable contains the entry that is wanted if non-NULL. The getpwnam() and getpwuid() functions are implemented as in this example, with error checking of course. Getpwent() calls setpwent() if this has not yet been done. Setpwent() first calls endpwent() if the password file is still open. (Other implementations may simply rewind the file.) FILES
/etc/passwd The password file database. SEE ALSO
cuserid(3), getlogin(3), getgrent(3), passwd(5). DIAGNOSTICS
Setpwent() has the same return value and error codes as the open(2) call it uses to open the password file. The getxxx() functions return NULL on end of file, entry not found, or error. You can set errno to zero before the call and check it after. NOTES
All getxxx() routines return a pointer to static storage that is overwritten in each call. Only getpwnam() and getpwuid() are defined by POSIX. The _MINIX_SOURCE macro must be defined before including <pwd.h> to make the other functions visible. The pw_passwd and pw_gecos fields are also not defined by POSIX, but are always visible. Portable code cannot reliably detect errors by setting errno to zero. Under Minix it is better to make a getpwent() scan if you need to look up several user-id's or names, but portable code had better use several getpwuid() or getpwnam() calls. The getpwent() is usually available on other systems, but may be very expensive. AUTHOR
Kees J. Bot (kjb@cs.vu.nl) GETPWENT(3)
All times are GMT -4. The time now is 05:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy