如何创建一个使用C / C一个Linux用户++? [英] How to create a linux user using C/C++?

查看:79
本文介绍了如何创建一个使用C / C一个Linux用户++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个程序,它需要一个用户名作为参数,创建用户及其主文件夹(有一些硬codeD规范,比如文件夹,安全检查一样的用户名不能是根或现有的用户)。

I would like to build a program which takes a username as parameter and creates the user and its home folder (with some hard-coded specifications like folder, and security checks like username cannot be root or an existing user).

我的应用程序需要为了给SSH访问创建用户。

My application needs to create users in order to give SSH access.

程序将使用的须藤被执行。我读过应该用C或C ++而不是脚本,因为脚本很容易被利用。

The program will be executed using sudo. I've read it should be written in C or C++ instead of scripts because scripts could easily be exploited.


  • 你能不能给我的一些建议或者好的做法关于如何实现这一目标?

  • 我应该使用一些帕姆库?是否有任何的例子吗?

  • 什么是在可能的安全漏洞?

  • Can you give me some advices or good practices about how to achieve this?
  • Should I use some Pam library? Is there any examples?
  • What are the possible security flaws?

我知道的C / C ++和运行Ubuntu清醒。

I know C/C++, and running Ubuntu Lucid.

编辑:

该用户将只能sudo访问来运行特定的命令,我不希望它能够运行一个shell或旁路某些程序(通过改变PATH环境,例如)。

The user will only have sudo access to run that specific command, I do not want it to be able to run a shell or bypass some programs (by changing PATH environment, for example).

因此​​,例如,我将需要覆盖的 PATH 还有什么我应该担心的?

As a result, for example, I will need to override the PATH, what else should I worry about?

推荐答案

可能是你最好的选择是调用useradd的;它会做正确的事(给予相应参数)。

Probably your best bet is to invoke useradd; it will do the right things (given appropriate parameters).

试图通过调用相应API手动创建一个是可能的,但不可取的。

Trying to create one manually by calling the appropriate APIs is possible but not desirable.

这篇关于如何创建一个使用C / C一个Linux用户++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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