You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.3 KiB
101 lines
2.3 KiB
15 years ago
|
/***************************************************************************
|
||
|
* Copyright 2003 Braden MacDonald <bradenm_k@shaw.ca> *
|
||
|
* Copyright 2003 Ravikiran Rajagopal <ravi@ee.eng.ohio-state.edu> *
|
||
|
* *
|
||
|
* This program is free software; you can redistribute it and/or modify *
|
||
|
* it under the terms of the GNU General Public License (version 2) as *
|
||
|
* published by the Free Software Foundation. *
|
||
|
* *
|
||
|
***************************************************************************/
|
||
|
|
||
|
/**
|
||
|
* @file Change a user's 'finger' information, specifically their full name.
|
||
11 years ago
|
* derived from tdepasswd.
|
||
15 years ago
|
*/
|
||
|
|
||
|
#include <unistd.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
15 years ago
|
#include <tqcstring.h>
|
||
15 years ago
|
|
||
13 years ago
|
#include <tdesu/process.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
|
#include <kdebug.h>
|
||
|
#include "chfnprocess.h"
|
||
|
|
||
|
|
||
|
int ChfnProcess::exec(const char *pass, const char *name)
|
||
|
{
|
||
|
// Try to set the default locale to make the parsing of the output
|
||
|
// of `chfn' easier.
|
||
|
putenv((char*)"LC_ALL=C");
|
||
|
|
||
|
QCStringList args;
|
||
|
args += "-f";
|
||
|
args += name;
|
||
|
int ret = PtyProcess::exec("chfn", args);
|
||
|
if (ret < 0)
|
||
|
return ChfnNotFound;
|
||
|
|
||
|
ret = ConverseChfn(pass);
|
||
|
|
||
|
waitForChild();
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
* The actual work.
|
||
|
* Return values: -1 = unknown error, 0 = ok, >0 = error code.
|
||
|
*/
|
||
|
int ChfnProcess::ConverseChfn(const char *pass)
|
||
|
{
|
||
|
int status=-1;
|
||
|
|
||
15 years ago
|
TQCString line;
|
||
15 years ago
|
while(1)
|
||
|
{
|
||
|
line = readLine();
|
||
|
|
||
|
if ( line.isEmpty() )
|
||
|
continue;// discard line
|
||
|
|
||
13 years ago
|
if ( line.contains( "Password: " )/*isPrompt( line, "password" )*/ )
|
||
15 years ago
|
{
|
||
|
WaitSlave();
|
||
|
write(m_Fd, pass, strlen(pass));
|
||
|
write(m_Fd, "\n", 1);
|
||
|
}
|
||
|
|
||
|
line = readLine(); // Let's see what the outcome was
|
||
|
|
||
13 years ago
|
if ( line.contains( "Changing finger info" ) )
|
||
15 years ago
|
{
|
||
|
// do nothing
|
||
|
}
|
||
13 years ago
|
else if ( line.contains( "information changed" ) )
|
||
15 years ago
|
{
|
||
|
status=0;
|
||
|
break;
|
||
|
}
|
||
|
else if ( line.isEmpty() )
|
||
|
{
|
||
|
status=0;
|
||
|
break;
|
||
|
}
|
||
13 years ago
|
else if ( line.contains( "Password error" ) || line.contains("Incorrect password") )
|
||
15 years ago
|
{
|
||
|
status=PasswordError;
|
||
|
break;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
status=MiscError;
|
||
|
m_Error=line;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
return status;
|
||
|
}
|
||
|
|