LinuxQuestions.org
Review your favorite Linux distribution.
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-05-2003, 07:41 PM   #1
evilchild504
LQ Newbie
 
Registered: Nov 2003
Posts: 1

Rep: Reputation: 0
help making a user adding program in c++


ok I'm running redhat 7.3 and using kdevelop 2.1
I'm trying to make a c++ program that i can execute when a user "newuser" logs in.

the program needs to some how execute the "adduser" and "passwd" commands and input the username and password the user of the program enters

where i'm stuck is somehow opening the "adduser" program and inputing the user name, wondering if this would work, "

string username = "";
string password = "";

//get username
outFile.open( "/usr/sbin/adduser.exe", ios::app )
cout << "please enter desired username";
cin >> username
outFile << username << endl;
outFile.close();
//get pass
outFile.open("/usr/bin/passwd.exe", ios::app)
cout << "please enter desired password";
cin >> password;
outFile << username << password << endl;
outFile.close()
cout << "thanks for using our services";
return 0;
}
as you can probably tell i'm no c++ genus, but would this work or is there some other way i should do this? please help
 
Old 11-06-2003, 02:46 AM   #2
mr_segfault
Member
 
Registered: Oct 2003
Location: Australia
Distribution: Redhat 9
Posts: 95

Rep: Reputation: 15
Well, what you have here will not work..

opening a file does not run a program..

This would be easier to do using a script, but if you must use C++ program, then use something like system, do a:

man 3 system

something like this might work:
Code:
#include <iostream>
#include <string>

int main()
{
  std::string username;
  std::string password;

  std::cout << "Please enter the desired username:";
  std::cin >> username;

  std::string commandToRun = "/usr/sbin/adduser.exe ";
  commandToRun += username;

  system(commandToRun.c_str());

// etc ...............................

  return 1;
}
But still I dont suggest using this method, a shell script would be better. Also passwd will want to read its input from stdin (use option --stdin), so you will have issues there, a line like "cat <put_password_here> | passwd --stdin" might work.

Also I think that you need to be logged in as the user for who you are changing the password for (when using passwd). I am no expert but I think that is correct..

What are you actually trying to do?

Cheers.
 
Old 11-06-2003, 03:39 AM   #3
gradedcheese
Member
 
Registered: Nov 2003
Posts: 59

Rep: Reputation: 15
Quote:
Originally posted by mr_segfault
Also I think that you need to be logged in as the user for who you are changing the password for (when using passwd). I am no expert but I think that is correct..
unless his program can use "su" and then run passwd somehow. This would be much more doable and generally nicer as a shell script, as mr_segfault said.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
making a backup of user / program settings Cinematography Linux - General 17 05-13-2005 11:42 PM
Making my FC3 box a Dual Boot by adding HD, and installing wXP. AaronW General 7 12-13-2004 10:38 PM
Adding route and making ifconfig permanent gani *BSD 9 09-21-2004 02:01 AM
what is a imaging making program djgerbavore Linux - Software 1 08-12-2004 07:39 AM
Adding a Gateway and making eth1 the primary unclebyron Linux - Networking 1 04-02-2002 07:35 PM

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

All times are GMT -5. The time now is 07:39 AM.

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