以编程方式从Unix中的用户名获取UID和GID? [英] Programmatically getting UID and GID from username in Unix?

查看:112
本文介绍了以编程方式从Unix中的用户名获取UID和GID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用setuid()和setgid()设置程序的相应ID,以从root放下特权,但是要使用它们,我需要知道我想要更改的用户的uid和gid

I'm trying to use setuid() and setgid() to set the respective id's of a program to drop privileges down from root, but to use them I need to know the uid and gid of the user I want to change to.

是否存在执行此操作的系统调用?我不想对其进行硬编码或从/ etc / passwd进行解析。

Is there a system call to do this? I don't want to hardcode it or parse from /etc/passwd .

我也想通过编程方式而不是使用:

Also I'd like to do this programmatically rather than using:

id -u用户名

任何帮助将不胜感激

推荐答案

看看 getpwnam()和< a href = http://linux.die.net/man/3/getgrnam rel = noreferrer> getgrnam()函数。

这篇关于以编程方式从Unix中的用户名获取UID和GID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆