add more spacing
[personal-kdebase.git] / apps / kdepasswd / kcm / chfnprocess.cpp
blob7596029b52a24a362d96a75e480fb5018856ad5d
1 /***************************************************************************
2 * Copyright 2003 Braden MacDonald <bradenm_k@shaw.ca> *
3 * Copyright 2003 Ravikiran Rajagopal <ravi@ee.eng.ohio-state.edu> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License (version 2) as *
7 * published by the Free Software Foundation. *
8 * *
9 ***************************************************************************/
11 /**
12 * @file Change a user's 'finger' information, specifically their full name.
13 * derived from kdepasswd.
16 #include "chfnprocess.h"
18 #include <unistd.h>
19 #include <stdlib.h>
21 #include <kdesu/process.h>
22 #include <kdebug.h>
24 int ChfnProcess::exec(const char *pass, const char *name)
26 // Try to set the default locale to make the parsing of the output
27 // of `chfn' easier.
28 putenv((char*)"LC_ALL=C");
30 QList<QByteArray> args;
31 args += "-f";
32 args += name;
33 int ret = KDESu::PtyProcess::exec("chfn", args);
34 if (ret < 0)
35 return ChfnNotFound;
37 ret = ConverseChfn(pass);
39 waitForChild();
40 return ret;
45 * The actual work.
46 * Return values: -1 = unknown error, 0 = ok, >0 = error code.
48 int ChfnProcess::ConverseChfn(const char *pass)
50 int status=-1;
52 QByteArray line;
53 while(1)
55 line = readLine();
57 if ( line.isEmpty() )
58 continue;// discard line
59 else if ( line.contains( "Permission denied" ) )
61 status=MiscError;
62 m_Error=line;
63 break;
66 if ( line.contains( "Password: " )/*isPrompt( line, "password" )*/ )
68 WaitSlave();
69 write(fd(), pass, strlen(pass));
70 write(fd(), "\n", 1);
73 line = readLine(); // Let's see what the outcome was
75 if ( line.contains( "Changing finger info" ) )
77 // do nothing
79 else if ( line.contains( "information changed" ) )
81 status=0;
82 break;
84 else if ( line.isEmpty() )
86 status=0;
87 break;
89 else if ( line.contains( "Password error" ) || line.contains("Incorrect password") )
91 status=PasswordError;
92 break;
94 else
96 status=MiscError;
97 m_Error=line;
98 break;
101 return status;