Changeset 6055
- Timestamp:
- Jun 5, 2008, 6:16:59 PM (14 years ago)
- Location:
- trunk/daemon
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/daemon/daemon.c
r5913 r6055 39 39 tr_benc d; 40 40 const char * str; 41 42 tr_bencInitDict( &d, 12 ); 41 char * username = tr_sessionGetRPCUsername( h ); 42 char * password = tr_sessionGetRPCPassword( h ); 43 char * auth = tr_strdup_printf( "%s:%s", username, password ); 44 45 tr_bencInitDict( &d, 14 ); 43 46 tr_bencDictAddStr( &d, "download-dir", tr_sessionGetDownloadDir( h ) ); 44 47 tr_bencDictAddInt( &d, "peer-limit", tr_sessionGetPeerLimit( h ) ); 45 48 tr_bencDictAddInt( &d, "pex-allowed", tr_sessionIsPexEnabled( h ) ); 46 49 tr_bencDictAddInt( &d, "port", tr_sessionGetPeerPort( h ) ); 50 tr_bencDictAddStr( &d, "auth", auth ); 51 tr_bencDictAddInt( &d, "auth-required", 52 tr_sessionIsRPCPasswordEnabled( h ) ); 47 53 tr_bencDictAddInt( &d, "port-forwarding-enabled", 48 54 tr_sessionIsPortForwardingEnabled( h ) ); … … 68 74 69 75 tr_bencFree( &d ); 70 } 71 72 static void 73 session_init( const char * configDir, int rpc_port, const char * rpc_acl ) 76 tr_free( auth ); 77 tr_free( password ); 78 tr_free( username ); 79 } 80 81 static int 82 parseAuth( const char * auth, char ** username, char ** password ) 83 { 84 int err = 0; 85 const char * pch = strchr( auth, ':' ); 86 if( !pch ) 87 err = -1; 88 else { 89 *username = tr_strndup( auth, pch-auth ); 90 *password = tr_strdup( pch+1 ); 91 } 92 return err; 93 } 94 95 static void 96 session_init( const char * configDir, int rpc_port, 97 const char * acl, const char * auth, int noauth ) 74 98 { 75 99 tr_benc state; … … 85 109 int encryption = TR_ENCRYPTION_PREFERRED; 86 110 char downloadDir[MAX_PATH_LENGTH] = { '\0' }; 87 const char * rpc_acl_fallback = TR_DEFAULT_RPC_ACL;111 const char * acl_fallback = TR_DEFAULT_RPC_ACL; 88 112 int64_t rpc_port_fallback = TR_DEFAULT_RPC_PORT; 113 int64_t auth_required_fallback = 0; 114 const char * auth_fallback = NULL; 89 115 tr_ctor * ctor; 90 116 tr_torrent ** torrents; 117 int auth_required; 118 char * user = NULL; 119 char * pass = NULL; 91 120 92 121 if(( have_state = !tr_bencLoadFile( myConfigFilename, &state ))) … … 101 130 tr_bencDictFindInt( &state, "port", &peer_port ); 102 131 tr_bencDictFindInt( &state, "port-forwarding-enabled", &fwd_enabled ); 103 tr_bencDictFindStr( &state, "rpc-acl", &rpc_acl_fallback ); 132 tr_bencDictFindStr( &state, "rpc-acl", &acl_fallback ); 133 tr_bencDictFindStr( &state, "auth", &auth_fallback ); 134 tr_bencDictFindInt( &state, "auth-required", &auth_required_fallback ); 104 135 tr_bencDictFindInt( &state, "rpc-port", &rpc_port_fallback ); 105 136 tr_bencDictFindInt( &state, "speed-limit-down", &down_limit ); … … 120 151 if( rpc_port < 1 ) 121 152 rpc_port = rpc_port_fallback; 122 if( !rpc_acl || !*rpc_acl ) 123 rpc_acl = rpc_acl_fallback; 153 if( !acl || !*acl ) 154 acl = acl_fallback; 155 if( !auth || !*auth ) 156 auth = auth_fallback; 157 158 if( auth && parseAuth( auth, &user, &pass ) ) { 159 tr_nerr( MY_NAME, "Unable to parse authentication string \"%s\"", auth ); 160 abort( ); 161 } 162 163 if( noauth ) { 164 /* user has explicitly turned off authentication */ 165 user = NULL; 166 pass = NULL; 167 } 168 169 auth_required = user || pass; 124 170 125 171 /* start the session */ … … 133 179 FALSE, /* is the blocklist enabled? */ 134 180 TR_DEFAULT_PEER_SOCKET_TOS, 135 TRUE, rpc_port, rpc_acl ); 181 TRUE, rpc_port, acl, 182 auth_required, user, pass ); 183 184 if( auth_required ) 185 tr_ninf( MY_NAME, "requiring authentication" ); 136 186 137 187 /* load the torrents */ … … 157 207 " -g --config-dir <dir> Where to look for torrents and daemon-config.benc\n" 158 208 " -h --help Display this message and exit\n" 209 " -t --auth <user>:<pass> Username and password for authentication\n" 159 210 " -p --port n Port to listen to for requests (Default: "TR_DEFAULT_RPC_PORT_STR")\n" 160 211 "\n" … … 166 217 static void 167 218 readargs( int argc, char ** argv, 168 int * nofork, int * port, char ** acl, 169 char ** configDir ) 219 int * nofork, int * port, 220 char ** configDir, 221 char ** acl, 222 char ** auth, 223 int * noauth ) 170 224 { 171 225 int opt; 172 char optstr[] = "a:fg:h p:";226 char optstr[] = "a:fg:hnp:t:u:w:"; 173 227 struct option longopts[] = { 174 228 { "acl", required_argument, NULL, 'a' }, … … 176 230 { "config-dir", required_argument, NULL, 'g' }, 177 231 { "help", no_argument, NULL, 'h' }, 232 { "noauth", no_argument, NULL, 'n' }, 178 233 { "port", required_argument, NULL, 'p' }, 234 { "auth", required_argument, NULL, 't' }, 179 235 { NULL, 0, NULL, '\0' } 180 236 }; … … 183 239 case 'a': *acl = tr_strdup( optarg ); break; 184 240 case 'f': *nofork = 1; break; 241 case 'n': *noauth = 1; break; 185 242 case 'g': *configDir = tr_strdup( optarg ); break; 243 case 't': *auth = tr_strdup( optarg ); break; 186 244 case 'p': *port = atoi( optarg ); break; 187 245 default: daemonUsage( ); break; … … 254 312 { 255 313 int nofork = 0; 314 int noauth = 0; 256 315 int port = TR_DEFAULT_RPC_PORT; 257 316 char * configDir = NULL; 258 317 char * acl = NULL; 318 char * auth = NULL; 259 319 260 320 signal( SIGINT, gotsig ); … … 264 324 signal( SIGHUP, SIG_IGN ); 265 325 266 readargs( argc, argv, &nofork, &port, & acl, &configDir);326 readargs( argc, argv, &nofork, &port, &configDir, &acl, &auth, &noauth ); 267 327 if( configDir == NULL ) 268 328 configDir = tr_strdup_printf( "%s-daemon", tr_getDefaultConfigDir() ); … … 277 337 } 278 338 279 session_init( configDir, port, acl );339 session_init( configDir, port, acl, auth, noauth ); 280 340 281 341 while( !closing ) -
trunk/daemon/remote.c
r5951 r6055 66 66 " -S --stop <int> Stop the torrent with the given ID\n" 67 67 " -S --stop all Stop all running torrents\n" 68 " -t --auth <user>:<pass> Username and password for authentication\n" 68 69 " -u --upload-limit <int> Max upload rate in KiB/s\n" 69 70 " -U --upload-unlimited No upload rate limit\n" … … 87 88 static int reqCount = 0; 88 89 static int debug = 0; 90 static char * auth = NULL; 89 91 90 92 static char* … … 115 117 { 116 118 int opt; 117 char optstr[] = "a:c:d:DeEf:ghlmMp:r:s:S: u:Uv:";119 char optstr[] = "a:c:d:DeEf:ghlmMp:r:s:S:t:u:Uv:"; 118 120 119 121 const struct option longopts[] = … … 135 137 { "start", required_argument, NULL, 's' }, 136 138 { "stop", required_argument, NULL, 'S' }, 139 { "auth", required_argument, NULL, 't' }, 137 140 { "upload-limit", required_argument, NULL, 'u' }, 138 141 { "upload-unlimited", no_argument, NULL, 'U' }, … … 153 156 { 154 157 case 'g': debug = 1; 158 addArg = FALSE; 159 break; 160 case 't': auth = tr_strdup( optarg ); 155 161 addArg = FALSE; 156 162 break; … … 288 294 289 295 if( tr_jsonParse( response, len, &top, NULL ) ) 290 tr_nerr( MY_NAME, "Unable to parse response ");296 tr_nerr( MY_NAME, "Unable to parse response \"%*.*s\"", (int)len, (int)len, (char*)response ); 291 297 else 292 298 { … … 347 353 curl_easy_setopt( curl, CURLOPT_POST, 1 ); 348 354 curl_easy_setopt( curl, CURLOPT_URL, url ); 355 if( auth ) { 356 curl_easy_setopt( curl, CURLOPT_USERPWD, auth ); 357 curl_easy_setopt( curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY ); 358 } 349 359 350 360 for( i=0; i<reqCount; ++i ) -
trunk/daemon/transmission-daemon.1
r5861 r6055 14 14 .Op Fl g Ar directory 15 15 .Op Fl p Ar port 16 .Op Fl t Ar user:pass 16 17 .Ek 17 18 … … 39 40 .It Fl g Fl -config-dir Ar directory 40 41 Where to look for .torrent and config files on startup. 42 .It Fl t Fl -auth Ar user:pass 43 Requre 44 .Ar username 45 and 46 .Ar password 47 authentication 41 48 .It Fl h Fl -help 42 49 Print command-line option descriptions. -
trunk/daemon/transmission-remote.1
r5868 r6055 25 25 .Op Fl M 26 26 .Op Fl p Ar port 27 .Op Fl t Ar user:pass 27 28 .Op Fl q 28 29 .Oo … … 84 85 .Ar port 85 86 for use as a listening port to accept incoming peer connections. 87 .It Fl t Fl -auth Ar user:pass 88 .Ar Username 89 and 90 .Ar password 91 for authentication 86 92 87 93 .It Fl r Fl -remove Ar all | id | torrent-hash
Note: See TracChangeset
for help on using the changeset viewer.