15368db27SMaxim Konovalov 25368db27SMaxim KonovalovAbout unix_cmsg 3b5718158SSergey Kandaurov=============== 45368db27SMaxim Konovalov 5b5718158SSergey KandaurovThis program is a collection of regression tests for ancillary data 6b5718158SSergey Kandaurov(control information) for PF_LOCAL sockets (local domain or Unix domain 7b5718158SSergey Kandaurovsockets). There are tests for stream and datagram sockets. 85368db27SMaxim Konovalov 9b5718158SSergey KandaurovUsually each test does following steps: creates Server, forks Client, 10b5718158SSergey KandaurovClient sends something to Server, Server verifies whether everything is 11b5718158SSergey Kandaurovcorrect in received message(s). 125368db27SMaxim Konovalov 135368db27SMaxim KonovalovIt is better to change the owner of unix_cmsg to some safe user 14b5718158SSergey Kandaurov(eg. nobody:nogroup) and set SUID and SGID bits, else some tests that 15b5718158SSergey Kandaurovcheck credentials can give correct results for wrong implementation. 16b5718158SSergey Kandaurov 17b5718158SSergey KandaurovIt is better to run this program by a user that belongs to more 18b5718158SSergey Kandaurovthan 16 groups. 195368db27SMaxim Konovalov 205368db27SMaxim KonovalovAvailable options 215368db27SMaxim Konovalov================= 225368db27SMaxim Konovalov 23b5718158SSergey Kandaurovusage: unix_cmsg [-dh] [-n num] [-s size] [-t type] [-z value] [testno] 245368db27SMaxim Konovalov 25b5718158SSergey Kandaurov Options are: 26b5718158SSergey Kandaurov -d Output debugging information 27b5718158SSergey Kandaurov -h Output the help message and exit 28b5718158SSergey Kandaurov -n num Number of messages to send 29b5718158SSergey Kandaurov -s size Specify size of data for IPC 30b5718158SSergey Kandaurov -t type Specify socket type (stream, dgram) for tests 31b5718158SSergey Kandaurov -z value Do not send data in a message (bit 0x1), do not send 32b5718158SSergey Kandaurov data array associated with a cmsghdr structure (bit 0x2) 33b5718158SSergey Kandaurov testno Run one test by its number (require the -t option) 345368db27SMaxim Konovalov 35b5718158SSergey KandaurovDescription 36b5718158SSergey Kandaurov=========== 375368db27SMaxim Konovalov 38b5718158SSergey KandaurovIf Client sends something to Server, then it sends 5 messages by default. 39b5718158SSergey KandaurovNumber of messages can be changed in the -n command line option. Number 40b5718158SSergey Kandaurovof messages will be given as N in the following descriptions. 415368db27SMaxim Konovalov 42b5718158SSergey KandaurovIf Client sends something to Server, then it sends some data (few bytes) 43b5718158SSergey Kandaurovin each message by default. The size of this data can be changed by the -s 44b5718158SSergey Kandaurovcommand line option. The "-s 0" command line option means, that Client will 45b5718158SSergey Kandaurovsend zero bytes represented by { NULL, 0 } value of struct iovec{}, referenced 46b5718158SSergey Kandaurovby the msg_iov field from struct msghdr{}. The "-z 1" or "-z 3" command line 47b5718158SSergey Kandaurovoption means, that Client will send zero bytes represented by the NULL value 48b5718158SSergey Kandaurovin the msg_iov field from struct msghdr{}. 495368db27SMaxim Konovalov 50b5718158SSergey KandaurovIf Client sends some ancillary data object, then this ancillary data object 51b5718158SSergey Kandaurovalways has associated data array by default. The "-z 2" or "-z 3" option 52b5718158SSergey Kandaurovmeans, that Client will not send associated data array if possible. 535368db27SMaxim Konovalov 545368db27SMaxim KonovalovFor SOCK_STREAM sockets: 555368db27SMaxim Konovalov----------------------- 565368db27SMaxim Konovalov 575368db27SMaxim Konovalov 1: Sending, receiving cmsgcred 585368db27SMaxim Konovalov 59b5718158SSergey Kandaurov Client connects to Server and sends N messages with SCM_CREDS ancillary 60b5718158SSergey Kandaurov data object. Server should receive N messages, each message should 61b5718158SSergey Kandaurov have SCM_CREDS ancillary data object followed by struct cmsgcred{}. 625368db27SMaxim Konovalov 63b5718158SSergey Kandaurov 2: Receiving sockcred (listening socket) 645368db27SMaxim Konovalov 65b5718158SSergey Kandaurov Server creates a listening stream socket and sets the LOCAL_CREDS 66b5718158SSergey Kandaurov socket option for it. Client connects to Server two times, each time 67b5718158SSergey Kandaurov it sends N messages. Server accepts two connections and receives N 68b5718158SSergey Kandaurov messages from each connection. The first message from each connection 69b5718158SSergey Kandaurov should have SCM_CREDS ancillary data object followed by struct sockcred{}, 70b5718158SSergey Kandaurov next messages from the same connection should not have ancillary data. 715368db27SMaxim Konovalov 72b5718158SSergey Kandaurov 3: Receiving sockcred (accepted socket) 735368db27SMaxim Konovalov 74b5718158SSergey Kandaurov Client connects to Server. Server accepts connection and sets the 75b5718158SSergey Kandaurov LOCAL_CREDS socket option for just accepted socket. Client sends N 76b5718158SSergey Kandaurov messages to Server. Server should receive N messages, the first 77b5718158SSergey Kandaurov message should have SCM_CREDS ancillary data object followed by 78b5718158SSergey Kandaurov struct sockcred{}, next messages should not have ancillary data. 795368db27SMaxim Konovalov 805368db27SMaxim Konovalov 4: Sending cmsgcred, receiving sockcred 815368db27SMaxim Konovalov 82b5718158SSergey Kandaurov Server creates a listening stream socket and sets the LOCAL_CREDS 83b5718158SSergey Kandaurov socket option for it. Client connects to Server and sends N messages 84b5718158SSergey Kandaurov with SCM_CREDS ancillary data object. Server should receive N messages, 85b5718158SSergey Kandaurov the first message should have SCM_CREDS ancillary data object followed 86b5718158SSergey Kandaurov by struct sockcred{}, each of next messages should have SCM_CREDS 87b5718158SSergey Kandaurov ancillary data object followed by struct cmsgcred{}. 885368db27SMaxim Konovalov 89b5718158SSergey Kandaurov 5: Sending, receiving timeval 905368db27SMaxim Konovalov 91b5718158SSergey Kandaurov Client connects to Server and sends message with SCM_TIMESTAMP ancillary 92b5718158SSergey Kandaurov data object. Server should receive one message with SCM_TIMESTAMP 93b5718158SSergey Kandaurov ancillary data object followed by struct timeval{}. 94b5718158SSergey Kandaurov 95b5718158SSergey Kandaurov 6: Sending, receiving bintime 96b5718158SSergey Kandaurov 97b5718158SSergey Kandaurov Client connects to Server and sends message with SCM_BINTIME ancillary 98b5718158SSergey Kandaurov data object. Server should receive one message with SCM_BINTIME 99b5718158SSergey Kandaurov ancillary data object followed by struct bintime{}. 100b5718158SSergey Kandaurov 101b5718158SSergey Kandaurov 7: Checking cmsghdr.cmsg_len 102b5718158SSergey Kandaurov 103b5718158SSergey Kandaurov Client connects to Server and tries to send several messages with 104b5718158SSergey Kandaurov SCM_CREDS ancillary data object that has wrong cmsg_len field in its 105b5718158SSergey Kandaurov struct cmsghdr{}. All these attempts should fail, since cmsg_len 106b5718158SSergey Kandaurov in all requests is less than CMSG_LEN(0). 107b5718158SSergey Kandaurov 108b5718158SSergey Kandaurov 8: Check LOCAL_PEERCRED socket option 109b5718158SSergey Kandaurov 110b5718158SSergey Kandaurov This test does not use ancillary data, but can be implemented here. 111b5718158SSergey Kandaurov Client connects to Server. Both Client and Server verify that 112b5718158SSergey Kandaurov credentials of the peer are correct using LOCAL_PEERCRED socket option. 1135368db27SMaxim Konovalov 1145368db27SMaxim KonovalovFor SOCK_DGRAM sockets: 1155368db27SMaxim Konovalov---------------------- 1165368db27SMaxim Konovalov 1175368db27SMaxim Konovalov 1: Sending, receiving cmsgcred 1185368db27SMaxim Konovalov 119b5718158SSergey Kandaurov Client connects to Server and sends N messages with SCM_CREDS ancillary 120b5718158SSergey Kandaurov data object. Server should receive N messages, each message should 121b5718158SSergey Kandaurov have SCM_CREDS ancillary data object followed by struct cmsgcred{}. 1225368db27SMaxim Konovalov 1235368db27SMaxim Konovalov 2: Receiving sockcred 1245368db27SMaxim Konovalov 125b5718158SSergey Kandaurov Server creates datagram socket and sets the LOCAL_CREDS socket option 126b5718158SSergey Kandaurov for it. Client sends N messages to Server. Server should receive N 127b5718158SSergey Kandaurov messages, each message should have SCM_CREDS ancillary data object 128b5718158SSergey Kandaurov followed by struct sockcred{}. 1295368db27SMaxim Konovalov 1305368db27SMaxim Konovalov 3: Sending cmsgcred, receiving sockcred 1315368db27SMaxim Konovalov 132b5718158SSergey Kandaurov Server creates datagram socket and sets the LOCAL_CREDS socket option 133b5718158SSergey Kandaurov for it. Client sends N messages with SCM_CREDS ancillary data object 134b5718158SSergey Kandaurov to Server. Server should receive N messages, the first message should 135b5718158SSergey Kandaurov have SCM_CREDS ancillary data object followed by struct sockcred{}, 136b5718158SSergey Kandaurov each of next messages should have SCM_CREDS ancillary data object 137b5718158SSergey Kandaurov followed by struct cmsgcred{}. 1385368db27SMaxim Konovalov 139b5718158SSergey Kandaurov 4: Sending, receiving timeval 1405368db27SMaxim Konovalov 141b5718158SSergey Kandaurov Client sends one message with SCM_TIMESTAMP ancillary data object 142b5718158SSergey Kandaurov to Server. Server should receive one message with SCM_TIMESTAMP 143b5718158SSergey Kandaurov ancillary data object followed by struct timeval{}. 144b5718158SSergey Kandaurov 145b5718158SSergey Kandaurov 5: Sending, receiving bintime 146b5718158SSergey Kandaurov 147b5718158SSergey Kandaurov Client sends one message with SCM_BINTIME ancillary data object 148b5718158SSergey Kandaurov to Server. Server should receive one message with SCM_BINTIME 149b5718158SSergey Kandaurov ancillary data object followed by struct bintime{}. 150b5718158SSergey Kandaurov 151b5718158SSergey Kandaurov 6: Checking cmsghdr.cmsg_len 152b5718158SSergey Kandaurov 153b5718158SSergey Kandaurov Client tries to send Server several messages with SCM_CREDS ancillary 154b5718158SSergey Kandaurov data object that has wrong cmsg_len field in its struct cmsghdr{}. 155b5718158SSergey Kandaurov All these attempts should fail, since cmsg_len in all requests is less 156b5718158SSergey Kandaurov than CMSG_LEN(0). 1575368db27SMaxim Konovalov 1585368db27SMaxim Konovalov- Andrey Simonenko 159b5718158SSergey Kandaurovandreysimonenko@users.sourceforge.net 160