File: ClientPOPPASS.cc

package info (click to toggle)
postman 2.0-9
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 8,036 kB
  • ctags: 3,078
  • sloc: cpp: 31,131; ansic: 1,948; sh: 787; makefile: 285
file content (75 lines) | stat: -rw-r--r-- 2,697 bytes parent folder | download | duplicates (3)
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
/*
ClientPOPPASS.cc
*/

#include "ClientPOPPASS.h"
extern Language *L;

ClientPOPPASS::ClientPOPPASS (const char *aserver, int aport, const char *auser, const char *aoldpw, const char *anewpw)
  {
  xstrncpy (server, CMAXIPNAME, aserver);
  xstrncpy (user, CMAXBUFFER, auser);
  xstrncpy (oldpw, CMAXBUFFER, aoldpw);
  xstrncpy (newpw, CMAXBUFFER, anewpw);    
  poppassport = aport;
  }  

ClientPOPPASS::~ClientPOPPASS ()
  {
  }

bool ClientPOPPASS::doChangePassword (TBuffer ErrorString)
  {
  char buffer[1024], basura[1024];
  int sock, cod;
  XSocket *socket;

  initStr (ErrorString);
  socket = new XSocket ();
  socket->ignore_pipe();
  sock = socket->do_client_inet (server, NULL, poppassport, 240);
  if (sock == -1) {xstrncpy (ErrorString, CMAXBUFFER, L->get (ERR_SERVERISDOWN)); return false;}
  socket->SetSock (sock);
  
  /*LEO LA LINEA DE BIENVENIDA*/
  /*    -1 by the possible buffer overflow resulting from the linefeed added below. */
  if (!socket->Gets (buffer, sizeof(buffer) -1)) {xstrncpy (ErrorString, CMAXBUFFER, "Socket error"); return false;}
  sscanf (buffer, "%d %s", &cod, basura);
  if (cod != 200) {xstrncpy (ErrorString, CMAXBUFFER, buffer); return false;}

  /*ENVIO USER*/
  sprintf (buffer, "user %s\n", user);
  if (socket->Puts (buffer) == -1) {xstrncpy (ErrorString, CMAXBUFFER, "Socket error"); return false;}
  /*LEO LO RECIBIDO*/
  if (!socket->Gets (buffer, sizeof(buffer) -1)) {xstrncpy (ErrorString, CMAXBUFFER, "Socket error"); return false;}
  sscanf (buffer, "%d %s", &cod, basura);
  if (cod != 200) {xstrncpy (ErrorString, CMAXBUFFER, buffer); return false;}
  
  /*ENVIO OLD PASS*/
  sprintf (buffer, "pass %s\n", oldpw);
  if (socket->Puts (buffer) == -1) {xstrncpy (ErrorString, CMAXBUFFER, "Socket error"); return false;}
  /*LEO LO RECIBIDO*/
  if (!socket->Gets (buffer, sizeof(buffer) -1)) {xstrncpy (ErrorString, CMAXBUFFER, "Socket error"); return false;}
  sscanf (buffer, "%d %s", &cod, basura);
  if (cod != 200) {xstrncpy (ErrorString, CMAXBUFFER, buffer); return false;}

  /*ENVIO NEW PASS*/
  sprintf (buffer, "newpass %s\n", newpw);
  if (socket->Puts (buffer) == -1) {xstrncpy (ErrorString, CMAXBUFFER, "Socket error"); return false;}
  /*LEO LO RECIBIDO*/
  if (!socket->Gets (buffer, sizeof(buffer) -1)) {xstrncpy (ErrorString, CMAXBUFFER, "Socket error"); return false;}
  sscanf (buffer, "%d %s", &cod, basura);
  if (cod != 200) {xstrncpy (ErrorString, CMAXBUFFER, buffer); return false;}

  /*ENVIO QUIT*/
  sprintf (buffer, "QUIT\n");
  if (socket->Puts (buffer) == -1) {/*NOTHING*/}

  /*LEO LA LINEA DE QUIT*/
  if (!socket->Gets (buffer, sizeof(buffer) -1)) {/*NOTHING*/}

  delete socket;
    
  return true;
  }