File: save.C

package info (click to toggle)
peruser 4b33-6
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,952 kB
  • ctags: 1,064
  • sloc: cpp: 22,367; perl: 2,733; makefile: 345; sh: 335
file content (131 lines) | stat: -rw-r--r-- 2,402 bytes parent folder | download | duplicates (2)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

#include "npfile.h"
#include "npstringarray.h"
#include "npauthentication.h"

int NP_Authentication::save()
{
   int existing;
   
   if ( config_file.openr( config_path ))
   {
      if ( errno != ENOENT )
      {
         snprintf( error_message, sizeof error_message, "NP_Authentication: "
                   "save(): %s", config_file.get_error() );
         return 1;
      }

      existing = 0;
   }
   else
      existing = 1;
   
   if ( temp_file.openw( temp_path ))
   {
      save_error( 0 );
      return 1;
   }

   char *line;

   if ( existing )
   {
      int x = 4;

      while( x-- )
      {
         if (( line = config_file.get_string()) == NULL )
         {
            save_error( 1 );
            return 1;
         }

         if ( temp_file.put_string( line ))
         {
            save_error( 0 );
            return 1;
         }
      }
   }
   else
   {
      int x = 4;
      while( x-- )
         if ( temp_file.put_string( "\n" ))
         {
            save_error( 0 );
            return 1;
         }
   }

   int total;
   if (( total = user_list.get_total() ) > 0 )
   {
      for( int i = 0; i < total; ++i )
      {
         if (( line = ( char *)user_list[ i ] ) == NULL )
         {
            save_error( 2 );
            return 1;
         }

         if ( line[ 0 ] == '\0' )
         {
            if ( temp_file.put_string( "0\n\n\n" ))
            {
               save_error( 0 );
               return 1;
            }

            continue;
         }

         if ( temp_file.put_string( "1\n" ))
         {
            save_error( 0 );
            return 1;
         }

         if ( temp_file.put_string( line ))
         {
            save_error( 0 );
            return 1;
         }

         if ( temp_file.put_string( "\n" ))
         {
            save_error( 0 );
            return 1;
         }

         if (( line = ( char *)pass_list[ i ] ) == NULL )
         {
            save_error( 3 );
            return 1;
         }

         if ( temp_file.put_string( line ))
         {
            save_error( 0 );
            return 1;
         }

         if ( temp_file.put_string( "\n" ))
         {
            save_error( 0 );
            return 1;
         }
      }
   }

   temp_file.close();
   config_file.close();

   rename( temp_path, config_path );

   return 0;
}