Changeset 5b52a48 for storage_text.c
- Timestamp:
- 2006-07-03T21:22:45Z (19 years ago)
- Branches:
- master
- Children:
- 7e3592e
- Parents:
- 911f2eb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
storage_text.c
r911f2eb r5b52a48 113 113 114 114 http_decode( s ); 115 nick_set( irc, s, prpl, nick );115 // FIXME!!!! nick_set( irc, s, prpl, nick ); 116 116 } 117 117 fclose( fp ); 118 119 return STORAGE_OK;120 }121 122 static storage_status_t text_save( irc_t *irc, int overwrite )123 {124 char s[512];125 char path[512], new_path[512];126 char *line;127 nick_t *n;128 set_t *set;129 mode_t ou = umask( 0077 );130 account_t *a;131 FILE *fp;132 char *hash;133 134 if (!overwrite) {135 g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" );136 if (access( path, F_OK ) != -1)137 return STORAGE_ALREADY_EXISTS;138 139 g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" );140 if (access( path, F_OK ) != -1)141 return STORAGE_ALREADY_EXISTS;142 }143 144 /*\145 * [SH] Nothing should be saved if no password is set, because the146 * password is not set if it was wrong, or if one is not identified147 * yet. This means that a malicious user could easily overwrite148 * files owned by someone else:149 * a Bad Thing, methinks150 \*/151 152 /* [WVG] No? Really? */153 154 /*\155 * [SH] Okay, okay, it wasn't really Wilmer who said that, it was156 * me. I just thought it was funny.157 \*/158 159 hash = hashpass( irc->password );160 if( hash == NULL )161 {162 irc_usermsg( irc, "Please register yourself if you want to save your settings." );163 return STORAGE_OTHER_ERROR;164 }165 166 g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks~" );167 fp = fopen( path, "w" );168 if( !fp ) return STORAGE_OTHER_ERROR;169 for( n = irc->nicks; n; n = n->next )170 {171 strcpy( s, n->handle );172 s[169] = 0; /* Prevent any overflow (169 ~ 512 / 3) */173 http_encode( s );174 g_snprintf( s + strlen( s ), 510 - strlen( s ), " %d %s", find_protocol_id(n->proto->name), n->nick );175 if( fprintf( fp, "%s\n", s ) != strlen( s ) + 1 )176 {177 irc_usermsg( irc, "fprintf() wrote too little. Disk full?" );178 fclose( fp );179 return STORAGE_OTHER_ERROR;180 }181 }182 if( fclose( fp ) != 0 )183 {184 irc_usermsg( irc, "fclose() reported an error. Disk full?" );185 return STORAGE_OTHER_ERROR;186 }187 188 g_snprintf( new_path, 512, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" );189 if( unlink( new_path ) != 0 )190 {191 if( errno != ENOENT )192 {193 irc_usermsg( irc, "Error while removing old .nicks file" );194 return STORAGE_OTHER_ERROR;195 }196 }197 if( rename( path, new_path ) != 0 )198 {199 irc_usermsg( irc, "Error while renaming new .nicks file" );200 return STORAGE_OTHER_ERROR;201 }202 203 g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts~" );204 fp = fopen( path, "w" );205 if( !fp ) return STORAGE_OTHER_ERROR;206 if( fprintf( fp, "%s", hash ) != strlen( hash ) )207 {208 irc_usermsg( irc, "fprintf() wrote too little. Disk full?" );209 fclose( fp );210 return STORAGE_OTHER_ERROR;211 }212 g_free( hash );213 214 for( a = irc->accounts; a; a = a->next )215 {216 if( !strcmp(a->prpl->name, "oscar") )217 g_snprintf( s, sizeof( s ), "account add oscar \"%s\" \"%s\" %s", a->user, a->pass, a->server );218 else219 g_snprintf( s, sizeof( s ), "account add %s \"%s\" \"%s\" \"%s\"",220 a->prpl->name, a->user, a->pass, a->server ? a->server : "" );221 222 line = obfucrypt( s, irc->password );223 if( *line )224 {225 if( fprintf( fp, "%s\n", line ) != strlen( line ) + 1 )226 {227 irc_usermsg( irc, "fprintf() wrote too little. Disk full?" );228 fclose( fp );229 return STORAGE_OTHER_ERROR;230 }231 }232 g_free( line );233 }234 235 for( set = irc->set; set; set = set->next )236 {237 if( set->value && set->def )238 {239 g_snprintf( s, sizeof( s ), "set %s \"%s\"", set->key, set->value );240 line = obfucrypt( s, irc->password );241 if( *line )242 {243 if( fprintf( fp, "%s\n", line ) != strlen( line ) + 1 )244 {245 irc_usermsg( irc, "fprintf() wrote too little. Disk full?" );246 fclose( fp );247 return STORAGE_OTHER_ERROR;248 }249 }250 g_free( line );251 }252 }253 254 if( strcmp( irc->mynick, ROOT_NICK ) != 0 )255 {256 g_snprintf( s, sizeof( s ), "rename %s %s", ROOT_NICK, irc->mynick );257 line = obfucrypt( s, irc->password );258 if( *line )259 {260 if( fprintf( fp, "%s\n", line ) != strlen( line ) + 1 )261 {262 irc_usermsg( irc, "fprintf() wrote too little. Disk full?" );263 fclose( fp );264 return STORAGE_OTHER_ERROR;265 }266 }267 g_free( line );268 }269 if( fclose( fp ) != 0 )270 {271 irc_usermsg( irc, "fclose() reported an error. Disk full?" );272 return STORAGE_OTHER_ERROR;273 }274 275 g_snprintf( new_path, 512, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" );276 if( unlink( new_path ) != 0 )277 {278 if( errno != ENOENT )279 {280 irc_usermsg( irc, "Error while removing old .accounts file" );281 return STORAGE_OTHER_ERROR;282 }283 }284 if( rename( path, new_path ) != 0 )285 {286 irc_usermsg( irc, "Error while renaming new .accounts file" );287 return STORAGE_OTHER_ERROR;288 }289 290 umask( ou );291 118 292 119 return STORAGE_OK; … … 337 164 .check_pass = text_check_pass, 338 165 .remove = text_remove, 339 .load = text_load, 340 .save = text_save 166 .load = text_load 341 167 };
Note: See TracChangeset
for help on using the changeset viewer.