blob: 72c1599fc55556ce6c9e5cb37de89141d84371ec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/***************************************************************************
* 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.
* derived from tdepasswd.
*/
#include <unistd.h>
#include <stdlib.h>
#include <tqcstring.h>
#include <tdesu/process.h>
#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;
TQCString line;
while(1)
{
line = readLine();
if ( line.isEmpty() )
continue;// discard line
if ( line.contains( "Password: " )/*isPrompt( line, "password" )*/ )
{
WaitSlave();
write(m_Fd, pass, strlen(pass));
write(m_Fd, "\n", 1);
}
line = readLine(); // Let's see what the outcome was
if ( line.contains( "Changing finger info" ) )
{
// do nothing
}
else if ( line.contains( "information changed" ) )
{
status=0;
break;
}
else if ( line.isEmpty() )
{
status=0;
break;
}
else if ( line.contains( "Password error" ) || line.contains("Incorrect password") )
{
status=PasswordError;
break;
}
else
{
status=MiscError;
m_Error=line;
break;
}
}
return status;
}
|