LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-28-2004, 08:26 PM   #1
phoenix_fei
Member
 
Registered: Nov 2004
Location: shanghai
Distribution: worket
Posts: 41

Rep: Reputation: 15
please ,come here


I want to create user in linux. I want to know how to create multiple uers using c++ in linux os .
 
Old 11-28-2004, 10:25 PM   #2
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 53
mostly people just use scripting for this but the useradd program is in the shadow
package and that would be the place to look i guess
 
Old 11-28-2004, 11:26 PM   #3
phoenix_fei
Member
 
Registered: Nov 2004
Location: shanghai
Distribution: worket
Posts: 41

Original Poster
Rep: Reputation: 15
thanks

can you give me a in details .
 
Old 11-28-2004, 11:48 PM   #4
itsjustme
Senior Member
 
Registered: Mar 2003
Location: Earth
Distribution: Slackware, Ubuntu, Smoothwall
Posts: 1,571

Rep: Reputation: 47
$ useradd -m username

Also, I've never heard of a distribution named 'worket', but the useradd command should work. maybe...
 
Old 11-29-2004, 12:18 AM   #5
phoenix_fei
Member
 
Registered: Nov 2004
Location: shanghai
Distribution: worket
Posts: 41

Original Poster
Rep: Reputation: 15
hi

thanks, itsjustme
but i want to user C++ to achieve it.
can you help me?
please give some advice .
 
Old 11-29-2004, 12:21 AM   #6
itsjustme
Senior Member
 
Registered: Mar 2003
Location: Earth
Distribution: Slackware, Ubuntu, Smoothwall
Posts: 1,571

Rep: Reputation: 47
Oh... Sorry.. I didn't see the C++ part. (it's late and I should be in bed. )
Can't help you there.
 
Old 11-29-2004, 01:02 AM   #7
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
You can run shell commands using the exec family of functions so you can create a user using the exec commands in C. Declared in unistd.h

See the linux programmers' manual pages for the exec family of functions and you should get help for it. Note that to create users, you need to have root access.

Last edited by vharishankar; 11-29-2004 at 01:05 AM.
 
Old 11-29-2004, 01:28 AM   #8
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Here's a C++ sample code:
Code:
system("useradd -m username");
 
Old 11-29-2004, 01:34 AM   #9
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
Quote:
Originally posted by jlliagre
Here's a C++ sample code:
Code:
system("useradd -m username");
@jlliagre: Does the system command do the same thing as the execve command?
 
Old 11-29-2004, 01:49 AM   #10
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Yes, it's an higher level and simpler function, using the fork and exec system calls under the cover.
 
Old 11-29-2004, 01:53 AM   #11
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Just to depart slightly, in future, please use a more useful thread title. "Please, Come Here" tells us nothing at all about your problem and many members just skip over threads like yours. All threads get at least looked at, so your title is redundant.

Thanks
 
Old 11-30-2004, 12:08 PM   #12
wmakowski
Member
 
Registered: Oct 2003
Location: Ohio
Distribution: Fedora 25, 26, RHL 5.2
Posts: 560

Rep: Reputation: 56
Adding a User Programatically

For a more complete example of a program to add users take a look at my post on the following thread: http://www.linuxquestions.org/questi...readid=259442.

I used C along with the system() library function to execute the command useradd. I also had to use the crypt() function to set a password otherwise the account is setup disabled.

Bill

Last edited by wmakowski; 11-30-2004 at 12:21 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration